/*
function loadFragmentInToElement(fragment_url, element_id, inittxt) {
      var element = document.getElementById(element_id); 
      xmlhttp.open("GET", fragment_url); 
      xmlhttp.onreadystatechange = function() { 
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        	element.parentNode.innerHTML = xmlhttp.responseText;
    	}
      }
      xmlhttp.send(null); 
}
      
      
function search(qstr){
	if(document.getElementById('searchPostCode').value == "" || document.getElementById('searchPostCode').value == "ENTER POSTCODE") {
		alert('Please enter postcode');
	}else {
		if(qstr == ''){
			qstr = 'postcode='+document.getElementById('searchPostCode').value;
			init = "Searching ...";
		}else {
			if(document.getElementById('uemail').value == "" || document.getElementById('upostcode').value==""){
				alert('Please fill in your email and postcode.');
				return false;
			}
			qstr = 'postcode='+document.getElementById('upostcode').value+'&email='+document.getElementById('uemail').value;
			init = "Sending ...";
		}
		loadFragmentInToElement('search_nanny.php?'+qstr, 'currentstatus', init);
	}
}
*/
function loadMessageDiv(fragment_url, element_id, inittxt, country_id) {
      xmlhttp.open("GET", fragment_url); 
      xmlhttp.onreadystatechange = function() { 
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (srcBoxNumber>0) {
				hideSrcError();
			}
			var tmpError = xmlhttp.responseText.split('*++*');
			var element = document.getElementById(element_id + tmpError[0]); 
        	element.innerHTML = tmpError[1];
        	srcBoxNumber = tmpError[0];
        	showSrcError(country_id);
    	}
      }
      xmlhttp.send(null); 
}
      
      
function search(qstr, country_id){
	country_id = (country_id) ? (country_id) : 1;
	var proceedSrch=1;
	if(country_id==2){
		if(document.getElementById('searchCounty').value == "0") {
			alert('Please select county');
			proceedSrch=0;
		}
	}else{
		if(document.getElementById('searchPC1').value == "" || document.getElementById('searchPC1').value == "ENTER POSTCODE") {
			alert('Please enter postcode');
			proceedSrch=0;
		}
	}
	if(proceedSrch==1){
		if(qstr == ''){
			if(country_id==2){
				qstr = 'postcode='+document.getElementById('searchCounty').value;
			}else{
				qstr = 'postcode='+document.getElementById('searchPC1').value;
			}
		}else {
			if(document.getElementById('uemail').value == "" || document.getElementById('upostcode').value==""){
				if(country_id==2){
					alert('Please fill in your email and county.');
				}else{
					alert('Please fill in your email and postcode.');
				}
				return false;
			}else if (checkEmail(document.getElementById('uemail').value)==false) {
				alert('Please fill in your valid email address.');
				return false;
			}
			qstr = 'postcode='+document.getElementById('upostcode').value+'&email='+document.getElementById('uemail').value+'&ran=' +  Math.random();
			document.getElementById('sndEmlMsg').innerHTML = "<FONT CLASS='ecchdTxT1'>Sending email...</FONT>";
		}
		
		loadMessageDiv(_gConfDocRoot+'index/search_nanny.php?'+qstr, 'searchTD', init, country_id);
	}
}


function showhide_divs(obj, show){
	if(obj){
		if(show){
			document.getElementById(obj).style.visibility = "visible";
			document.getElementById(obj).style.display = "block";
		} else {
			if(document.getElementById('wait_family')){
				document.getElementById(obj).style.visibility = "hidden";
				document.getElementById(obj).style.display = "none";
			}
	
		}
	}
}

function clearPopulate(fldArr, valArr, clear){
	var obj;
	if(clear){
		for(i=0; i<fldArr.length; i++){
			obj = document.getElementById(fldArr[i]);	
			obj.value = '';
		}
	} else {
		for(i=0; i<fldArr.length; i++){
			obj = document.getElementById(fldArr[i]);	
			obj.value = valArr[i];
		}
	}
}

//AJAX code
var xmlhttp=false;       
var response = '';
function initAJAX(){

     
      /*@cc_on @*/ 
      /*@if (@_jscript_version >= 5) 
      // JScript gives us Conditional compilation, we can cope with old IE versions. 
      // and security blocked creation of the objects. 
        try { 
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
         try { 
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
         } catch (E) { 
          xmlhttp = false; 
         } 
        } 
      @end @*/ 
      if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
        xmlhttp = new XMLHttpRequest(); 
      } 
}



