//----------------------------
function PassSelectOneText(form) {
  for (var i = 0; i < form.elements.length; i++)  {
                if (form.elements[i].type == 'select-one')  {
                        GetSelectOneText(form,form.elements[i]);
                }
        }
  function GetSelectOneText(form,selectOne) {
    var text = selectOne.options[selectOne.selectedIndex].text;
    var exists = false;
    var name = selectOne.name+'Text'
    for (var i = 0; i < form.elements.length; i++)  {
                  if (form.elements[i].name == name)  {
                          exists = true
                  }
          }
          if (!exists) {
                  form.innerHTML += '<input type="hidden" name="' + name + '">'
    }
    form.elements[name].value = text;
  }
}


















function passvalue() {
if (document.f.prof[document.f.prof.selectedIndex].value == "Other") {
alert ("hello")

//document.forms['f'].elements['psupport'].disabled = false;
} else {
//document.forms['f'].elements['psupport'].disabled = true;
}
}



function checkad9() {
if (!document.f.agree.checked)
    {
        alert ( "Please confirm to the terms and attendance." );
        document.f.agree.focus();
        document.f.agree.style.background = "yellow";
        return false;
        } else {
        document.f.agree.style.background = "white";
        }

if ( document.f.sign.value == "" )
    {
        alert ( "Please fill in the 'Full Name' box." );
        document.f.sign.focus();
        document.f.sign.style.background = "yellow";
        return false;
        } else {
        document.f.sign.style.background = "white";
        }
}




function checkad() {
if ( document.f.firstname.value == "" )
    {
        alert ( "Please fill in the 'First Name' box." );
	document.f.firstname.focus();
	document.f.firstname.style.background = "yellow";
	return false;
	} else {
	document.f.firstname.style.background = "white";
	}

if ( document.f.surname.value == "" )
    {
        alert ( "Please fill in the 'SurName' box." );
	document.f.surname.focus();
        document.f.surname.style.background = "yellow";
        return false;
    	} else {	
	document.f.surname.style.background = "white";
	}

if( (document.f.gender[0].checked == false ) && ( document.f.gender[1].checked == false))
    {
        alert ( "Please choose your Gender: Male or Female" );
	  document.f.gender[0].focus();
        document.f.gender[0].style.background = "yellow";
	document.f.gender[1].style.background = "yellow";
	return false;
    } else {
	document.f.gender[0].style.background = "white";
	document.f.gender[1].style.background = "white";
    }


if ( document.f.birthplace.value == "" )
    {
        alert ( "Please fill in the 'Place of Birth' box." );
        document.f.birthplace.focus();
        document.f.birthplace.style.background = "yellow";
        return false;
    } else {
	document.f.birthplace.style.background = "white";
	}

if ( document.f.email.value == "" )
    {
        alert ( "Please fill in the 'Valid Email Required' box." );
        document.f.email.focus();
        document.f.email.style.background = "yellow";
        return false;
    } else {
	document.f.email.style.background = "white";
	}

// ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$

if (document.f.email.value != '')  {
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.f.email.value))) {
alert("The email you entered is not a valid email address.");
document.f.email.focus();
if(document.all || document.getElementByID){
document.f.email.style.background = "yellow";
}

return false;
}
}



}

function checkad2() {

// Page 2 checks
if ( document.f.flathouse.value == "" )
    {
        alert ( "Please fill in the 'Flat No or House No' box." );
        document.f.flathouse.focus();
        document.f.flathouse.style.background = "yellow";
        return false;
    } else {
        document.f.flathouse.style.background = "white";
        }


if ( document.f.town.value == "" )
    {
        alert ( "Please fill in the 'Town Required' box." );
        document.f.town.focus();
        document.f.town.style.background = "yellow";
        return false;
    } else {
        document.f.town.style.background = "white";
        }

if ( document.f.city.value == "" )
    {
        alert ( "Please fill in the 'City field required' box." );
        document.f.city.focus();
        document.f.city.style.background = "yellow";
        return false;
    } else {
        document.f.city.style.background = "white";
        }

if ( document.f.phone.value == "" )
    {
        alert ( "Please fill in the 'Reachable Telephone Required' box." );
        document.f.phone.focus();
        document.f.phone.style.background = "yellow";
        return false;
    } else {
        document.f.phone.style.background = "white";
        }

if (document.f.country[document.f.country.selectedIndex].value == "Select-One") 
   {
	alert ("Select country");
	document.f.country.focus();
	document.f.country.style.background = "yellow";
        return false;
    } else {
        document.f.country.style.background = "white";
        }

if (document.f.email.value != '')  {
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.f.email.value))) {
alert("The email you entered is not a valid email address.");
document.f.email.focus();
if(document.all || document.getElementByID){
document.f.email.style.background = "yellow";
}

return false;
}
}


if (document.f.ukpostcode.value != '') {
if (!/^[A-Z]{1,2}\d{1,2} \d[A-Z]{2}$/.test(document.f.firstname.value)) {
alert("First Name Error");
document.f.ukpostcode.focus();
if(document.all || document.getElementByID){
document.f.ukpostcode.style.background = "yellow";
}

return false;
}
}


}




