function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function HRM_findObj(n, d) { //v4.01
	alert(n+d);
	  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=HRM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	var haveError = false;
	
function emptyItemValidate(id,validateItem){
	thisItem = document.getElementById(id);
	
	labelTdThisItem = document.getElementById(id+'LabelTd');	
	imgTdThisItem = document.getElementById(id+'ImgTd');		
	errorTdThisItem = document.getElementById(id+'ErrorTd');			
	
	if(validateItem == 'textbox')
		if(thisItem.value == '' )
			empty(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
	
	if(validateItem == 'combo'){
		thisItemValue = thisItem.value;
		//usefull when validate state in ie...
		if(arguments[2])	
			thisItemValue=arguments[2];
		//***
		if(thisItemValue == '-1')
			empty(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
	}
	if(validateItem == 'radio'){
		if(document.getElementById('step1Form').gender[0].checked == false && document.getElementById('step1Form').gender[1].cheched == false)
			empty(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
	}
	
	return haveError;	

}

function dateValidate(){
	labelTdThisItem = document.getElementById('dateLabelTd');	
	imgTdThisItem = document.getElementById('dateImgTd');		
	errorTdThisItem = document.getElementById('dateErrorTd');			
	if(document.getElementById('birthDay').value == '-1' || document.getElementById('birthMont').value == '-1' || document.getElementById('birthYear').value == ''){
		labelTdThisItem.className='failLabel';
		errorTdThisItem.innerHTML = 'وارد کردن تاریخ دقیق تولد، شامل روز، ماه و سال الزامی است';
		imgTdThisItem.innerHTML = '<img src=hrm/img/nok.gif />';
		haveError = true;
	}
	else{
		labelTdThisItem.className='okLabel';
		imgTdThisItem.innerHTML = '';
	//	image.innerHTML = '<img src=hrm/img/ok.gif />';
		errorTdThisItem.innerHTML = '';
		haveError= false;
	}	
	return haveError;	
}

function gpaValidate(no){
	
		var numberReg ="^[0-9]+$" ;
		var regex = new RegExp(numberReg);
		gpaInt = document.getElementById('gpaInt'+no);
		gpaFloat = document.getElementById('gpaFloat'+no);
		labelTdThisItem = document.getElementById('gpa'+no+'LabelTd');	
		imgTdThisItem = document.getElementById('gpa'+no+'ImgTd');		
		errorTdThisItem = document.getElementById('gpa'+no+'ErrorTd');

		if(gpaInt.value == '' || gpaFloat.value == ''){
			labelTdThisItem.className='failLabel';
			errorTdThisItem.innerHTML = 'وارد کردن معدل دقیق الزامی است';
			imgTdThisItem.innerHTML = '<img src=hrm/img/nok.gif />';
			haveError = true;
			return false;
		}
		if(!(regex.test(gpaInt.value)) || !(regex.test(gpaFloat.value))){
			labelTdThisItem.className='failLabel';
			errorTdThisItem.innerHTML = 'وارد کردن معدل دقیق الزامی است';
			imgTdThisItem.innerHTML = '<img src=hrm/img/nok.gif />';
			haveError = true;
			return false;
		}else{
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
			return true;
		}
	
	
	}
function valueValidate(id,validateType){
	thisItem = document.getElementById(id);
	labelTdThisItem = document.getElementById(id+'LabelTd');	
	imgTdThisItem = document.getElementById(id+'ImgTd');		
	errorTdThisItem = document.getElementById(id+'ErrorTd');
	
		if(validateType == 'number'){
		var numberReg ="^[0-9]+$" 
		var regex = new RegExp(numberReg);
		if(!(regex.test(thisItem.value)))
			wrong(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
	}
	
	if(validateType == 'email'){
		var emailReg ="^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$"; 
		var regex = new RegExp(emailReg);
		if(!(regex.test(thisItem.value)))
			wrong(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);

	}
	
	if(validateType == 'floatPoint'){
		if (parseInt(thisItem.value)>20)
			wrong(labelTdThisItem,imgTdThisItem,errorTdThisItem);
		else
			correct(labelTdThisItem,imgTdThisItem,errorTdThisItem);
	}
	return haveError;
}	


function correct(label,image,error){
	label.className='okLabel';
	image.innerHTML = '';
//	image.innerHTML = '<img src=hrm/img/ok.gif />';
	error.innerHTML = '';	
	haveError= false;
	}

function wrong(label,image,error){
	label.className='failLabel';
	error.innerHTML = '.'+thisItem.getAttribute('label')+' شما صحیح نمی باشد';
	image.innerHTML = '<img src=hrm/img/nok.gif />';
	haveError = true;
	}

function empty(label,image,error){
	label.className='failLabel';
	thisItemLabelText=(thisItem.getAttribute('label')==null)?'این قسمت':thisItem.getAttribute('label');
	error.innerHTML = 'وارد کردن '+thisItemLabelText+' الزامی است';
	image.innerHTML = '<img src=hrm/img/nok.gif />';
	haveError = true;
	}
	
function validateEducation(){

	step2Error=false;
	for(i=0;i<2;i++){	
		if(document.getElementById('step2Table'+(i)).style.display=='block'){
			if(i==0 || document.getElementById('major'+i).value !='-1' || document.getElementById('gpaInt'+i).value !='' || document.getElementById('collegeName'+i).value !='' )  {
				if(emptyItemValidate('major'+i,'combo'))
					step2Error = true;
							
				if(!gpaValidate(i)){
					step2Error = true;
				}
				if(emptyItemValidate('date'+i,'textbox'))
					step2Error = true;
				if(emptyItemValidate('collegeName'+i,'textbox'))
					step2Error = true; 
				if(emptyItemValidate('collegeLocation'+i,'combo'))
					step2Error = true;
				if(i != 0)
					if(emptyItemValidate('collegeType'+i,'combo'))
						step2Error = true;
			}
		}
	}

	if(emptyItemValidate('englishKnow','combo'))
		step2Error = true;
	
	if(!step2Error){
		submitRegister('step2');
	}else{
		alert('لطفا فرم را به دقت بررسی نموده و خطاها را تصحیح نمایید');
	}
	
}	

function validateStep1(){
	step1Error = false;
	
	if(emptyItemValidate('fName','textbox'))
		step1Error = true;
	if(emptyItemValidate('lName','textbox'))
		step1Error = true;
	if(emptyItemValidate('pNumber','textbox'))
			step1Error = true;
	if(emptyItemValidate('nationalCode','textbox'))
			step1Error = true;
	if(emptyItemValidate('pLocation','textbox'))
			step1Error = true;
	if(emptyItemValidate('phone','textbox'))
			step1Error = true;
	if(emptyItemValidate('address','textbox'))
		step1Error = true;
	if(dateValidate())
			step1Error = true;
	 if(emptyItemValidate('marital','combo'))
	 		step1Error = true;
	if(emptyItemValidate('military','combo'))
			step1Error = true;
	if(emptyItemValidate('userDoc','textbox'))
			step1Error = true;
	if(document.getElementById('step1Form').nationalCode.value != '') 
		if(valueValidate('nationalCode','number'))
			step1Error = true;
	if(document.getElementById('step1Form').pNumber.value != '') 
		if(valueValidate('pNumber','number'))
			step1Error = true;
	if(document.getElementById('step1Form').email.value != '') 
		if(valueValidate('email','email'))
			step1Error = true;

	if(!step1Error){
		submitRegister('step1');
	}else{
		alert('لطفا فرم را به دقت بررسی نموده و خطاها را تصحیح نمایید');
	}
 }

	
	xajax.callback.global.onExpiration = function() {
		alert('خطا در دریافت اطلاعات \n لطفا مجددا سعی کنید');
		cityLoadImg = xajax.$('cityLoadImg');
		if( cityLoadImg.style.display=='block' ){
			cityLoadImg.style.display = 'none';
		}
	}
	xajax.callback.global.onFailure = function(args)
	{
		alert(args.request.status+" خطای شماره "+"\n در دریافت اطلاعات ، لطفا مجددا سعی کنید ");
		if( cityLoadImg.style.display=='block' ){
			cityLoadImg.style.display = 'none';
		}
	}
	
	function setUserImg(path,picName){
		document.getElementById('userPic').src='hrm/'+path+picName;
	}
	
	function setUserDocument(path,picName){
		document.getElementById('userDoc').value=picName;
	}
	 
	function submitRegister(stepName)
		{

		//	xajax.$(stepName+'SubmitButton').disabled=true;
			//xajax.$(stepName+'SubmitButton').value="   لطفا کمی صبر کنید  ";

			xajax.$(stepName+'Div').style.display='none';
			xajax.$('loadingDiv').style.display='block';
			xajax_processForm(xajax.getFormValues(stepName+'Form'));
			return false;
		}
	function updateSelectListInnerHTML(parentId,selectListId)
		{
			
			if(parentId!=0 && parentId!=-1)	{
				xajax.$('cityLoadImg').style.display='block';
				xajax.$('city').innerHTML='لطفا چند لحظه صبر کنید...';
			}
			if(parentId==-1){
				xajax.$('city').innerHTML='لطفا ابتدا استان را مشخص کنید...';
			}
				
				
			xajax_setSelectListOptions(parentId,selectListId);
		
			return false;
		}		
		
		
	var stateSelectedIndexValue = -1;	
	function call_updateSelectListInnerHTML	(){
		updateSelectListInnerHTML(stateSelectedIndexValue,'cityTd');
	}
