// JavaScript Document

////////////////////////Check Register/////////////////////////////////////
function CheckRegisterPros() {

		
		if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.ProsApp.email.value))
		{
			alert("Please enter your email address");
			document.ProsApp.email.focus();
			return false;
		}

		if(document.ProsApp.p1.value=="")
		{
			window.alert('Please enter your password');
			document.ProsApp.p1.focus();
			return false;
		}

		if(document.ProsApp.p2.value=="")
		{
			window.alert('Please confirm your password');
			document.ProsApp.p2.focus();
			return false;
		}

		if(document.ProsApp.p1.value != "" && document.ProsApp.p2.value != "" && document.ProsApp.p1.value != document.ProsApp.p2.value)
		{
			window.alert('Please enter and confirm your password again');
			document.ProsApp.p1.value="";
			document.ProsApp.p2.value="";
			document.ProsApp.p1.focus();
			return false;
		}

		if(document.ProsApp.FamilyName.value=="")
		{
			window.alert('Please enter your Family name');
			document.ProsApp.FamilyName.focus();
			return false;
		}

		if(document.ProsApp.FirstName.value=="")
		{
			window.alert('Please enter your First name');
			document.ProsApp.FirstName.focus();
			return false;
		}

		if(document.ProsApp.Address.value=="")
		{
				window.alert('Please enter your address');
			document.ProsApp.Address.focus();
			return false;
		}

		if(document.ProsApp.City.value=="")
		{
			window.alert('Please enter your city');
			document.ProsApp.City.focus();
			return false;
		}
		
		if(document.ProsApp.CountryResd.value=="")
		{
			window.alert('Please enter your country of residence');
			document.ProsApp.CountryResd.focus();
			return false;
		}
	
		if(document.ProsApp.PhoneNumber.value=="")
		{
			window.alert('Please enter your phone number');
			document.ProsApp.PhoneNumber.focus();
			return false;
		}
		
		if(document.ProsApp.CountryBirth.value=="")
		{
			window.alert('Please enter your country of birth');
			document.ProsApp.CountryBirth.focus();
			return false;
		}
		
		if(document.ProsApp.Nationality.value=="")
		{
			window.alert('Please enter your country of citizenship');
			document.ProsApp.Nationality.focus();
			return false;
		}
					
		if(document.ProsApp.HometownP.value=="")
		{
			window.alert('Please enter  your family city of origin in Palestine');
			document.ProsApp.HometownP.focus();
			return false;
		}
		
		//////////////////Files verification
		var frm = document.ProsApp;
		fld = frm.cvfile; val = cmtrim(fld.value);
		var valext = '';
		if (val!='') {
			if (val.toLowerCase().indexOf('.pdf')>=0) valext = '.pdf';
			else if (val.toLowerCase().indexOf('.doc')>=0) valext = '.doc';
			if (valext=='') {
				fld.focus();
				alert('Only PDF and DOC files are suitable for uploading to this web site.');
				return false;
			}
		}
		
		var frm = document.ProsApp;
		fld = frm.photofile; val = cmtrim(fld.value);
		var valext = '';
		if (val!='') {
			if (val.toLowerCase().indexOf('.gif')>=0) valext = '.gif';
			else if (val.toLowerCase().indexOf('.jpg')>=0) valext = '.jpg';
			else if (val.toLowerCase().indexOf('.jpeg')>=0) valext = '.jpeg';
			else if (val.toLowerCase().indexOf('.png')>=0) valext = '.png';
			if (valext=='') {
				fld.focus();
				alert('Only GIF, JPEG and PNG images are suitable for uploading to this web site.');
				return false;
			}
		}
		//////////////////Files verification		
	
		if(!document.ProsApp.subscribe.checked)
		{
			window.alert('You have to agree to join Palestine Agency and abide by its Terms & Conditions');
			document.ProsApp.subscribe.focus();
			return false;
		}
			
}
		
function findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function addlang() {
	var lay = findObj('langs');
	if (lay) {
		var frm = document.frmMain;
		var i;
		var lang = '', langid = '', langexp = '', langexpid = '';
		var fld = frm.languagenew;
		for (i = 0; i < fld.length; i++) {
			if (fld[i].selected) {
				langid = fld[i].value;
				lang = fld[i].text;
				break;
			}
		}
		fld = frm.languageexpnew;
		for (i = 0; i < fld.length; i++) {
			if (fld[i].selected) {
				langexpid = fld[i].value;
				langexp = fld[i].text;
				break;
			}
		}
		if (langid!='' && lang!='' && langexp!='' && langexpid!='') {
			var j = -1;
			for (i = 0; i <= xlanguage; i++) {
				fld = eval('frm.language' + i);
				if (fld) ; else { j = i; break; }
			}
			if (j < 0) j = (++xlanguage);
			var os = '<div id="lang' + j + '" style="height:auto;visibility:visible;overflow:hidden;"><span class="formtext" style="width:120px"><input type="hidden" name="language' + j + '" value="' + langid + '">' + lang + '</span>&nbsp;&nbsp;';
			os += '<span class="formtext" style="width:200px"><input type="hidden" name="languageexp' + j + '" value="' + langexpid + '">' + langexp + '</span>&nbsp;&nbsp;';
			os += '<span class="formtextsmall"><a href="javascript:dellang(' + j + ')">Delete</a></span></div>\n';
			frm.languagenew.value = '';
			frm.languageexpnew.value = '';
			lay.innerHTML = lay.innerHTML + os;
		}
	}
}

function dellang(i) {
	var lay = findObj('lang' + i);
	if (lay) {
		lay.style.height = '1px';
		lay.style.visibility = 'hidden';
		lay.innerHTML = '';
	}
}
/*
*/

function cmtrim(str) {
	return str.replace(/^ */,"").replace(/ *$/,"");
}
