function msg(n_msg,x){
var msg="The following fields were found to be blank or incorrect.\nKindly check and correct it before submiting the form \n"
msg=msg+"------------------------------------------------------------------\n\n"
msg=msg+n_msg
if(x==1){alert(msg); return false;}
}

// pop up - virtual tour
function popwin(x, y)
{window.open(x, y,'status=no,toolbar=0,scrollbars=1,resizable=1,menubar=0,width=500,height=500,left=150,top=50');}
// ends


//Verify TEXTAREA field - general
function VerifyMsg(f_ld,c_nt,cnt_fld) {

	var len = f_ld.value.length
	var cl

	if ((len == 1) && (f_ld.value.substring(0, 1) == " ")) {
		f_ld.value = ""
		len = 0
	}
	if (len > (c_nt-10)) {
		f_ld.value = f_ld.value.substring(0, c_nt)
		cl = 0
	}
	else {
		cl = c_nt - len
	}
	eval(cnt_fld).value = cl
}

//for email addresses
var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

//illegal characters in fields
var illegalCharStr = '~!@#$%^*()<>{}[]=?/\\\":;';

var illegalCharStrWeb = '~!@#$%^*()<>{}[]=?";';
 	
// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//check for illegal characters
function checkIlleg(va)
{
	var stripped = stripCharsInBag (va, illegalCharStr);
	if(va != '' && stripped.length < va.length)
	{
		return false;
	}
	return true;
}

//check illegal characters for url
function checkIllegweb(va)
{
	var stripped = stripCharsInBag (va, illegalCharStrWeb);
	if(va != '' && stripped.length < va.length)
	{
		return false;
	}
	return true;
}

// Validate search form
function Val_Search(){
	var x=0;
	var err_msg=""

if ( parseInt(document.Prpty_Srch.price_to[document.Prpty_Srch.price_to.selectedIndex].value) &&  parseInt(document.Prpty_Srch.price_frm[document.Prpty_Srch.price_frm.selectedIndex].value) )
{	
if ( parseInt(document.Prpty_Srch.price_to[document.Prpty_Srch.price_to.selectedIndex].value) < parseInt(document.Prpty_Srch.price_frm[document.Prpty_Srch.price_frm.selectedIndex].value) )
		{
		err_msg=err_msg+"Invalid Price Range! - Please try a valid option\n"; x=1;			
		}
	return msg(err_msg,x);	
}		
	}			


// Validate email updates form
function Val_eml(){
//alert("5")
	var x=0;
	var err_msg=""		
if(document.BRE_Form.email.value=="")
        {
     err_msg=err_msg+"Email Address\n"; x=1;	
        }
			else {
					email = document.BRE_Form.email.value;
					if(email.search(regexp) == -1){
		  			  err_msg=err_msg+"Email Address - Invalid Characters\n"; x=1;		
						}
				}				
	return msg(err_msg,x);		
	}		
	
// Contact Us Validation
function ConValidate()
{
var x=0;
var err_msg=""		
if(document.Contact.Comments.value=="")
        {
        err_msg=err_msg+"Enquiry\n"; x=1;
        }
if(document.Contact.Name.value=="")
        {
        err_msg=err_msg+"Name\n"; x=1;
        }
if (!document.Contact.Country[document.Contact.Country.selectedIndex].value)
		{
		err_msg=err_msg+"Country\n"; x=1;		
		}					 					 				
if((document.Contact.ConCC.value) || (document.Contact.ConAC.value) || (document.Contact.ConNo.value)){
		
		if((document.Contact.ConCC.value=="") || (document.Contact.ConAC.value=="") || (document.Contact.ConNo.value==""))
		{
		err_msg=err_msg+"Contact Details - Complete Tel/Mob Numbers\n"; x=1;
		}
		if(isNaN(document.Contact.ConCC.value)){
	 	 err_msg=err_msg+"Country Code - Invalid Characters\n"; x=1;
		}
		if(isNaN(document.Contact.ConAC.value)){
	 	 err_msg=err_msg+"Area Code - Invalid Characters\n"; x=1;
		}
		if(isNaN(document.Contact.ConNo.value)){
	 	 err_msg=err_msg+"Contact Number - Invalid Characters\n"; x=1;		 
		}						
        }
		
if(document.Contact.email.value=="")
        {
                err_msg=err_msg+"Email\n"; x=1;		 
        }							
else {
		email = document.Contact.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}						
return msg(err_msg,x);	
}	

