﻿var arrMandatoryEx=new Array();
var arrAlert = new Array();
	function formatFloat (num) {
		num = parseFloat(num)		
		if (num.toString()=='NaN') {
			num = 0;			
		}
		else {
			num = num*100
			num = Math.round (num)
			num = num/100
		}
		return num;
	}
function formatIntAsMand (num) {
		num = parseFloat(num)		
		if (num.toString()=='NaN') {
			num = '';			
		}
		else {			
			num = Math.round (num)
		}
		return num;
	}
	function checkValidFload (elFld) {
			strVal =  elFld.value
			strVal = strVal.replace(",", ".")	
			elValue = parseFloat(strVal)
			if (elValue.toString()=='NaN') {
				elValue = 0
				elFld.value = 0
				return false
			}
			else {
			elFld.value = formatFloat(elValue)
			return true
			}
		
	}
function ValidDate (currdate, toAlert) {
veryTmp=currdate
var tmpDate = currdate.split("/");
	if ((tmpDate.length < 3 && currdate !="") || tmpDate.length > 3) {
	currdate = "";}
	else if (isNaN(tmpDate[0]) || isNaN(tmpDate[1]) || isNaN(tmpDate[2])) {
		currdate = "";}
	else { 
		tmpDate[0] = GetNumFromStr (tmpDate[0])
		tmpDate[1] = GetNumFromStr (tmpDate[1])
		
		if (!(parseInt(tmpDate[1]) >0 && parseInt(tmpDate[1])<13 && parseInt(tmpDate[0]) >0 && parseInt(tmpDate[0]) <32 && 	parseInt(tmpDate[2])>1900 && parseInt(tmpDate[2])<2050 && ValidDateForMonth (tmpDate[0], tmpDate[1],tmpDate[2]))) {
			currdate = "";
		}
		else {			
			var r1,r2;
			r1=""; r2=""
			if (parseInt(tmpDate[0]) < 10) {r1 = "0";}
			if (parseInt(tmpDate[1]) < 10) {r2 = "0";}
			currdate = r1+parseInt(tmpDate[0]) + "/" + r2 + parseInt(tmpDate[1]) + "/" + parseInt(tmpDate[2])
			var f=ValidDateForMonth(parseInt(tmpDate[0]),parseInt(tmpDate[1]),parseInt(tmpDate[2]))		
		}
	}
	if (currdate == "" && toAlert) {alert(GetWord(953))
	}
return currdate;
}

function get_radio_value(radioar) {
 for(i = 0; i < radioar.length; i++)
 {	
	 if(radioar[i].checked) {return radioar[i].value;}
}
return '';
}

function GetNumFromStr (str) {
	var pos=str.indexOf("0")
	if (pos == 0 ) {str = str.substring(1,str.length);}
return str;
}

function ValidDateForMonth (dayIs, monthIs,yearIs) {
var mDays= new Array (31,28,31,30,31,30,31,31,30,31,30,31)
if (parseInt(yearIs) % 400 == 0 ) {mDays[1]=29;}
if (parseInt(yearIs) % 4 == 0 && parseInt(yearIs) % 100 != 0) {mDays[1]=29;}

if (parseInt(dayIs)>mDays[parseInt(monthIs)-1]) {return false;}
else {return true;}
}	
function calendar(t,fromyear,toyear,GW)
{
elementname=t.name;

currdate=window.document.getElementsByName(elementname)[0].value;
tmpCurrdate = ValidDate (currdate,false)
if (tmpCurrdate!=currdate) {
window.document.getElementsByName(elementname)[0].value=tmpCurrdate;
currdate = tmpCurrdate;
}
wnd = window.open('/MakeCalendar.asp?elementname='+elementname+'&fromyear='+fromyear+'&toyear='+toyear+'&currdate='+currdate+'&quest='+GW,'Calendar','toolbar=no,width=410,height=250,resizable=yes',true);

if (!wnd.closed) {wnd.focus();}
}

function OnOver(img,type) {
img.src = img.src.substring(0,img.src.length-5)+'2.'+type;
}

function OnOut(img,type) {
img.src = img.src.substring(0,img.src.length-5)+'1.'+type;
}

function check_fields(form_data) {
var flagValidate;

 for(i = 0; i < form_data.elements.length; i++)
 {flagValidate = true;
  atPos = form_data.elements[i].name.indexOf("__",1)
  //atPos = form_data.elements[i].name.search(/__$/)
  if(atPos != -1)
   {    
	   
    hTmp = document.getElementById('h_'+form_data.elements[i].name)
    if (hTmp!=null) {
	    if (hTmp.style.display == 'none') {flagValidate = false;}	
    }
    if (arrMandatoryEx[form_data.elements[i].name]!=null) {
	    for ( tmpDiv in  arrMandatoryEx[form_data.elements[i].name]) {		    
		    if (arrMandatoryEx[form_data.elements[i].name][tmpDiv]!='' && arrMandatoryEx[form_data.elements[i].name][tmpDiv]!=null) {
		    objTmp = document.getElementById(arrMandatoryEx[form_data.elements[i].name][tmpDiv])
		     if (objTmp!=null) {		    
			     if (objTmp.style.display == 'none') {flagValidate = false;}		     
		     }
		    }
	    }
	   
	    
	  
    }
    
    if(form_data.elements[i].value=="" && flagValidate==true)
    {alert(GetWord(954)); return false}
   
   }
 }
return true
}