function runSodexhoPass(fragment_url, company, registrationFees) {
				
	var voucher_amount_val = document.calendar.voucher_amt.value;
	var voucher_pence_val = document.calendar.voucher_pence.value;
	
	//alert(fragment_url);
      xmlhttp.open("GET", fragment_url); 
      xmlhttp.onreadystatechange = function() {
		document.getElementById('verrortxt').innerHTML = document.getElementById('verrortxt').innerHTML+".";

	      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
				//alert(xmlhttp.responseText);
           		var response = xmlhttp.responseText.split('####') ;
				showhide(true, new Array('lowerbuttons'));

            if(response[0] == '1'){
            	document.getElementById('verrortxt').innerHTML = response[1];
			} else if(response[0] == '0'){
				showhide(true, new Array('spTxt'));
           		showhide(false, new Array('voucherTab'));

                document.getElementById('verrortxt').innerHTML = "";
           		document.calendar.vstatus.value = '1';
      			document.calendar.vusername.value = document.calendar.vuser.value;
      			document.calendar.vpassword.value = document.calendar.vpass.value;
      			document.calendar.vamount.value = voucher_amount_val + "." + voucher_pence_val;
      			      			
	     		clearPopulate(new Array('voucher_amt', 'voucher_pence', 'vpass'), '', true);
				if(document.calendar.voucher_type.value != "care4"){
		     		clearPopulate(new Array('vuser'), '', true);
				}
      			ccPayNursery(registrationFees);
			}else{
            	document.getElementById('verrortxt').innerHTML = "Failure connecting to "+ company;
			}
           } 
      }
      xmlhttp.send(null); 
} 


function checkBal(reg_fees){
	var comp;
	
	var registrationFees = reg_fees;

	if(document.calendar.voucher_type.value == "sp"){
		comp = "Sodexho Pass";
	}else if(document.calendar.voucher_type.value == "care4"){
		comp = "care-4";
	}else if(document.calendar.voucher_type.value == "mfcv"){
		comp = "My Family Care Vouchers";
	}
	document.getElementById('verrortxt').innerHTML = "Connecting to "+ comp;
	document.getElementById('lowerbuttons').style.display = "none";
	document.calendar.vstatus.value = '';

	initAJAX();
	var url = '../index/checkVourcher.php?username='+document.getElementById('vuser').value+'&password='+document.getElementById('vpass').value;
	url  += '&vourcherTyp='+document.calendar.voucher_type.value;
		
	url = url + '&amount='+document.getElementById('voucher_amt').value + "." + document.calendar.voucher_pence.value;
	//alert(url);
	runSodexhoPass(url, comp, registrationFees);
	
	// this is added by sanjay
	document.getElementById('voucher_amt').value = '';
}


function checkBalBussyBees(reg_fees){
	
	var registrationFees = reg_fees;
	
	document.getElementById('verrortxt').innerHTML = "Connecting to Busy Bees ";
	//document.getElementById('lowerbuttons').style.display = "none";
	document.calendar.vstatus.value = '';

	showhide(true, new Array('spTxt'));
	showhide(false, new Array('voucherTab'));

    document.getElementById('verrortxt').innerHTML = "";
	document.calendar.vstatus.value = '1';
	document.calendar.vusername.value = document.calendar.vuser.value;
	document.calendar.vpassword.value = document.calendar.vpass.value;
	
	document.calendar.vuser_busy.value = document.calendar.vuser.value;
	document.calendar.vpass_busy.value = document.calendar.vpass.value;
	document.calendar.date_of_birth_show_busy.value = document.calendar.vdd.value + '/' + document.calendar.vmm.value + '/' + document.calendar.vyyyy.value;
	
	document.calendar.vamount.value = document.calendar.voucher_amt.value + "." + document.calendar.voucher_pence.value;
	clearPopulate(new Array('voucher_amt', 'voucher_pence', 'vpass', 'vdd', 'vmm', 'vyyyy'), '', true);
	
	if(document.calendar.voucher_type.value != "care4"){
 		clearPopulate(new Array('vuser'), '', true);	
	}
	
	ccPayNursery(registrationFees);	
	
}


