var quoteChar = "'";
var globTe = null;
	function calWin(inTargetDateElement,allowClear)
	{
	var te="../includes/calendar.asp?date=" + document.getElementById(inTargetDateElement).value + "&clearDate=" + allowClear;
	globTe = document.getElementById(inTargetDateElement);
	window.open(te,'calWin','width=300,height=420,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=10,left=10'); 
	}
	
	function stt(inval){
	globTe.value=inval;
	}

	function SetAnyOption(inElem){
	 if (inElem[0].selected){
		for(x=1;x<inElem.length;x++) inElem[x].selected = false;
	 }
  	}
	
	function openPrintWin(){
  	myWin= open("printPage.asp","printWin","width=750,height=545,status=no,toolbar=yes,menubar=yes,resizable=yes,scrollbars=auto,top=10,left=10");
	}
	
	function imViewer(inUrlAddr){
  	myWin= open(inUrlAddr, "imViewer", "width=750,height=545,status=no,toolbar=yes,menubar=yes,resizable=yes,scrollbars=auto,top=10,left=10");
	}
	
	function getPrintStr(){
  /* try{
	return document.getElementById("mainContent").innerHTML;
  }
  catch(e){}
  return ""; */
  return document.getElementById("mainContent").innerHTML;
   }

	function openContent(inLocation){
  	myWin2= open(inLocation, "contentWin", "width=750,height=545,status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=yes,top=10,left=10");
}

 function checkRegDets(form){
 	if ((form.confpassword.value == "") != (form.password.value == "")) { alert("password does not match the password confirmation"); form.password.focus(); form.password.select(); return false;}
 	if (form.password.value == "") { alert("password cannot be empty"); form.password.focus(); form.password.select(); return false;}
	if (form.firstname.value == "") { alert("first name cannot be empty"); form.firstname.focus(); form.firstname.select(); return false;}
	if (form.surname.value == "") { alert("surname cannot be empty"); form.surname.focus(); form.surname.select(); return false;}
	if (form.phone.value == "") { alert("telephone number must be provided"); form.phone.focus(); form.phone.select(); return false;}
	if (form.address1.value == "") { alert("address line 1 cannot be empty"); form.address1.focus(); form.address1.select(); return false;}
	if (form.email.value == "") { alert("email address cannot be empty"); form.email.focus(); form.email.select(); return false;}
	if (form.town.value == "") { alert("town cannot be empty"); form.town.focus(); form.town.select(); return false;}
	if (form.county.value == "") { alert("county cannot be empty"); form.county.focus(); form.county.select(); return false;}
	if (form.postCode.value == "") { alert("postcode cannot be empty"); form.postCode.focus(); form.postCode.select(); return false;}
	return true;
 }
 
 function checkSubscriptionDets(form){
 
 var chosenAmount, chosenType, exactType
 
 	try{
		for (var i=0; i < form.amount.length; i++)
		   {
		   		if (form.amount[i].checked) chosenAmount = form.amount[i].value;
		   }
		for (var i=0; i < form.M_membershipType.length; i++)
		   {
		   		if (form.M_membershipType[i].checked) chosenType = form.M_membershipType[i].value;
		   }
	form.normalAmount.value = chosenAmount;
	if ((chosenAmount == "500.00") || (chosenAmount == "250.00")) form.futurePayType.value="";
	else form.futurePayType.value="regular";
	}
	catch(e) {alert("Error please inform system Administrator"); return false;}
	if ((chosenType < 2) && ((chosenAmount == "10.00") || (chosenAmount == "15.00") || (chosenAmount == "13.00") || (chosenAmount == "16.00"))){
	 if (chosenType == 0) exactType = "Other";
	 else exactType = "Lay";
	 alert("Concessions apply to pensioners, students, unwaged and religious but you have\nstated that you are " + exactType + ". Please correct before continuing");
	 return false;	
	}
	
	if ((chosenType >= 2) && ((chosenAmount == "25.00") || (chosenAmount == "40.00") || (chosenAmount == "30.00") || (chosenAmount == "35.00"))){
		if (chosenAmount == "25.00") exactType = "10.00";
		if (chosenAmount == "40.00") exactType = "15.00";
		if (chosenAmount == "30.00") exactType = "13.00";
		if (chosenAmount == "35.00") exactType = "16.00";
		alert("You are eligible for concessions. You should probably choose the £" + exactType + " option.\nPlease correct before continuing");
	 	return false;
	}
	
	return true;
 }
 
