// JavaScript Document
/*NOTE: This js file includes only the javascript methods
		that are used in every page of the new design.
		I.E. ONLY ADD methods that are used by the primary
		elements of the new design. */

//This Method is used for login operations
//It makes the login div to appear in the middle of the page.
function showLoginBox(boxID, contentID,w,h,eff_length){
	var url = "http://www.ravand.com/email/includes_ajax/login.cfm?command=initialize";
	popupDiv(boxID,w,h,eff_length);
	ajax(url, contentID, "fadein", eff_length);
}

//This method makes a div with display=none appear
//with fade-in effect. w is width, and h is height.
//these values are used for centering the div in the window
function popupDiv(id,w,h,eff_length){
	var msgbox = document.getElementById(id); 
	var underlayer = document.getElementById('popupUnderlay'); 
	if(msgbox.style.display!='block'){
		msgbox.style.top = (document.body.clientHeight - h) / 2;  
		msgbox.style.left = (document.body.clientWidth - w) / 2;
		underlayer.style.width=document.body.clientWidth;
		underlayer.style.height=document.body.scrollHeight;
		underlayer.style.display='block';
		setTimeout("Effect.Appear('"+id+"', {duration: "+eff_length+"/1000})",300);
	}
}		

//Closes the div opened by function popupDiv
function closeDiv(id){
	Effect.DropOut(id);
	document.getElementById('popupUnderlay').style.display='none';
}

//Automatically closes the div opened by function popupDiv
//after the given amount of waitTime.
function autoCloseDiv(id, waitTime){
	setTimeout("closeDiv('"+id+"')",waitTime);
}

//This method is used to open LIVE CHAT popup
function popupLiveChat() {
	var url="http://www.ravand.com/livehelp/UserPreChat.aspx?ref=http%3a%2f%2fwww.ravand.com%2f&d=1&u=&bypass=";
	newwindow=window.open(url,'Support','location=no,menubar=no,toolbar=no,height=325,width=480');
	if (window.focus) {newwindow.focus()}
	return false;
}

//This method is used for input verification purposes for
//the Quick Contact! form in the footer.
function checkFooterFrom(givenForm){
	if(givenForm.name.value == '' || givenForm.email.value == '' || givenForm.message.value == ''){
		if(givenForm.name.value == ''){givenForm.name.className = 'FooterFormInputError';}
		if(givenForm.email.value == ''){givenForm.email.className = 'FooterFormInputError';}
		if(givenForm.message.value == ''){givenForm.message.className = 'FooterFormTextareaError';}
	} else {
		var name= givenForm.name.value;
		var email = givenForm.email.value;
		var phone = givenForm.phone.value;
		var message = givenForm.message.value;
		var url = "http://www.ravand.com/email/includes/footerFormSent.cfm?name="+name+"&email="+email+"&phone="+phone+"&message="+message;
		ajaxFadeOutIn(url,'footerform', 500);
	}
}

//These functions are used for tables with multiple rows
//They perform mouseover and mouseout actions
//requires the id of the row that is focused,
//and the name of the class that is assigned to the table.
function doFocus(id, className) { document.getElementById(id).className = className+"Focus"; }
function doUnfocus(id, className) { document.getElementById(id).className = className; }
function opentPage(page) { window.location.href=page; }


//Function used in Main Page for Newsletter Subscribers.
function checkEmail(email,divID) {
	var email=document.getElementById('Sub_email').value;
	if(email.search(/@/)==-1) {
		alert("Invalid Email!\nPlease make sure you enter your email address correctly!");
		return false;
	} else if(email.search(/\./)==-1) {
		alert("Invalid Email!\nPlease make sure you enter your email address correctly!");
		return false;
	} else { 
		var url = "http://www.ravand.com/email/includes_ajax/subscribe_newsletter.cfm?e="+email+"&es="+document.subscribe.es.value; 
		ajaxFadeOutIn(url,divID, 500);
	}
}