function accor(reg_fees){
	//showhide(true, new Array('accorTxt'));
	var registrationFees = reg_fees;
	document.getElementById('verrortxt').innerHTML = "";
            			
	document.calendar.vstatus.value = '1';
	showhide(false, new Array('voucherTab'));
      document.calendar.vusername.value = document.calendar.vuser.value;
      document.calendar.vpassword.value = document.calendar.vpass.value;
      document.calendar.vamount.value = document.calendar.voucher_amt.value + "." + document.calendar.voucher_pence.value;

      clearPopulate(new Array('voucher_amt', 'voucher_pence','vuser', 'vpass'), '', true);
      ccPayNursery(registrationFees);
	

}
function changeStat(stat, div, reg_fees){

	var s = parseInt(document.calendar.vstatus.value); 
	var registrationFees = reg_fees;
	ccPayNursery(registrationFees);

	if(s!=1) {
		showhide(stat, new Array(div)); 
	} 

 	if(!stat){
		
		showhide(stat, new Array('spTxt', 'spNote'));
     		clearPopulate(new Array('voucher_amt', 'voucher_pence',  'vpass'), '', true);
		if(document.calendar.voucher_type.value != "care4"){
			clearPopulate(new Array('vuser'), '', true);
		}

		
	}
	setFullAmts();

}
function checkVoucherDetails(typ){
	var ele = document.calendar.voucher_amt;
	var ele2 = document.calendar.voucher_pence;
	var amt = parseFloat(document.calendar.cc_amount.value) + parseFloat(document.calendar.vamount.value);
		
	if(document.calendar.vuser.value=="" || document.calendar.vpass.value==""){
		alert("Please enter "+typ+" details ");
		return false;
	}

	if(document.calendar.pay_type[1].checked){
		return checkVoucherAmt(ele, ele2, amt);
	} else {
		var str = amt.toString();
		if(str.indexOf('.') != -1){
			var parts = str.split('.');
			ele.value = parseInt(parts[0]);
			ele2.value = parseInt(parts[1]);
		} else {
			ele.value = parseInt(amt);
			ele2.value = 0;
		}
	}
	return true;
}

function checkbusybeesdetails(){
	
	var frm = document.forms['calendar'];
    var el = frm.elements;
    var error = "";
    
    if(el['vuser'].value == '' ) {
	    error += 'Busy Bees Username.\n';
	}
	
	if(el['vpass'].value == '' ) {
	    error += 'Busy Bees Password.\n';
	}
	
	if(el['vdd'].value == '' ) {
	    error += 'Date of Birth(date).\n';
	}
	
	if(el['vmm'].value == '' ) {
	    error += 'Date of Birth(month).\n';
	}
	
	if(el['vyyyy'].value == '' ) {
	    error += 'Date of Birth(year).\n';
	}
		
	if(el['pay_type'][0].checked == false) {
		if(!el['voucher_amt'].value) {
			error += 'Part payment amount.\n';		
		}
	}
	
	if(error != "") {
		error = "The following mandatory fields have not been filled\n\n" + error;
		alert(error);
		return false;
	}
  	
    return true;
	
}


