// JavaScript Document

function Checkaddress(FieldVal1,FieldVal2,FieldVal3){
	if (document.theForm.same.checked){
document.theForm.sstreet.value=FieldVal1;
document.theForm.scity.value=FieldVal2;
document.theForm.spostfix.value=FieldVal3;
	}else{
		document.theForm.sstreet.value="";
document.theForm.scity.value="";
document.theForm.spostfix.value="";
	}
	
}
/***********************************************
* Required field(s) validation v1.10- By Mostafa Mohamed@un

***********************************************"aposition","Mostafa",*/
<!-- Begin Field Checks
		var NumericOnly = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\?\;\<\>\!\,\.\-\/\a-z\A-Z]/;
		var InValidExp = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\~\=\|\?\;\:\`\<\>\!\,\.\^\/\d]/;
		var CityCode = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\`\~\=\|\?\;\<\>\!\,\.\-\/]/;
		var TelCheck = /[^\d|\-|.|\ ]/;	

function CheckTele(FieldVal) {
		var ValField = FieldVal.value;
		var FieldLen = ValField.length;
		var lchar = FieldVal.value.charAt((FieldLen) - 1);
		if(lchar.search(TelCheck) != -1) 
			{
			var checked = FieldVal.value.substring(0, (FieldLen) - 1);
			FieldVal.value = checked;
			}
		}


function formCheck(formobj){
	// Enter name of mandatory fields
var fieldRequired = Array("Title","firstname", "lastname","Citizenship","pob","DirectTel3","pstreet","pcity","pcountry","nameorg","astreet","acity","Orgcountry","HQCountry","ChiefEditor","aposition","MediaType","sstreet","scity","sfirstname", "slastname","sphone","shcolor","secolor","shight","sweight","RulesNoted");
	// Enter field description to appear in the dialog box
var fieldDescription = Array("Select salutation","Enter your first name", "Enter your last name","Select your citizenship","Enter your place of birth (city and country)","Enter your phone number","Enter your street address", "Enter your city address","Enter your country address","Enter organization name","Enter organization street address", "Enter organization city address","Enter organization country address","Enter organization country address","Enter name of supervisor"," Check your position"," Check the type of media you represent","Enter street address while working at UN Headquarters","Enter city address while working at UN Headquarters","Enter emergency contact first name", "Enter emergency contact last name","Enter emergency contact phone","Enter hair color","Enter eye color","Enter your height","Enter your weight","RulesNoted");	// dialog message
	
	// Enter name of not mandatory fields
	
	var alertMsg = "Please complete the following:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == 0 || obj.options[obj.selectedIndex].text == 0){
					alertMsg += " - " + fieldDescription[i] + "\n";
				} 
								
				break;
//			case "select-multiple":
				case "select-multiple":
	if (obj.selectedIndex == 0){
					alertMsg += " - " + fieldDescription[i] + obj.options[obj.selectedIndex].value + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
						
						if ((j==8)&& (formobj.MTypeOther.value=="")) {
						alertMsg += " -  What other Type of medium ?\n";
						}
						}
						
				}
				if (!blnchecked){
					alertMsg += " -" + fieldDescription[i] + "\n";
				} 
			}
		}
		
		}
		
	// off first part passwored gos here
	alertMsg += checkDate(formobj.dob_day.value,formobj.dob_month.value,formobj.dob_year.value);
	alertMsg += checkEmail(formobj.email.value);
	alertMsg += CountTextField(formobj.password1.value);
alertMsg += checkPassword(formobj.password1.value,formobj.password2.value);
	alertMsg += CountTextField(formobj.pstreet.value);
	alertMsg += CountTextField(formobj.sstreet.value);
	alertMsg += CountTextField(formobj.astreet.value);
	alertMsg += CountText(formobj.note.value);
	alertMsg += checkCheckBox(formobj.RulesNoted.value);
	
	//alertMsg += checkPhone(formobj.DirectTel2.value,2,1);//2 formobj.RulesNoted.
	//alertMsg += checkPhone(formobj.DirectTel3.value,3,1);//3 number
	//alertMsg += checkPassword(formobj.password1.value,formobj.password2.value);

function checkCheckBox(f){
if (formobj.RulesNoted.checked == false )
		{
			alertMsg='Please read the notice and check the box below to continue.\n';
			}else  {
   alertMsg =  "";
	 }	
return alertMsg;
}
	//email
function checkEmail(strng){
var emailFilter=/^.+@.+\..{2,3}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

 if (strng == "") {
 		alertMsg = " - Enter your e-mail address\n";
    }
	
  else if  (!(emailFilter.test(strng))) {
		alertMsg =  " - Your email address appears to be incorrect\n";
  }
 
	else if (strng.match(illegalChars)) {
   alertMsg =  " - Your email address  contains illegal characters\n";
	 }
else  {
   alertMsg =  "";
	 }	
return alertMsg;
}//end Email
	
//Count the note
	function CountText(strng){
	
	var countMe = strng;
        var escapedStr = encodeURI(countMe)
        if (escapedStr.indexOf("%") != -1) {
            var count = escapedStr.split("%").length - 1
            if (count == 0) count++  //perverse case; can't happen with real UTF-8
            var tmp = escapedStr.length - (count * 3)
            count = count + tmp
        } else {
            count = escapedStr.length
        }
       // alert(escapedStr + ": size is " + count)
	   if (count >1000){
		  alertMsg = " -The note you entered contains more than 1,000 characters "+"\n";
	   } else
	   {alertMsg = ""}
	
	return alertMsg;
	}//end count note
	
//Count any text field
	
	function CountTextField(strng){
	
	var countMe = strng;
        var escapedStr = encodeURI(countMe)
        if (escapedStr.indexOf("%") != -1) {
            var count = escapedStr.split("%").length - 1
            if (count == 0) count++  //perverse case; can't happen with real UTF-8
            var tmp = escapedStr.length - (count * 3)
            count = count + tmp
        } else {
            count = escapedStr.length
        }
       // alert(escapedStr + ": size is " + count)
	   if (count >200){
		  alertMsg = " -The Adress you entered contains more than 200 characters "+"\n";
	   } else if (count < 6 ){
		  alertMsg = " -The Adress you entered contains more than 6 characters "+"\n";
	   }
	   {alertMsg = ""}
	
	return alertMsg;
	}//end count note

//Password function
function checkPassword (strng1,strng2) {
 var illegalChars = /[\W_]/; // allow only letters and numbers
 if (strng1 == "") {
    alertMsg =  " - Choose a password\n";
 }
  else if (illegalChars.test(strng1)) {
      alertMsg =  " - The password contains illegal characters\n";
    }
	else if (strng1 != strng2) {
      alertMsg =  " - Re-enter your password and confirm\n";
	}
  	else
			{alertMsg=""}
return alertMsg;
}
// more filed 
	
//check for date of birth	
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function checkDate(xday,xmonth,xyear)
{
	var x = document.forms[0].elements;
	var day =xday ;
	var month =xmonth ;
	var year =xyear ;
if ((day==0)||(month==0) ||(year==0)){
		alertMsg= " - Enter date of birth \n";
			
	}else if( year >= 1991 ){
		alertMsg= " - You have to be at least 16 years old to apply \n";
		}
	/* not now
	if (checkInternationalPhone(Phone.value)==false){
		alertMsg= "Please Enter a Valid Phone Number\n";
		}*/
	else {alertMsg=""}
return alertMsg;
}

/* check checkPhone*/
function checkPhone(strng,intNo,intwho)
{
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
var intwho
var intNo
var strname
var addin
/* if (strng == "")&& {
    alertMsg = "* You didn't enter a phone NO.\n";
 }*/

if (intwho==1){
	addin="in Personal information"
}else if (intwho==2) {
	addin="In Supervisor Phone"
} else {
	addin=""
}
		if (intNo==1){
			strname=" country code"
			}
		else if (intNo==2){
			strname="area code" 
			}
		else if (intNo==3){
			strname="number" 
			}
//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		   alertMsg =  " - The "+ strname+" "+ addin+  " contains illegal characters\n";
		}//Then we count the length of the number. It should have exactly ten digits — any more or less, and we reject it.
		else
			{alertMsg=""}
return alertMsg;
}
	if (alertMsg.length == l_Msg){
		return true;
	}else{
	alert(alertMsg);
			//document.write(alertMsg);
	return false;
	}
}
// 