// Program Select verification
//---------------------------	
	function calcHrs() {
	//alert("5")
		//tothrs  = document.BRE_Form.hrs.value;
		tothrs  = 3;
		var hrs = 0;
		if (document.BRE_Form.cmpr_id.length>0){
			for (i=0;i<document.BRE_Form.cmpr_id.length;i++){
				if (document.BRE_Form.cmpr_id[i].checked){
					hrs = hrs + 1;
					if (hrs > tothrs) {
						alert("Your selection ("+hrs+") exceeded more than the total hours ("+tothrs+") subscribed for.");
						document.BRE_Form.cmpr_id[i].checked =false;
						}
					}
				}
			}
		}
//---------------------------

var freeItemCount=0 
var maxProperties=3 
function setItems(item)
{ 
  if(item.checked)
  {freeItemCount=freeItemCount+1}

else
 {freeItemCount=freeItemCount-1} 

if (freeItemCount>maxProperties)
  {item.checked=false 
  freeItemCount=freeItemCount-1 
  alert('You can choose only maximum '+maxProperties+' properties to compare.') 
  } 
  
} 

// Enquiry Validation
function Enq_Validate()
{
var x=0;
var err_msg=""		
if(document.Contact.Prpty_ID.value=="")
        {
        err_msg=err_msg+"Property ID\n"; x=1;
        }
if(document.Contact.Prpty_Name.value=="")
        {
        err_msg=err_msg+"Property Name\n"; x=1;
        }
if(document.Contact.Name.value=="")
        {
        err_msg=err_msg+"Name\n"; x=1;
        }		
if (!document.Contact.Country[document.Contact.Country.selectedIndex].value)
		{
		err_msg=err_msg+"Country\n"; x=1;		
		}					 					 				
if((document.Contact.ConCC.value) || (document.Contact.ConAC.value) || (document.Contact.ConNo.value)){
		
		if((document.Contact.ConCC.value=="") || (document.Contact.ConAC.value=="") || (document.Contact.ConNo.value==""))
		{
		err_msg=err_msg+"Contact Details - Complete Tel/Mob Numbers\n"; x=1;
		}
		if(isNaN(document.Contact.ConCC.value)){
	 	 err_msg=err_msg+"Country Code - Invalid Characters\n"; x=1;
		}
		if(isNaN(document.Contact.ConAC.value)){
	 	 err_msg=err_msg+"Area Code - Invalid Characters\n"; x=1;
		}
		if(isNaN(document.Contact.ConNo.value)){
	 	 err_msg=err_msg+"Contact Number - Invalid Characters\n"; x=1;		 
		}						
        }		
if(document.Contact.email.value=="")
        {
                err_msg=err_msg+"Email\n"; x=1;		 
        }							
else {
		email = document.Contact.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}						
return msg(err_msg,x);	
}	



// Landlord Registration Validation
function Dvlpr_Validate()
{
var x=0;
var err_msg=""		
if(document.Contact.Prpty_Name.value=="")
        {
        err_msg=err_msg+"Name\n"; x=1;
        }
if(document.Contact.email.value=="")
        {
                err_msg=err_msg+"Email\n"; x=1;		 
        }							
else {
		email = document.Contact.email.value;
		if(email.search(regexp) == -1){
		   	err_msg=err_msg+"Email - Invalid Characters\n"; x=1;
			}
		}
if(document.Contact.Price.value=="")
        {
                err_msg=err_msg+"Price Sought\n"; x=1;		 
        }										
return msg(err_msg,x);	
}