function validEmail(email) {
  email1=email.value;
  wrong=0;
  atPos = email1.indexOf("@",1)
  if (atPos == -1){wrong=1}
  if (email1.indexOf("@",atPos+1) > -1){wrong=1}
  periodPos = email1.indexOf(".",atPos)
  if (periodPos == -1){wrong=1}
  if (periodPos+3 > email1.length){wrong=1}
if (wrong != 0){alert(GetWord(955)); email.value=""; return false}
return true
}

var minH, minW, maxW, maxH
minW=780; minH=67; maxW=2605; maxH=225;


function setWidthHeightImg (theEl) {
//width='1000' height='86'	
var scale
scale = (screen.availWidth-20)/theEl.width
theEl.width = theEl.width * scale
if (theEl.width>maxW) {theEl.width=maxW; theEl.height=maxH;}
else if (theEl.width<minW) {theEl.width = minW; theEl.height=minH;}
else {theEl.height = theEl.height * scale}

}

function setWidth (theEl) {
var scale
scale = (screen.availWidth-20)/theEl.width
theEl.width = theEl.width * scale
if (theEl.width>maxW) {theEl.width=maxW;}
else if (theEl.width<minW) {theEl.width = minW;}
}

//desing functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3) {
	  if ((x=MM_findObj(a[i]))!=null){
	  	document.MM_sr[j++]=x; 
	  	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	  }
  }
}

function MM_swapImageSimple() { //v3.0
  var i,j=0,x,a=MM_swapImageSimple.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3) {
	  if ((x=a[i])!=null){
	  	document.MM_sr[j++]=x; 
	  	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	  }
  }
}

