function nath(select,textbox){
//alert(document.memForm.nationality.selectedIndex);
//alert(document.memForm.nationality.selectedIndex);

//document.memForm.country.options[document.memForm.country.selectedIndex].value=document.getElementById("country").options[document.memForm.country.selectedIndex].text;
document.getElementById(textbox).value="00"+document.getElementById(select).value;
//alert(document.getElementById("nationality").options[document.memForm.nationality.selectedIndex].id);


//document.memForm.personal_phone.value="00"+document.memForm.country.options[document.memForm.country.selectedIndex].id;//+document.getElementsByName("personal_phone")[0].value;
//document.memForm.personal_mobile.value="00"+document.memForm.country.options[document.memForm.country.selectedIndex].id;//+document.getElementsByName("personal_phone")[0].value;
//document.memForm.personal_fax.value="00"+document.memForm.country.options[document.memForm.country.selectedIndex].id;//+document.getElementsByName("personal_phone")[0].value;


}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

//Display a named menu, at the position of another object
function display_menu(parent,named)
{
	//get the named menu
	var menu_element = document.getElementById(named);
	//override the 'display:none;' style attribute
	menu_element.style.display = "";
	//get the placement of the element that invoked the menu...
	var placement = findPos(parent);
	//...and put the menu there
	menu_element.style.left = placement[0]  ;
	menu_element.style.top = placement[1] +20;
		//menu_element.style.width=parent.style.width;

	
}

//Hide a named menu
function hide_menu(named)
{
	//get the named menu
	var menu_element = document.getElementById(named);
	//hide it with a style attribute
	menu_element.style.display = "none";
}


function check_number(n) {
	ok = "1234567890";
	for(i=0; i < n.length ;i++){
		if(ok.indexOf(n.charAt(i))<0){
			//alert("Please insert a number");	
			return (false);
		}	
	}
	return (true);
}

function check_email(e) {	
	if (e=="")
		return true;
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){
		//alert("Please enter a valid email address e.g. name@someone.com");
		return (false);
		}	
	} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			//alert("Please enter a valid email address e.g. name@someone.com");
			return (-1);		
		} 
	}
}

function checkEmail(e){
	if (!check_email(e))
	{
		alert("Please enter a valid email address e.g. name@someone.com");
		return false;
	}
	return true;
}

function checkConfirm(password,confirmPass){
	if (password != confirmPass)
	{
		alert("Your passwords do not match");
		return false;
	}
	
	return true
}

function check_form()
	{
		
		
		
		var isSelectAppType=false;
		
		//check select application type
		var gr=document.memForm.memType;
		for (var i=0;i<gr.length;i++)
			if (gr[i].checked)
			{
				isSelectAppType=gr[i].checked;
				break;
			}
		if (!isSelectAppType)
		{
			alert("Please select application type");
			return false;
		}
		
		//not empty feild
		var firsName=document.memForm.firsName;
		var surname=document.memForm.surname;
		var DOB=document.memForm.DOB;
		//var passportNum=document.memForm.passportNum;
		var personalEmail=document.memForm.personalEmail;
		
		var title=document.memForm.title;
		//var maritalStatus=document.memForm.maritalStatus;
		var nationality=document.memForm.nationality;
		
		var username=document.memForm.username;
		var password=document.memForm.password;
		
		
		if (
			firsName.value == ""  ||
			surname.value == ""  ||
			DOB.value == ""  ||
			//passportNum.value == ""  ||
			title.value == ""  ||
			//maritalStatus.value == ""  ||
			nationality.value == ""  ||
			
			username.value == ""  ||
			password.value == ""  ||
			
			personalEmail.value == ""
			
			)
		{
			if (username.value == "")
				alert("Please fill in User Name field");
			else
			if (password.value == "")
				alert("Please fill in Password Name field");
			else
			if (firsName.value == "")
				alert("Please fill in First Name field");
			else		
			if (surname.value == "")
				alert("Please fill in Family Name field");
			else
			if (DOB.value == "")
				alert("Please fill in Date of Birth field");
			else
			
			if (nationality.value == "")
				alert("Please fill in Nationality field");
			else
			
			//if (passportNum.value == "")
			//	alert("Please fill in Passport Number field");
			//else
			if (personalEmail.value == "")
				alert("Please fill in Personal Email field");
			
			
			//alert("Please fill in all the required fields");
			return false;
		}
		
		//ceck gender	
		var gr=document.memForm.gender;
		if (!gr[0].checked && !gr[1].checked)
		{
			alert("Please select the Gender");
			return false;
		}
		
		//check edu qualification
		//isSelectAppType=false;
		//gr=document.memForm.educationQual;
		//for (var j=0;j<gr.length;j++)
		//	if (gr[j].checked)
		//	{
		//		isSelectAppType=gr[j].checked;
		//		break;
		//	}
		//if (!isSelectAppType)
		//{
		//	alert("Please select the Educational Qualification");
		//	return false;
		//}
		
		//ceck email
		
		if (
			!checkEmail(document.memForm.personalEmail.value) ||
			!checkEmail(document.memForm.ref1Email.value) ||
			!checkEmail(document.memForm.ref2Email.value) ||
			!checkEmail(document.memForm.business_email.value)
			){
			
			return false;
		}
		
		//check numbers
		
		//if (
		//	!check_number(document.memForm.director_experience.value) ||
		//	!check_number(document.memForm.business_experience.value)
		//	){
			
		//	return false;
		//}
		
		if (!checkConfirm(password.value,document.memForm.confirm.value))
			return false;
		
		
		isSelectOnePref=false;
		for(var i=0;i<9;i++)
		{
			pref=document.getElementById("pref"+i)
			if (pref.checked)
			{
				isSelectOnePref=true;
				break;
			}
			
		}
		if (!isSelectOnePref)
		{
			alert("Please select one at least in section (7)");
			return false;
		}
			
		
		isSelectOneInfo=false;
		for(var i=0;i<15;i++)
		{
			info=document.getElementById("info"+i)
			if(info.checked)
			{
				isSelectOneInfo=true;
				break;
			}
			
		}
		
		if (!isSelectOneInfo)
			{
				alert("Please select at least one in section(8)");
				return false;
			}
			
		
		

		if (!document.memForm.consent0.checked)
		{
			alert("Please check \"I agree to the terms...\" in (11)Applicant Consents");
			return false;
		}
		
		return true;
		
	}
	
	