function checkad3() {


if ( document.f.passport.value == "" )
    {
        alert ( "Please fill in the 'Passport No' box." );
        document.f.passport.focus();
        document.f.passport.style.background = "yellow";
        return false;
    } else {
        document.f.passport.style.background = "white";
        }

if (document.f.national[document.f.national.selectedIndex].value == " ")
   {
        alert ("Select Nationality");
        document.f.national.focus();
        document.f.national.style.background = "yellow";
        return false;
    } else {
        document.f.national.style.background = "white";
        }

}


function checkad4() {


if ( document.f.abilitycourse.value == "" )
    {
        alert ( "Please fill in the 'Enter your recent course name' box." );
        document.f.abilitycourse.focus();
        document.f.abilitycourse.style.background = "yellow";
        return false;
    } else {
        document.f.abilitycourse.style.background = "white";
        }

if ( document.f.abilityaward.value == "" )
    {
        alert ( "Please fill in the 'Enter your recent course awarding body' box." );
        document.f.abilityaward.focus();
        document.f.abilityaward.style.background = "yellow";
        return false;
    } else {
        document.f.abilityaward.style.background = "white";
        }



if (document.f.abilitylevel[document.f.abilitylevel.selectedIndex].value == " ")
   {
        alert ("Select Course Level");
        document.f.abilitylevel.focus();
        document.f.abilitylevel.style.background = "yellow";
        return false;
    } else {
        document.f.abilitylevel.style.background = "white";
        }


if (document.f.prof[document.f.prof.selectedIndex].value == " ")
   {
        alert ("Select English proficiency. If you are willing to go for an interview by the college select the appropriate option. IELTS and TOEFL results helps us decide the application quickly.");
        document.f.prof.focus();
        document.f.prof.style.background = "yellow";
        return false;
    } else {
        document.f.prof.style.background = "white";
        }



}








function checkform() {

if (document.sampleform.ukpostcode.value != '') {
if (!/^[A-Z]{1,2}\d{1,2} \d[A-Z]{2}$/.test(document.sampleform.ukpostcode.value)) {
alert("The UK Postcode you entered is not a valid ukpostcode address. Try Using capital Letters");
document.sampleform.ukpostcode.focus();
if(document.all || document.getElementByID){
document.sampleform.ukpostcode.style.background = "yellow";
}

return false;
}
}



if (document.sampleform.email.value != '') {
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.sampleform.email.value))) {
alert("The email you entered is not a valid email address.");
document.sampleform.email.focus();
if(document.all || document.getElementByID){
document.sampleform.email.style.background = "yellow";
}

return false;
}
}


if (document.sampleform.fname.value == '') {
        alert('There is a problem with the fname field');
	document.sampleform.fname.focus();
	if(document.all || document.getElementByID){
	document.sampleform.fname.style.background = "yellow";
	}
        return false;
}





return true;
}

function checknow() {
ok = "1234567890qwertyuiopasdfghjklzxcvbnm.-:QWERTYUIOPASDFGHJKLZXCVBNM()&<>,";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
}}

//---------------------------
function split(s,del){
	arrS= new Array();
	var i=0;
	var j=0;
	var k=0;
	var delim=new String(del);

	//Is the delimeter in the string
	if(s.indexOf(delim)!=-1){
		for (i=0; i<s.length;i++){
			if(s.charAt(i)==delim){
				if(k==0){
					arrS[j]=s.substring(k,i);
				}else{
					arrS[j]=s.substring(k+1,i);
				}
				k=i;
				j++;
			}
		}
		arrS[j]=s.substring(k+1,s.length);
	}else{
		arrS[0]=s;
	}
	return arrS;
}

//Converts string to ProperCase with spaces and hyphens
function propercase(s){


ok = " /1234567890qwertyuiopasdfghjklzxcvbnm.-:QWERTYUIOPASDFGHJKLZXCVBNM()&<>,";

for(i=0; i < s.length ;i++){
	if(ok.indexOf(s.charAt(i))<0){
	var b = s.substring(0,i);
	var c = s.substring(i,i+1);
	alert('The value is using illegal charachter. Please check and retype. Press Shift+Tab and fix again to fix the field by removing  --->           ' + c );
	s= b;
	}
}


	var i;
	var returnString = "";
	var tmpS= s.toLowerCase();
	var arrS= new Array();
	var arrS2 = new Array();
	//search each word in array arrS
	arrS=split(tmpS," ");
	for (i = 0; i < arrS.length; i++){   
		var thisWord=arrS[i];
		//Check to see if word contains a hyphen
		if(thisWord.indexOf("-")!=-1){
			arrS2 = split(thisWord,"-");
			for(var j=0; j < arrS2.length; j++){
				var thisWord2=arrS2[j];
				returnString = returnString + thisWord2.charAt(0).toUpperCase() + thisWord2.substring(1,thisWord2.length)+"-";
			}
			returnString = returnString.substring(0,returnString.length-1)+" ";
		} else {
			returnString = returnString + thisWord.charAt(0).toUpperCase() + thisWord.substring(1,thisWord.length)+" ";
		}
	}
	returnString = returnString.substring(0,returnString.length-1);
	return returnString;
}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=150,height=150,left = 437,top = 309');");
}

function showmenu(elmnt)
{
document.all(elmnt).style.visibility="visible"
}

function hidemenu(elmnt)
{
document.all(elmnt).style.visibility="hidden"
}


