function OrderValidate()
{
//used in order.php
	var msg = "";
	if (document.forms[0].name.value == "")
		msg += "Name\n";
	if (document.forms[0].email.value == "")
		msg += "EMail\n";
	if (document.forms[0].email.value.length>1){
			if ( ! isEmail(document.forms[0].email.value) )
				msg += "Invalid Email address format \n" ;
		}
	if (document.forms[0].qty.value <= "0")
		msg += "Quantity\n";
	
	if (document.forms[0].accept.checked == false) 
		msg += "Please check the box to show you accept the terms and conditions";

	if ( msg != "" )
   {
		 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
		 return false;
	}

	document.forms[0].submit();
}
	
function ValidateContact()
{
//used in contact.php
	var msg = "";
	if (document.forms[0].subject.value == "")
		msg += "Subject\n";
	if (document.forms[0].emailaddress.value == "")
		msg += "EMail Address\n";
	if (document.forms[0].emailaddress.value.length>1){
			if ( ! isEmail(document.forms[0].emailaddress.value) )
				msg += "Invalid Email address format \n" ;
		}
	if ( msg != "" )
   {
		 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
		 return false;
	}

	document.forms[0].submit();
}
function ValidateContact2()
{
//used in contact.php
	var msg = "";
	if (document.forms[0].subject.value == "")
		msg += "Subject\n";
	if (document.forms[0].emailaddress.value == "")
		msg += "EMail Address\n";
	if (document.forms[0].emailaddress.value.length>1){
			if ( ! isEmail(document.forms[0].emailaddress.value) )
				msg += "Invalid Email address format \n" ;
		}
	if ( msg != "" )
   {
		 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
		 return false;
	}

	return true;
}

function periodremove( Property_ID, ID)
{
	location.replace( 'pricing.php?ID=' + Property_ID + "&d=" + ID)
}
function PeriodValidate()
	{
		var msg = "";
		if (document.forms[0].Price.value == "")
			msg += "Price\n";
		if ( msg != "" )
	   {
			 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
			 return false;
		}
		 document.forms[0].submit();
	}
function ImageValidate()
	{
		var msg = "";
		if ( msg != "" )
	   {
			 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
			 return false;
		}
		 document.forms[0].submit();
	}
function AccountValidate()
	{
		var msg = "";
		if (document.forms[0].Owner_Name.value == "")
			msg += "Name\n";
		if (document.forms[0].Owner_Address1.value == "")
			msg += "Address\n";
		if (document.forms[0].Owner_Country.value == "")
			msg += "Country\n";
		if (document.forms[0].Owner_Phone.value == "")
			msg += "Phone\n";
		if (document.forms[0].Owner_EMail.value == "")
			msg += "EMail\n";
		if (document.forms[0].Owner_EMail.value.length>1){
				if ( ! isEmail(document.forms[0].Owner_EMail.value) )
					msg += "Invalid Email address format \n" ;
			}
		if (document.forms[0].Owner_Password.value == "")
			msg += "Password\n";

		if ( msg != "" )
	   {
			 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
			 return false;
		}
		 document.forms[0].submit();
	}
	
function PropertyValidate()
	{
		var msg = "";
		if (document.forms[0].Property_Name.value == "")
			msg += "Property Name\n";
		if (document.forms[0].Property_Country.value == "")
			msg += "Country\n";
		if (document.forms[0].Property_Region.value == "")
			msg += "Region\n";
		if (document.forms[0].Property_Headline.value == "")
			msg += "Headline\n";
		if (document.forms[0].Property_Sleeps.value == "" || document.forms[0].Property_Sleeps.value == "0" )
			msg += "Sleeping Capacity\n";
		/*if (document.forms[0].Property_NoBedrooms.value == "" || document.forms[0].Property_NoBedrooms.value == "0" )
			msg += "Number of bedrooms\n";
		if (document.forms[0].Property_NoBathrooms.value == "" || document.forms[0].Property_NoBathrooms.value == "0" )
			msg += "Number of bathrooms\n";
		*/
		if (document.forms[0].Property_EMail.value == "" && document.forms[0].Property_ContactDetails.value == "" )
			msg += "EMail or Contact details\n";
		if (document.forms[0].Property_EMail.value.length>1){
				if ( ! isEmail(document.forms[0].Property_EMail.value) )
					msg += "Invalid Email address format \n" ;
			}

		if ( msg != "" )
	   {
			 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
			 return false;
		}
		document.forms[0].Property_Country.disabled=false;
			document.forms[0].Property_Region.disabled=false;
		 document.forms[0].submit();
	}
function AdminPropertyValidate()
	{
		var msg = "";
		if (document.forms[0].Property_Name.value == "")
			msg += "Property Name\n";
		if (document.forms[0].country.options) {
			if (document.forms[0].country.options[document.forms[0].country.selectedIndex].text=="")
				msg += "Country\n";
		} else {
			if (document.forms[0].country.value == "")
			msg += "Country\n";
		}
		if (document.forms[0].region.options) {
			if (document.forms[0].region.options[document.forms[0].region.selectedIndex].text=="")
				msg += "Region\n";
		} else {
			if (document.forms[0].region.value == "")
			msg += "Region\n";
		}
		if (document.forms[0].Property_Headline.value == "")
			msg += "Headline\n";
		if (document.forms[0].Property_Sleeps.value == "" || document.forms[0].Property_Sleeps.value == "0" )
			msg += "Sleeping Capacity\n";
		if (document.forms[0].Property_NoBedrooms.value == "" || document.forms[0].Property_NoBedrooms.value == "0" )
			msg += "Number of bedrooms\n";
		if (document.forms[0].Property_NoBathrooms.value == "" || document.forms[0].Property_NoBathrooms.value == "0" )
			msg += "Number of bathrooms\n";
		if (document.forms[0].Property_EMail.value == "" && document.forms[0].Property_ContactDetails.value == "" )
			msg += "EMail or Contact details\n";
		if (document.forms[0].Property_EMail.value.length>1){
				if ( ! isEmail(document.forms[0].Property_EMail.value) )
					msg += "Invalid Email address format \n" ;
			}

		if ( msg != "" )
	   {
			 alert( "The following required field(s) require an entry or are invalid\n\n" + msg + "\nPlease complete or correct & click submit" );
			 return false;
		}
		 document.forms[0].submit();
	}

function isEmail(strInput) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=strInput.match(emailPat);
	if (matchArray==null) {
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];
	// See if "user" is valid
	if (user.match(userPat)==null) return false;
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		// this is an IP address
		for (var i = 1; i <= 4; i++) {
			if (IPArray[i] > 255) return false;
		}
		return true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray==null) return false;
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)
		return false;
	if (len < 2) return false;
	return true;
}

function TextAreaLimiter(objField, intLength)
	{
	returnvalue=true;
	//if (eval("document.forms[0]." + objField.name + '.value.length') >= intLength)
	//	returnvalue=false;
	return returnvalue;
	}
	
function renewals() {
var chkbox = document.owner.renew;
var ids = "";
if (chkbox) {
	if (chkbox.length) {
	   var list=new Array();
	   for( x=0; x < chkbox.length; x++) {
	      if (chkbox[x].checked) {
	         list.length = list.length++;
	         list[list.length] = chkbox[x].value;
	      }
	   }
	   ids = list.toString();
	}
	if (chkbox.checked) 
	     ids = chkbox.value;
	if (ids != "") {
	   location.href="order.php?id=" + ids;
	  }
 }
} // end function
/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/

var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(theform,thelimit){
var limit_text='<span id="'+theform.toString()+'">'+thelimit+'</span> characters remaining.'

if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

