var gpAlertWindow;

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}


function validate_email(theFormName,section_id,rootDir){
	var emailForm = document.getElementById(theFormName);
	var e_address = emailForm.email.value;
	var url;
	
	window.name = 'email_popup_gp';
 
	if ((section_id==null)||(section_id=="")){
		section_id=0;
	}
	
	if ((rootDir==null) || (rootDir=="")){
		rootDir="/";
	}else{
		rootDir=unescape(rootDir)+"/";
	}
	
	if ((e_address==null)||(e_address=="") || (e_address=="Enter e-mail address")){
		alert("Please Enter a valid e-mail address.")
		emailForm.email.focus()
		return false
	}
	if (echeck(e_address)==false){
		alert("This e-mail address is invalid, please check the syntax and try again. Thank You.")
		emailForm.email.focus()
		return false
	}
	
	url="http://www.greatperformances.com/gp/email.php?email="+escape(e_address)+"&id="+section_id;
	remote = open(url, "", "status=no,location=0,resizable=0,menubar=0,width=550,height=300,scrollbars=0,left=300,top=100");
}

function alert_popup(url) {
	gpAlertWindow=window.open(url,"","location=0,status=0,scrollbars=0,width=600,height=250,left=300,top=100");
	if (!gpAlertWindow.opener)
	gpAlertWindow.opener = self;
}

function alerted_popup(url) {
	gpAlertWindow=window.open(url,"","location=0,status=0,scrollbars=0,width=450,height=450,left=300,top=100");
	if (!gpAlertWindow.opener)
	gpAlertWindow.opener = self;
}

function validate_alert(theFormName,section_id,rootDir){
	var emailForm = document.getElementById(theFormName);
	var e_address = emailForm.email.value;
	var url;
	
	window.name = 'email_popup_gp';
 
	if ((section_id==null)||(section_id=="")){
		section_id=0;
	}
	
	if ((rootDir==null) || (rootDir=="")){
		rootDir="";
	}else{
		rootDir=unescape(rootDir)+"/";
	}
	
	if ((e_address==null)||(e_address=="") || (e_address=="Enter e-mail address")){
		alert("Please Enter a valid e-mail address.")
		emailForm.email.focus()
		return false
	}
	if (echeck(e_address)==false){
		alert("This e-mail address is invalid, please check the syntax and try again. Thank You.")
		emailForm.email.focus()
		return false
	}
	
	emailForm.action.value="add";
	emailForm.id.value=section_id;
	
	return true;
}



function validate_share(theFormName,section_id,rootDir){
	var emailForm = document.getElementById(theFormName);
	var e_from = emailForm.from_email.value;
	var e_to = emailForm.to_email.value;
	var url;
	
	window.name = 'email_popup_gp';
 
	if ((section_id==null)||(section_id=="")){
		section_id=0;
	}
	
	if ((rootDir==null) || (rootDir=="")){
		rootDir="";
	}else{
		rootDir=unescape(rootDir)+"/";
	}
	
	if ((e_from==null)||(e_from=="") || (e_from=="Enter e-mail address")){
		alert("Please Enter a valid e-mail address.")
		emailForm.email.focus()
		return false
	}
	if (echeck(e_from)==false){
		alert("This e-mail address is invalid, please check the syntax and try again. Thank You.")
		emailForm.email.focus()
		return false
	}
	
	if ((e_to==null)||(e_to=="") || (e_to=="Enter e-mail address")){
		alert("Please Enter a valid recipient e-mail address.")
		emailForm.email.focus()
		return false
	}
	if (echeck(e_to)==false){
		alert("This recipient's e-mail address is invalid, please check the syntax and try again. Thank You.")
		emailForm.email.focus()
		return false
	}
	
	emailForm.action.value="send";
	emailForm.id.value=section_id;
	
	return true;
}


function validate_customer_form(theFormName,section_id,rootDir){
	var theForm = document.getElementById(theFormName);
	var url;
	var c_firstname = theForm.firstname.value;
	var c_lastname = theForm.lastname.value;
	var c_email = theForm.customer_email.value;
	var c_company = theForm.company.value;
	var c_address = theForm.address.value;
	var c_city = theForm.city.value;
	var c_state = theForm.state.options[theForm.state.selectedIndex].value;
	var c_zipcode = theForm.zipcode.value;
	var c_telephone = theForm.telephone.value;
	var c_director = theForm.director.value;
	
	window.name = 'customer_popup_gp';
 
	if ((section_id==null)||(section_id=="")){
		section_id=0;
	}
	
	if ((rootDir==null) || (rootDir=="")){
		rootDir="/";
	}else{
		rootDir=unescape(rootDir)+"/";
	}
	
	if ((c_firstname==null)||(c_firstname=="") || (c_firstname=="Enter firstname")){
		alert("Please enter your firstname.")
		theForm.firstname.focus()
		return false
	}
	if ((c_lastname==null)||(c_lastname=="") || (c_lastname=="Enter lastname")){
		alert("Please enter your lastname.")
		theForm.lastname.focus()
		return false
	}
	if ((c_email==null)||(c_email=="") || (c_email=="Enter E-mail address")){
		alert("Please enter your e-mail address.")
		theForm.customer_email.focus()
		return false
	}
	if (echeck(c_email)==false){
		alert("This e-mail address is invalid, please check the syntax and try again. Thank You.")
		theForm.customer_email.focus()
		return false
	}
	
	url="http://www.greatperformances.com/inc/customer.php?firstname="+escape(c_firstname)+"&lastname="+escape(c_lastname)+"&email="+escape(c_email)+"&id="+section_id;
	url+="&company="+escape(c_company)+"&address="+escape(c_address)+"&city="+escape(c_city);
	url+="&state="+c_state+"&zipcode="+escape(c_zipcode)+"&telephone="+escape(c_telephone)+"&director="+escape(c_director);
	remote = open(url, "", "status=no,location=0,resizable=0,menubar=0,width=550,height=300,scrollbars=0,left=300,top=100");
}

function gup( name ){  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	if( results == null )    
		return "";  
	else    
		return results[1];
}