function checkVoucherAmt(ele, ele2, amt){
	var err = "";
	var amtTxt = ele.value + "."+ ele2.value;
	if(isNaN(amtTxt)){
		amtTxt = 0;
	}
	if(parseFloat(amtTxt)==0){
		err = "Please enter the amount to be paid by your childcare voucher.";
	}
	if(err==""){
		thisamt = parseFloat(amt) - parseFloat(amtTxt);
		if(thisamt < 0){
			err= "Voucher amount is more than the grand total";
		}
	}
	if(err!=""){
		alert(err);
		ele.select();
		return false;
	}
	return true;

}
function ccPayNursery(registrationFees){
			
	if(document.calendar.pay_type[1].checked==true){
		if(parseFloat(document.calendar.grand_total.value) < parseFloat(document.calendar.vamount.value)){
			document.calendar.vamount.value = document.calendar.grand_total.value;
		}
	}else{
		document.calendar.vamount.value = document.calendar.grand_total.value;
	}
	
	var gtotal = parseFloat(document.calendar.grand_total.value);
	var vAmt = parseFloat(document.calendar.vamount.value);
	var ccAmt = parseFloat(document.calendar.cc_amount.value);
	
	//alert(gtotal + ' :gtotal ' + vAmt + ' :vAmt ' + ccAmt + ' :ccAmt ' + bal + ' :bal' + ' ==== ' + document.calendar.voucher_amt.value);

	var bal = gtotal ;
	if((parseInt(document.calendar.vstatus.value) > 0 && document.calendar.chk_ccvoucher.checked)  || document.calendar.voucherID.value != ""){
		bal = bal - vAmt;
		if(vAmt >0 ){
			showhide(true, new Array('spTxt', 'spNote'));
		}
	}
	
	var stat = false;
	if((bal >0 &&   bal < document.calendar.grand_total.value )|| (ccAmt > 0 && document.calendar.voucherID.value  ) ){
		stat = true;
		if(ccAmt > 0 && document.calendar.voucherID.value  ){
			bal = ccAmt;

		}
		
		if(registrationFees){
			bal += registrationFees;
		}
		
		//alert(bal + '===');
		
		document.getElementById('ccAmtTxt').innerHTML = "&pound;"+ formatNumber(bal, '###########.00', false) + "&nbsp;&nbsp;";
	}
	
	if(registrationFees){
		//stat = true;	
	}

	document.calendar.cc_amount.value = bal;

	setFullAmts();

	showhide(stat, new Array('ccTxt'));

}
function setFullAmts(){
	//set inner HTML

	var amt;
	
	amt = (parseFloat(document.calendar.cc_amount.value) + parseFloat(document.calendar.vamount.value))/2 ;
	//document.getElementById('fullamt').innerHTML = "&pound;"+ formatNumber(amt, '###########.00', false);
	document.getElementById('fullamt').innerHTML = "&pound;"+ formatNumber(document.calendar.grand_total.value, '###########.00', false);
	document.getElementById('vAmountTxt').innerHTML = "&pound;"+ formatNumber(parseFloat(document.calendar.vamount.value), '###########.00', false)+'&nbsp;&nbsp;';


}
function accorCheck(){
	var ele = document.calendar.accor_voucher_amt;
	var ele2 = document.calendar.accor_voucher_pence;
	var amt = parseFloat(document.calendar.cc_amount.value)  + parseFloat(document.calendar.accor_amount.value);

	if(document.calendar.accor_user.value=="" || document.calendar.accor_pass.value==""){
		alert("Please enter Accor Membership No. and PIN");
		return false;
	}


	if(document.calendar.accorpay_type[1].checked){
		return checkVoucherAmt(ele, ele2, amt);
	} else {
		var str = toString(amt);
		if(str.indexOf('.') != -1){
			var parts = str.split('.');
			ele.value = parseInt(parts[0]);
			ele2.value = parseInt(parts[1]);
		} else {
			ele.value = parseInt(amt);
			ele2.value = 0;
		}
	}
	return true;
}
function validAmt(fld, msg, val){
	var err = false;

	if(isNaN(fld.value)){
		err = true;
	}
	if(val == '%' && parseFloat(fld.value)>100){
		err = true;
	} else if(val == 'P' && (parseFloat(fld.value)>99 || fld.value.indexOf('.') >=0) ){
		err = true;
	} else if(val == 'GBP' && (fld.value.indexOf('.') >=0) ){
		err = true;
	}
	if(err){
		alert('Invalid '+msg);
		fld.select()
		return false;
	}
	return true;
}

function changeCareIcon(val, obj, tickObj, faceObj){
	if(document.carer.dependent_id.value == ''){ 
		obj.src = tickObj.src;
		document.carer.dependent_id.value = val;
	} else if(document.carer.dependent_id.value == val){
		obj.src = faceObj.src;
		document.carer.dependent_id.value = '';
	}
	
}
function check_blank(formName,fieldarr) {
	var err = "";
	if(document.getElementById('searchPC1').value == "" || document.getElementById('searchPC1').value == "ENTER POSTCODE") {
		if(formName.callcentre.value == '1'){
			if(formName.ut1.value == '1'){
				serviceType = "childminder";
			}else if(formName.ut1.value == '3'){
				serviceType = "site";
			}else{
				serviceType = "nursery";
			}
			//serviceType = (formName.ut1.value == '1') ? "childminder" : "nursery";
			err += "You cannot book a " + serviceType + "space without first inserting a postcode. The postcode will usually, but not always, be the parents home postcode.";
		}else {
			err += "Please enter postcode.";
		}
		alert(err);
	}else {
		formName.code.value=document.getElementById('searchPC1').value;
		if(fieldarr){
	      	for (i = 0; i < fieldarr.length; ++i) {
	      		 eval('formName.' + fieldarr[i] + '.value = document.getElementById("' + fieldarr[i] + '").value');
	      	}
		}
		formName.submit();	
	}
}

