var popUpWin=0;
function popUpWindow(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=780,height=550,left=0, top=0,screenX=0,screenY=0');
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
// ---- Email validation
var testresults
function checkemail(){
	var str=document.form1.txtEmail.value
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		testresults=false;
	else{
		alert("Please input a valid email address!");
		testresults=true;
	}
	return (testresults);
}
// --- End Email validation


function checkForm(){
	var err=false;
	
	var rType=getCheckedValue(document.forms['form1'].elements['number']);

	if(rType == ""){ err=true; }
	else if(document.form1.txtFname.value == ""){err=true;}
	else if(document.form1.txtLname.value == ""){err=true;}
	else if(document.form1.txtEmail.value == ""){err=true;}
	else if(document.form1.txtCountry.value == "-1"){err=true;}
	else if(checkemail()){err = true;}
	
    document.form1.txtReserve.value=rType;

	if(!err){
		return true;
	}
	else{
		return false;
		alert("* marked fields are required.");	
	} 
}

//----------- Admin section methods --------------
var AgentPopUpWin=0;
function AgentPopUpWindow(){
	//alert("Goda Goda");
  var left, top, width, height;
  width=550;
  height=250;
  left=(screen.width/2)-(width/2);
  top=(screen.height/2)-(height/2);
  
  if(AgentPopUpWin)
  {
    if(!AgentPopUpWin.closed) AgentPopUpWin.close();
  }
  AgentPopUpWin = open("forgotpassword.php", 'AgentPopUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

//------ Password generator --------------
var keylist="abcdefghijklmnopqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var temp=''

function generatepass(plength){
temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
return temp
}

function populatePassword(enterlength){
document.form1.txtPW.value=generatepass(enterlength)
//alert(generatepass(enterlength));
}

var adminPopup=0;
function adminPopup(URLStr, width, height)
{
	alert("");s
  var left, top, width, height;
  width=550;
  height=250;
  left=(screen.width/2)-(width/2);
  top=(screen.height/2)-(height/2);
  if(adminPopup)
  {
    if(!adminPopup.closed) adminPopup.close();
  }
  adminPopup = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

//edit validation

function subEdit()
{

//Agent Name
if(form1.txtName.value==0)
{
window.alert("Agent Name must be filled out!");
form1.txtName.focus();
return false;
}

//Phone No.
if(isNaN(form1.txtContact.value)) 
   { 
     alert("Invalid Phone Number! Please re-enter."); 
     form1.txtContact.focus(); 
     return (false); 
   }

//Email
if(form1.txtEmail.value==0)
{
window.alert("Email must be filled out!");
form1.txtEmail.focus();
return false;}
else 
{if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form1.txtEmail.value ))
{
return true;
}
else
{
alert("Invalid E-mail Address! Please re-enter.")
form1.txtEmail.focus();
return false;
}}

}

//New validation

function subNew()
{


//Password
if(form1.txtPW.value==0)
{
window.alert("Password must be filled out!");
form1.txtPW.focus();
return false;
}

//Agent Name
if(form1.txtName.value==0)
{
window.alert("Agent Name must be filled out!");
form1.txtName.focus();
return false;
}

//Phone No.
if(isNaN(form1.txtContact.value)) 
   { 
     alert("Invalid Phone Number! Please re-enter."); 
     form1.txtContact.focus(); 
     return (false); 
   }

//Email
if(form1.txtEmail.value==0)
{
window.alert("Email must be filled out!");
form1.txtEmail.focus();
return false;}
else 
{if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form1.txtEmail.value ))
{
return true;
}
else
{
alert("Invalid E-mail Address! Please re-enter.")
form1.txtEmail.focus();
return false;
}}

}

//Login validation

function subLogin()
{


//Password
if(form1.txtOldPW.value==0)
{
window.alert("Old Password must be filled out!");
form1.txtOldPW.focus();
return false;
}

//New Password1
if(form1.txtNewPW.value==0)
{
window.alert("New Password must be filled out!");
form1.txtNewPW.focus();
return false;
}

//New Password2
if(form1.txtNewPW1.value==0)
{
window.alert("Confirm Password must be filled out!");
form1.txtNewPW1.focus();
return false;
}

}