var xmlHttp

function checkUserName(baseUrl,userName){
	xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url=baseUrl+"/Check/check";
url=url+"?userName="+userName;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("submit").innerHTML=xmlHttp.responseText;

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function check_form_Mem()
	{
		
		//not empty feild
		var name=document.memForm.name;
		var code=document.memForm.code;
		var app_fee=document.memForm.app_fee;
		var annual_fee=document.memForm.annual_fee;		
		
		if (name.value == ""  || code.value == ""  || app_fee.value == ""  || annual_fee.value == "" )
		{
			alert("Please fill in all the required fields.");
			return false;
		}
		
		//check numbers 
		
		// Zero or Less
		/*if ( 
			(document.memForm.app_fee.value==0) ||
			(document.memForm.annual_fee.value==0)
			){
			
			alert("Error: Value Equal Zero");
			return false;
		}*/
		
		//  Less
		if ( 
			(document.memForm.app_fee.value<0) ||
			(document.memForm.annual_fee.value<0)
			){
			
			alert("Error: Value Less than Zero");
			return false;
		}
		
		// char
		if ( 
			!check_number(document.memForm.app_fee.value) ||
			!check_number(document.memForm.annual_fee.value)
			){
			
			alert("Invalid Number");
			return false;
		}
		
		return true;
		
	}

// feedback
function check_form2()
	{
		
		//not empty feild
		var name=document.form1.name;
		var email=document.form1.email;	
		
		if (name.value == "")
		{
			alert("Please fill in Feedback Type Name");
			return false;
		}
		
		//ceck email
		
		if (!checkEmail(document.form1.email.value))
		{
			return false;
		}
		
		return true;
		
	}


function check_form3()
	{
		
		//not empty feild
		var title=document.form1.title;
		
		if (title.value == "")
		{
			alert("Please fill in eMail Template Title");
			return false;
		}
		 
		if ((document.form1.SM.value!='')&&(!checkEmail(document.form1.SM.value)))
		{
			//alert("Sender eMail Syntax is not correct ");
			return false;
		}
		
		if ((document.form1.reply.value!='')&&(!checkEmail(document.form1.reply.value)))
		{
			//alert("Reply eMail Syntax is not correct ");
			return false;
		}
		
		return true;
		
	}
	
	
function check_form4()
	{
		
		//not empty feild
		var subject=document.form1.subject;
		
		if (subject.value == "")
		{
			alert("Please fill in eMail Template Title");
			return false;
		}
		
		return true;
		
	}