function check_blankIreland(formName,fieldarr) {
	var err = "";
		
	if(document.getElementById('searchCountyName').value=="0"){
		err = "County";	
	}else if(document.getElementById('searchMilesName').value=="0"){
		err = "Miles";	
	}
	if(err){
		alert('Please select ' + err +'.');
		return false;	
	}else{
		formName.code.value = document.getElementById('searchCountyName').value;	
		formName.miles.value = document.getElementById('searchMilesName').value;	
		
		formName.submit();
	}	
}

function showProviderFromClosest(formName, codeVal){
	document.forms[formName].code.value = codeVal;

	document.forms[formName].submit();
}

<!-- Hide from older browsers

              // Original JavaScript code by Duncan Crombie: dcrombie@chirp.com.au
              // Please acknowledge use of this code by including this header.

              // CONSTANTS
             var separator = ",";  // use comma as 000's separator
             var decpoint = ".";  // use period as decimal point
             var percent = "%";
             var currency = "$";  // use dollar sign for currency

             function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
               if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

               if (number - 0 != number) return null;  // if number is NaN return null
               var useSeparator = format.indexOf(separator) != -1;  // use separators in number
               var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
               var useCurrency = format.indexOf(currency) != -1;  // use currency format
               var isNegative = (number < 0);
               number = Math.abs (number);
               if (usePercent) number *= 100;
               format = strip(format, separator + percent + currency);  // remove key characters
               number = "" + number;  // convert number input to string

                // split input value into LHS and RHS using decpoint as divider
               var dec = number.indexOf(decpoint) != -1;
               var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
               var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

                // split format string into LHS and RHS using decpoint as divider
               dec = format.indexOf(decpoint) != -1;
               var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
               var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

                // adjust decimal places by cropping or adding zeros to LHS of number
               if (srightEnd.length < nrightEnd.length) {
                 var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
                 nrightEnd = nrightEnd.substring(0, srightEnd.length);
                 if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

            // patch provided by Patti Marcoux 1999/08/06
                 while (srightEnd.length > nrightEnd.length) {
                   nrightEnd = "0" + nrightEnd;
                 }

                 if (srightEnd.length < nrightEnd.length) {
                   nrightEnd = nrightEnd.substring(1);
                   nleftEnd = (nleftEnd - 0) + 1;
                 }
               } else {
                 for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
                   if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
                   else break;
                 }
               }

                // adjust leading zeros
               sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
               while (sleftEnd.length > nleftEnd.length) {
                 nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
               }

               if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
               var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
               output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
               if (isNegative) {
                 // patch suggested by Tom Denn 25/4/2001
                 output = (useCurrency) ? "(" + output + ")" : "-" + output;
               }
               return output;
             }

             function strip(input, chars) {  // strip all characters in 'chars' from input
               var output = "";  // initialise output string
               for (var i=0; i < input.length; i++)
                 if (chars.indexOf(input.charAt(i)) == -1)
                   output += input.charAt(i);
               return output;
             }

             function separate(input, separator) {  // format input using 'separator' to mark 000's
               input = "" + input;
               var output = "";  // initialise output string
               for (var i=0; i < input.length; i++) {
                 if (i != 0 && (input.length - i) % 3 == 0) output += separator;
                 output += input.charAt(i);
               }
               return output;
             }

  		 // Stop hiding -->


function showhideItems(showdivs, hidedivs, act){
	if(showdivs != ''){
      	for (i = 0; i < showdivs.length; ++i) {
      		e = document.getElementById(showdivs[i]);
      		if(act){	
      			e.className = "visible";
      		} else {
      			e.className = "hidden";
      		}
      	}
	}
	
	if(hidedivs != ''){
      	for (i = 0; i < hidedivs.length; ++i) {
      		e = document.getElementById(hidedivs[i]);
      		if(act){	
      			e.className = "hidden";
      		} else {
      			e.className = "visible";
      		}
      	}
	}
}