function getParam(theKey){
  var qV = location.search.split(RegExp("[?&]"+theKey+"="));
  if(qV.length>1){
    return unescape((qV[1]+"&").split("&")[0]);
  }
}
function removeOneDivByGroup(divName , divInd, trueVal, idGroup) {arrGr_1 = new Array()arrGr_1 ['21'] = document.getElementsByName("packet21")[0].checkedarrGr_1 ['26'] = document.getElementsByName("packet26")[0].checkedarrGr_1 ['101'] = document.getElementsByName("packet101")[0].checkedarrGr_2 = new Array()arrGr_2 ['112'] = document.getElementsByName("packet112")[0].checkedarrGr_2 ['114'] = document.getElementsByName("packet114")[0].checkedarrGr_2 ['115'] = document.getElementsByName("packet115")[0].checkedarrGr_2 ['116'] = document.getElementsByName("packet116")[0].checkedarrGr_2 ['118'] = document.getElementsByName("packet118")[0].checkedarrGr_2 ['23'] = document.getElementsByName("packet23")[0].checkedarrGr_2 ['113'] = document.getElementsByName("packet113")[0].checkedarrGr_2 ['117'] = document.getElementsByName("packet117")[0].checkedarrGr_3 = new Array()arrGr_3 ['112'] = document.getElementsByName("packet112")[0].checkedarrGr_3 ['114'] = document.getElementsByName("packet114")[0].checkedarrGr_3 ['115'] = document.getElementsByName("packet115")[0].checkedarrGr_3 ['116'] = document.getElementsByName("packet116")[0].checkedarrGr_3 ['118'] = document.getElementsByName("packet118")[0].checkedflagShow = falsearrGr = eval("arrGr_"+idGroup)	for ( i_element in  arrGr) {				if (arrGr[i_element]==trueVal) {			flagShow = true			break;		}	}		if (flagShow) {						document.getElementById(divName+divInd).style.display = '';					}		else {			document.getElementById(divName+divInd).style.display = 'none';		}		}function SetValueBySelect(objName,objSelect) {var obj;obj = window.document.getElementsByName(objName)[0];obj.value=objSelect.options[objSelect.selectedIndex].text;}function ValidNIN (nin, toAlert) {
	if (nin!=null) {
		if (nin.value!='') {
	var match = /^ *[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z] ?\d{2} ?\d{2} ?\d{2} ?[ABCDFM] ?$/i.test(nin.value);
	if (!match && toAlert) {
		alert(GetWord(956))
		nin.focus();
	}
	}
	}
}
function filterNonNum (objToFilter) {
	objToFilter.value=objToFilter.value.replace(/[\D]/g, "");
	
}
function ValidUkPostalCode (postalcode, toAlert) {

if (postalcode!=null) {
		if (postalcode.value!='') {
	var match = /^ *(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW]) *[0-9][ABD-HJLNP-UW-Z]{2}) *$/i.test(postalcode.value);
	if (!match && toAlert) {
		alert(GetWord(957)+"\nA9 9AA\nA99 9AA\nA9A 9AA\nAA9 9AA\nAA99 9AA\nAA9A 9AA")
		postalcode.focus();
	}
	}
	}
}
function AbleForCSCSCard (obj) {
var total=window.document.getElementsByName("total")[0];
	if (obj!=null && total!=null && obj.checked && (total.value=='0' || total.value=='')) {
		alert(GetWord(1004))
	}
}
function GetWord(id) {
	if (arrAlert[id] != null) {
		return arrAlert[id];
	}
}
function alertLngCscs() {
	//cscs only
	
	
	objCscstestWhere = window.document.getElementsByName( "cscstest_where__")[0];
	if (objCscstestWhere == null) {
		document.getElementById('lnglondon1').style.display='none';
		return true;
	}
	
	cscsLang = window.document.getElementsByName( "cscs_lang__")[0]
	if (cscsLang==null) {cscs_lang=6}
	else {cscs_lang =cscsLang.value}
	
	if (parseInt(cscs_lang)>6 && parseInt(objCscstestWhere.value)==1) {
		document.getElementById('priceen1').style.display='none';
		document.getElementById('price1').style.display='';
	}
	else {
		document.getElementById('priceen1').style.display='';
		document.getElementById('price1').style.display='none';
	}
	
	if (parseInt(objCscstestWhere.value) <= 1) {
		document.getElementById('lnglondon1').style.display='none';
		return true;
	}
	objExamType = window.document.getElementsByName( "exam_type__")[0];
	if (objExamType == null) {
		document.getElementById('lnglondon1').style.display='none';
		return true;
	}
	
	if (parseInt(objExamType.value) <= 1||objExamType.value=='') {
		document.getElementById('lnglondon1').style.display='none';
		return true;
	}
	document.getElementById('lnglondon1').style.display='';
	return false;
}
function removeElement (elName , trueVal, curVal) {
		if (document.getElementById(elName)==null) return;		
		if (trueVal ==curVal) {
			document.getElementById(elName).style.display = '';
		}
		else {
			document.getElementById(elName).style.display = 'none';
		}
}
function removeAlertByLng(current) {
	if (document.getElementById('divTopLeft')==null) return;
	if (current=="1" || current=="10" || current=="13") {
		document.getElementById('divTopLeft').style.display = '';
	}
	else {
		document.getElementById('divTopLeft').style.display = 'none';
	}
}
function PaymentOptionsCSSexcept () {
var objDate, objVal, arrDate
        objDate = window.document.getElementsByName( "appointment_date__")[0];
        r_alert = window.document.getElementById('r_paymentalert' + '1');
        flag_where = false;
        if (r_alert!=null) r_alert.style.display = 'none';
        if (objDate!=null) {
                objVal = objDate.value;
                if (objVal!='') {
                        arrDate = objVal.split("/", 3);
                        var myDate=new Date();
                        myDate.setFullYear(arrDate[2],arrDate[1]-1,arrDate[0]);
                        weekDay = myDate.getDay()
                        //alert(weekDay+'**'+arrDate[2]+'**'+arrDate[1]+'&&'+arrDate[0]+'&&'+myDate);
                        if (weekDay==0 || weekDay==6) {
                                HideShowCheckedElement('payment0',false)
                                HideShowCheckedElement('payment2',false)
                                if (r_alert!=null) r_alert.style.display = '';
                        }
                        else {
                                flag_where = true;
                        }
                }
                else {
                        flag_where = true;
                }
        }
        if (flag_where) {
                objWhere = window.document.getElementsByName( "cscstest_where__")[0];
                if (objWhere!=null && objWhere.value=="1") {
                        HideShowCheckedElement('payment0',true)
                        HideShowCheckedElement('payment2',false)
                }
                else {
                        HideShowCheckedElement('payment0',true)
                        HideShowCheckedElement('payment2',true)
                }
        }
}
function HideShowCheckedElement (objID,action) {
var obj
        obj = window.document.getElementById(objID);
        if (obj!=null) {
                r_obj=window.document.getElementById('r_'+objID+'1');
                if (!action) {
                        obj.checked = false;
                        if (r_obj!=null) {
                                r_obj.style.display = 'none';
                        }
                        else {
                                obj.style.display = 'none';
                        }
                        //obj.style.display = 'none';
                }
                else {
                        if (r_obj!=null) {
                                r_obj.style.display = '';
                        }
                        else {
                                obj.style.display = '';
                        }
                }
        }
}
function CSCSShowList (cscstest_where) {
var divWhere, cscstest_where_name;
        cscstest_where_name = document.getElementsByName('test_center_name__')[0];
        divWhere = document.getElementById('testcenterwhere1');
        if (cscstest_where!=null && cscstest_where_name!=null && divWhere!=null) {
                if (cscstest_where.value==2 || cscstest_where.value==3) {
                        divWhere.style.display = '';
                }
                else {
                        divWhere.style.display = 'none';
                }
        }
}