function checkDonationDets(form){
 
 var chosenAmount
 
 	try{
		for (var i=0; i < form.preAmount.length; i++)
		   {
		   		if (form.preAmount[i].checked) chosenAmount = form.preAmount[i].value;
		   }
		form.amount.value = chosenAmount;
		form.M_amount.value = chosenAmount;
		if (chosenAmount == "other"){
			if(isNumVal(form.otherAmount.value)){
				form.amount.value = fmtDecimal(form.otherAmount.value,2);
				form.M_amount.value = fmtDecimal(form.otherAmount.value,2);
				if(fmtDecimal(form.amount.value,2) < 1.0) {alert("minimum donation is £1.00"); return false;}
			}
			else{
			alert("You have chose to donate a specified amount but the amount is not a number\nnote that the currency notation is GB for example £1,250.00");
			form.otherAmount.focus();
			form.otherAmount.select();
			return false;
			}
		}
	}
	catch(e) {alert("Error please inform system Administrator"); return false;}
	
	return confirm("You are about to donate £" + form.amount.value + " continue?");
 } 
 
 function enterCommaDelimter(inVal){
 // assumes the decimal has been put into place careful
 
 var x, retVal, tempStr;
 
 tempStr = "";
 
	 if (inVal.length > 6) {
	 	for (x=inVal.length;x>=0; x--){
		  if (x==0) tempStr = "," + tempStr;
		  tempStr = inVal.charAt(x) + tempStr;
		}
	 
	 	return tempStr;
	 }
 return inVal;
 }
 
 function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}
 
 function checkLoginDets(form){
 	if (form.email.value == "") { alert("email address cannot be empty"); form.email.focus(); form.email.select(); return false;}
	if (form.password.value == "") { alert("password cannot be empty"); form.password.focus(); form.password.select(); return false;}
	
	return true;
 }
 
 function fmtDecimal(inVal,d){
 var dpls=d;
 var lt1=false;
 var i;
 var res;
 
 if ((inVal.toString().charAt(0)=='N') || (inVal.toString().charAt(0)=='I')){
 	this.x = 0
  }
 else {
 	this.x = inVal.replace(",","")
 }
 
 var len=inVal.toString().length;

 var absx=Math.abs(this.x);		// only works with absolute values

 if ((absx < 1) && (absx > 0)){
  lt1 = true;
  absx+=10;
 }
 var pt_pos = absx.toString().indexOf(".");
	 if (pt_pos == -1){		//No decimal value just add the number of zeros
	  
	   res = "" + absx + ".";
		  for (i=0;i<dpls;i++){
		   res += 0;
		  } 

	 }
	 else{
	  res = Math.round(absx * Math.pow(10,dpls));
	  res=res.toString();
		  if (res.length == 
		      Math.round(Math.floor(absx * Math.pow(10,dpls))).toString().length){ 
		   res = res.substring(0,pt_pos) + "." + 
		         res.substring(pt_pos,res.length);
		  }
		  else{
		   pt_pos++;
		   res = res.substring(0,pt_pos) + "." + 
		          res.substring(pt_pos,res.length);
		  } 

	  if (lt1){
	   res=res.substring(1,res.length);
	  }
	 }
	  if (dpls == 0){
	  	res = res.substring(0,((res.length)-1));
	  }

 if (this.x < 0)res = "-"+res;
 return res;
}