function showhideSites(obj){
	if(obj.checked){
		showhideItems(new Array('siteNum'),'', 'true')
	}else{
		showhideItems('',new Array('siteNum'), 'false')
		document.getElementById('site_num').value=1;
		showSites(1);
	}	
}
function insertNewRow(tab, fldArr, objTyp){

	var parentTable = document.getElementById(tab); 
	var cellObj ;
     	var tbody_obj = document.createElement("tbody");
     	tr_obj = add_table_row(0);

	for(i=0; i<fldArr.length; i++){
    		cellObj = add_table_cell( tr_obj, fldArr[i], objTyp[i]);
      	tbody_obj.appendChild(tr_obj);
	}
	parentTable.appendChild(tbody_obj);

}

	
function deleteRow(cellObj){
	var con = "Are you sure you want to delete this entry?";
	if(confirm(con)){ 
      	cellObj.value = '';
      	cellObj.parentNode.parentNode.style.visibility ='hidden';
      	cellObj.parentNode.parentNode.style.display ='none';
	}
	return false;
}
// function creates a tr object and sends it back

function add_table_row() {

	tr_obj = document.createElement("tr");
	return tr_obj;
}
// function creates a td object and sends it back

function add_table_cell(tr_obj, objname, objTyp) {

	td_obj = document.createElement("td");
	switch(objTyp){
		case  "input":
      		fldObj = document.createElement("input");
            	for(att in objname){
            		if(att == 'event'){
					fldObj.onclick = eval(objname[att]) ;
				} else {
            	 		fldObj.setAttribute(att, objname[att]);
            		}
            	}
      		td_obj.appendChild(fldObj);

		break;
		case  "checkbox":
      		fldObj = document.createElement("input");
/*      		fldObj.setAttribute('type','checkbox');
      		fldObj.setAttribute('value', objval);
      		fldObj.setAttribute('name',objname);
      		fldObj.setAttribute('class',objclass);
*/
      		//fldObj.setAttribute('size',5);
      		td_obj.appendChild(fldObj);
		break;
		case  "button":
      		fldObj = document.createElement("input");

			fldObj.onclick = eval(objeve) ;
/*
      		fldObj.setAttribute('type','button');
      		fldObj.setAttribute('value',objval);
      		fldObj.setAttribute('name',objname);
      		fldObj.setAttribute('className',objclass);
*/
      		//fldObj.setAttribute('size',5);
      		td_obj.appendChild(fldObj);
		break;	
	}

	tr_obj.appendChild(td_obj);
	td_obj.setAttribute('align','center');
	return td_obj;
}

function check_serach_fields(user_type){
	
	var frm = document.forms['query'];
    var el = frm.elements;
    var error = ""; 
	
	if(el['firstname'].value == '' ) {
	    error += 'Firstname.\n';
	}
	
	if(el['surname'].value == '' ) {
	    error += 'Surname.\n';
	}
	
	if(el['post'].value == '' ) {
	    error += 'Postcode.\n';
	}
	
	if(el['email'].value == '' ) {
	    error += 'Email.\n';
	}
	
// 	if(user_type==2){
// 		if(el['nursery_name'].value == '' ) {
// 		    error += 'Nursery Name.\n';
// 		}	
// 	}
	
	if(error){
	    
	    error = "The following mandatory fields have not been filled\n\n" + error;
		alert(error);
		return false;

	}
}

function check_serach_pro(country_id){
	
	var frm = document.forms['query'];
    var el = frm.elements;
    var error = ""; 
	
	if(el['firstname'].value == '' ) {
	    error += 'Firstname.\n';
	}
	
	if(el['surname'].value == '' ) {
	    error += 'Surname.\n';
	}
	if(country_id==1){
		if(el['post'].value == '' ) {
		    error += 'Postcode.\n';
		}
	}else{
		if(el['countyIre'].value == '--Select--' ) {
		    error += 'County.\n';
		}
	}	
	if(el['email'].value == '' ) {
	    error += 'Email.\n';
	}
	if(error){
	    
	    error = "The following mandatory fields have not been filled\n\n" + error;
		alert(error);
		return false;

	}
}


