/*
Conference javascript page.
PKAY, SCS 07/11/2008
Copyright 2008 John Wiley and Sons Ltd
*/

function ShowHideBillingDetails(){
	//Display Billing Details
	//Effect.BlindDown('BillingDetails');
	//Effect.BlindDown('BillingDetails', { duration:60.0 });
	if (document.getElementById("show_hide_door").value!='none'){			
		//document.getElementById("BillingDetails").style.display = 'block';
		Effect.BlindDown("BillingDetails",{ duration: 2.0 });
		document.getElementById("show_hide_door").value ='none';
	}else{
		//document.getElementById("BillingDetails").style.display = 'none';
		//$('BillingDetails').hide(); 
		Effect.BlindUp("BillingDetails",{ duration: 2.0 });
		document.getElementById("show_hide_door").value ='block';
	}
}


//*************************************************
// This function validate IsNumeric for CurrentID
// 
//*************************************************
function CheckNumeric(CurrentID)
{ 
	var curField = document.getElementById(CurrentID);
	if(isNAN(document.getElementById(CurrentID).value )==false){
		alert("Price must be numeric");
	document.getElementById(CurrentID).focus();
	}
}

//*************************************************
// This function is display "price", if default Null value
// 
//*************************************************
function showprice(CurrentID)
{
	//This function set default value = "price"
	var myTextField = document.getElementById(CurrentID);
	if(myTextField.value != ""){
		//alert("You entered: " + myTextField.value)
	}else{
		document.getElementById(CurrentID).value='price';
	}
}

//*************************************************
// This function is changing Currency Format
// 
//*************************************************
function CurrencyFormatted(amount,CurrentID)
{
	var myPrice = amount;
	var myNewPrice = myPrice.replace(/£/, "");
	if (IsNumeric(myNewPrice)==false){
		s = 'price'
		document.getElementById(CurrentID).value = 'price';
	}else{
		var i = parseFloat(myNewPrice);
		if(isNaN(i)) { i = 'price'; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if(s.indexOf('.') < 0) { s += '.00'; }
		if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		//alert(s)
		document.getElementById(CurrentID).value = s;
		return s;
	}
}


//*************************************************
// This function is check for valid numeric strings
// 
//*************************************************
function IsNumeric(strString)
{
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
}

//*************************************************
// This function is validate Email Address
// 
//*************************************************

function validateEmail(strEmail) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(strEmail);
}

//*************************************************
// This function is using in Yourdetails.asp page
// Form fields validation 
//*************************************************
function yourdetailsvalidateForm() {
		var errortext = "";
		var strfirstname;
		var strAddress;
		var strCity;
		var strCounty;
		var strPostcode;
		var strEmail;
	//Title validation 
	if(document.getElementById('title').value=="Please select") {
		errortext += "<li>Please select a Title</li>";
	}
	
	//FirstName validation 
	if(document.ContactDetailForm.firstname.value=="") {
		errortext += "<li>First Name missing</li>";
	}else{
		strfirstname=document.ContactDetailForm.firstname.value
		if (strfirstname.length>0){
			if ((strfirstname.length<2) || (strfirstname.length>160)){

				errortext += "<li>Please enter valid First Name</li>";
			}
		}
	}
	//SurName validation 	
	if(document.ContactDetailForm.surname.value=="") {
		errortext += "<li>Surname missing</li>";
	}	
	//Address validation 			
	if(document.ContactDetailForm.address.value=="") {
		errortext += "<li>Address missing</li>";
	}else{
		strAddress=document.ContactDetailForm.address.value
		if (strAddress.length>0) {
			if ((strAddress.length<4) || (strAddress.length>255)){
				errortext += "<li>Please enter valid Address</li>";
			}
		}
	}
	//City validation 		
	if(document.ContactDetailForm.city.value=="") {
		errortext += "<li>City missing</li>";
	}else{
		strCity=document.ContactDetailForm.city.value
		if (strCity.length>0) {
			if ((strCity.length<2) || (strCity.length>160)){
				errortext += "<li>Please enter valid City</li>";
			}
		}
	}

	//## County validation removed by K Thomas - 2nd Feb 09 - clients request
	//County validation 		
	//if(document.ContactDetailForm.county.value=="") {
	//	errortext += "<li>County missing</li>";
	//}else{
	//	strCounty=document.ContactDetailForm.county.value
	//	if (strCounty.length>0) {
	//		if ((strCounty.length<4) || (strCounty.length>160)){
	//			errortext += "<li>Please enter valid County</li>";
	//		}
	//	}
	//}
	
	
	//## Postcode validation removed by K Thomas - 2nd Feb 09 - clients request
	//Postcode validation 		
	//if(document.ContactDetailForm.postcode.value=="") {
	//	errortext += "<li>Postcode missing</li>";
	//}else{
	//	strPostcode=document.ContactDetailForm.postcode.value
	//	if (strPostcode.length>0) {
	//		if ((strPostcode.length<4) || (strPostcode.length>160)){
	//			errortext += "<li>Please enter valid Postcode</li>";
	//		}
	//	}
	//}
	
	//Country validation
	if(document.getElementById('country').value==-1) {
		errortext += "<li>Please select a Country</li>";
	}
	
	//Email validation
	if(document.ContactDetailForm.email.value=="") {
		errortext += "<li>Email Address missing</li>";
	}else{
		strEmail=document.ContactDetailForm.email.value
		if (((strEmail.Length<8)||(strEmail.length>160))||(validateEmail(strEmail) == false)){	
			errortext += "<li>Please enter valid Email</li>";
		}
	}
	
	if (errortext.length > 0) {
		errortext = "<ul class='warning'>" + errortext;
		errortext = errortext + "</ul>";
		document.getElementById("errormsg").innerHTML = errortext;
		document.location = "#errormsg";
		return false;
	} else {
		return true;
	}
}



//*************************************************
// This function is using in Membershipdetails.asp page
// Form fields validation 
//*************************************************
function membershipdetailsvalidateForm() {
	var errortext = "";
	for (i=0; i<document.membershipdetails.radmember.length; i++) {
         if (document.membershipdetails.radmember[i].checked==true){
			document.getElementById('strRad1').value='1';
		 }
	}
	for (i=0; i<document.membershipdetails.conference.length; i++) {
         if (document.membershipdetails.conference[i].checked==true){
			document.getElementById('strRad2').value='1';
         }
    }
	if(document.getElementById('strRad1').value!=1){
		errortext += "<li>Please select a Membership</li>";
	}
	if(document.getElementById('strRad2').value!=1){
		errortext += "<li>Please select a Conference</li>";
	} 
	if (errortext.length > 0) {
			errortext = "<ul class='warning'>" + errortext;
			errortext = errortext + "</ul>";
			document.getElementById("errormsg").innerHTML = errortext;
			document.location = "#errormsg";
			return false;
		} else {
			return true;
	}
}


//*************************************************
// This function is using in Confirmdetails.asp page
// Form fields validation 
//*************************************************
function validateFormConDetails() {
	var errortext = "";
	for (i=0; i<document.confirmdetails.paymode.length; i++) {
		if (document.confirmdetails.paymode[i].checked==true){
			document.getElementById('strRad1').value=1;			
		}
	}
	if(document.getElementById('strRad1').value!=1) {
		errortext += "<li>Please choose Payment Method</li>";
	}
	if (errortext.length > 0) {
		errortext = "<ul class='warning'>" + errortext;
		errortext = errortext + "</ul>";
		document.getElementById("errormsg").innerHTML = errortext;
		document.location = "#errormsg";
		return false;
	} else {
		return true;
	}
}