// function delete_file(Obj) {
// 	if(document.getElementById(Obj).checked) {
// 		if(confirm('Are you sure you want  to delete the file?')) {
// 			initAJAX();
// 			var url = '../index/delete_logo_file.php?logo_file_id='+ document.getElementById(Obj).value;
// 		     xmlhttp.open("GET", url, true); 
// 		     xmlhttp.send(url);
// 			  xmlhttp.onreadystatechange = function() { 
// 			    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
// 			    	if(xmlhttp.responseText) {
// 				    	var x = document.getElementById('deldiv');
// 				    	document.getElementById('deldiv').parentNode.removeChild(x);
// 				    	document.getElementById('image_upload').style.visibility = 'visible';
// 				    	document.getElementById('image_upload').style.display = 'block';
// 			    	}
// 			    } 
// 		    }
// 	    } else{
// 		   document.getElementById(Obj).checked = false; 
// 	    }
//     }
// }
function delete_file(Obj, delDiv, showDiv, tableName, field, orderNo, hiddenObj) {
	if(document.getElementById(Obj).checked) {
		if(confirm('Are you sure you want  to delete the file?')) {
			initAJAX();
			var url = '../index/delete_logo_file.php?logo_file_id='+ document.getElementById(Obj).value + '&table_name=' + tableName + '&field=' + field;
		     xmlhttp.open("GET", url, true); 
		     xmlhttp.send(url);
			  xmlhttp.onreadystatechange = function() { 
			    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
			    	if(xmlhttp.responseText) {
				    	var x = document.getElementById(delDiv);
				    	document.getElementById(delDiv).parentNode.removeChild(x);
				    	document.getElementById(showDiv).style.visibility = 'visible';
				    	document.getElementById(showDiv).style.display = 'block';
			    	}
			    } 
		    }
	    	document.getElementById(hiddenObj).value = '';
	    } else{
		   document.getElementById(Obj).checked = false; 
	    }
    }
}
function number_format(p,d) 
{
  var r;
  if(p<0){p=-p;r=format_number2(p,d);r="-"+r;}
  else   {r=format_number2(p,d);}
  return r;
}
function format_number2(pnumber,decimals) 
{
  var strNumber = new String(pnumber);
  var arrParts = strNumber.split('.');
  var intWholePart = parseInt(arrParts[0],10);
  var strResult = '';
  if (isNaN(intWholePart))
    intWholePart = '0';
  if(arrParts.length > 1)
  {
    var decDecimalPart = new String(arrParts[1]);
    var i = 0;
    var intZeroCount = 0;
     while ( i < String(arrParts[1]).length )
     {
       if( parseInt(String(arrParts[1]).charAt(i),10) == 0 )
       {
         intZeroCount += 1;
         i += 1;
       }
       else
         break;
    }
    decDecimalPart = parseInt(decDecimalPart,10)/Math.pow(10,parseInt(decDecimalPart.length-decimals-1)); 
    Math.round(decDecimalPart); 
    decDecimalPart = parseInt(decDecimalPart)/10; 
    decDecimalPart = Math.round(decDecimalPart); 

    //If the number was rounded up from 9 to 10, and it was for 1 'decimal' 
    //then we need to add 1 to the 'intWholePart' and set the decDecimalPart to 0. 

    if(decDecimalPart==Math.pow(10, parseInt(decimals)))
    { 
      intWholePart+=1; 
      decDecimalPart="0"; 
    } 
    var stringOfZeros = new String('');
    i=0;
    if( decDecimalPart > 0 )
    {
      while( i < intZeroCount)
      {
        stringOfZeros += '0';
        i += 1;
      }
    }
    decDecimalPart = String(intWholePart) + "." + stringOfZeros + String(decDecimalPart); 
    var dot = decDecimalPart.indexOf('.');
    if(dot == -1)
    {
      decDecimalPart += '.'; 
      dot = decDecimalPart.indexOf('.'); 
    } 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  else
  {
    var dot; 
    var decDecimalPart = new String(intWholePart); 
    decDecimalPart += '.'; 
    dot = decDecimalPart.indexOf('.'); 
    var l=parseInt(dot)+parseInt(decimals); 
    while(decDecimalPart.length <= l) 
    {
      decDecimalPart += '0'; 
    }
    strResult = decDecimalPart;
  }
  return strResult;
}

//function to change site
function changeSite(newSite) {
	var ajaxVar = new ajaxVars();
	ajaxVar.vars['action'] = "runFunction";
	ajaxVar.vars['func'] = "checkSess";
	ajaxVar.vars['nosplit'] = 1;
	ajaxVar.vars['newSite'] = newSite;
	ajaxVar.vars['id'] = 1;
	ajaxVar.gotoFunction = 'redirectSite';
	ajaxVar.AjaxPostSQL();	
}

function redirectSite(dataArr, fnVars) {
	if (dataArr==-1) {
		return false;
	}else{
		var tmp = dataArr.split('++++');
		if (tmp[2]==1) {
 			document.location.href = 'https://' + tmp[0] + 'index/index.php?cVal=' + tmp[1];
		}else{
			
			switch (tmp[3]) {
				case "mfc_sg":
					document.location.href = 'http://' + tmp[0] + 'searchandguidance/cVal=' + tmp[1];
				break;
				case "mfc_hl":
					document.location.href = 'http://' + tmp[0] + 'helpline/cVal=' + tmp[1];
				break;
				case "mfc_tr":
					document.location.href = 'http://' + tmp[0] + 'training/cVal=' + tmp[1];
				break;
				case "family":
					document.location.href = 'http://' + tmp[0] + 'index/index.php?cVal=' + tmp[1];	
				break;
				case "ecc":
				case "ehc":
				case "hol":
					document.location.href = 'http://' + tmp[0] + 'index/index.php?cVal=' + tmp[1];
				break;
			}
			
			
		}
// 		document.getElementById('sss').value = dataArr
	}
}

////////////////
//function to change site
function changeSiteFront(newSite) {
	var ajaxVar = new ajaxVars();
	ajaxVar.vars['action'] = "runFunction";
	ajaxVar.vars['func'] = "checkSess";
	ajaxVar.vars['nosplit'] = 1;
	ajaxVar.vars['newSite'] = newSite;
	ajaxVar.vars['id'] = 1;
	ajaxVar.gotoFunction = 'redirectSiteFront';
	ajaxVar.AjaxPostSQL();	
}

function redirectSiteFront(dataArr, fnVars) {
	if (dataArr==-1) {
		return false;
	}else{
		var tmp = dataArr.split('++++');
		if (tmp[2]==1) {
 			parent.document.location.href = 'https://' + tmp[0] + 'index/index.php?cVal=' + tmp[1];
		}else{
			
			switch (tmp[3]) {
				case "ecc":
				case "ehc":
				case "hol":
					parent.document.location.href = 'http://' + tmp[0] + 'index/index.php?cVal=' + tmp[1];
				break;
			}
			
			
		}
// 		document.getElementById('sss').value = dataArr
	}
}
////////////////

function findPosNewX(obj) {
	var curleft = 0;
	if(obj) {
	if (obj.offsetParent) 	{
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
	}
}

function findPosNewY(obj) {
	var curtop = 0;
	if(obj) {
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curtop += obj.x;
	}
	return curtop;
	}
}


function showAlt(obj, altDiv, show, div_id) {
	var altObj = document.getElementById(altDiv);
	if (show==1) {
		altObj.style.visibility = 'visible';
		altObj.style.display = 'block';
		altObj.style.left = parseInt(findPosNewX(obj)) + parseInt(obj.width) + 'px';
		altObj.style.top = parseInt(findPosNewY(obj)) + 'px';
		
		document.getElementById('mfc_alt_div').innerHTML = document.getElementById(div_id).innerHTML;
	}else{
		altObj.style.visibility = 'hidden';
		altObj.style.display = 'none';
	}
}

function updBlackLink() {
	var imgObjs = document.getElementsByTagName("img");
	var xI = imgObjs.length;
	for (var xJ=0; xJ<xI; xJ++) {
		if (imgObjs[xJ].src.indexOf('Q-1.jpg')>0) {
			var tmpObj = imgObjs[xJ].parentNode;
			for (var xTmp=0; xTmp<6; xTmp++) {
				if (tmpObj.tagName=='TR') {
					break;
				}
				tmpObj = tmpObj.parentNode;
			}
			if (tmpObj.tagName=='TR') {
				for (var xY=0; xY<4; xY++) {
					if (tmpObj.childNodes[xY]) {
						var hrefObjs = tmpObj.childNodes[xY].getElementsByTagName("a");
						if (hrefObjs.length>0) {
							for (var xQ=0; xQ<hrefObjs.length; xQ++) {
								hrefObjs[xQ].style.color = "#101010";
							}
						}
					}
				}
			}
			break;
		}
	}
}

function setSelectedCountyVal(selval, drop_name){
			
	if(drop_name == "listSearchName"){
		var hidObj = document.getElementById('searchCounty');	
	}else if(drop_name == "listCountyName"){
		var hidObj = document.getElementById('searchCountyName');	
	}else if(drop_name == "listMilesName"){
		var hidObj = document.getElementById('searchMilesName');	
	}
	
	if(hidObj){
		hidObj.value = selval;
	}	
}
