// JavaScript Document
//////////////////////////////////////////////START FUNCTIONS DONE By Ajay Shukla /////////////////////////////////////////////                      //////////////////////////////////////////////////////////////////////////////

//////////////////
 /*
* Constructor for the Comparison cart
* @author Ajay Shukla 
* @return false
*/ 
/////////////////	
var newwindow;
function poptastic(url)
{
	w=800
	h=500
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;
	newwindow=window.open(url,'name', 'width='+w+', height='+h+', scrollbars=yes,resizable=no,top='+TopPosition+',left='+    LeftPosition+'');
	if (window.focus) {newwindow.focus()}
	
}

//////////////////
 /*
* Constructor for the Comparison cart
* @author Ajay Shukla 
* @return false
*/ 
/////////////////	
var newwindow;
function newpoptastic(url)
{
	w=500
	h=300
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;
	newwindow=window.open(url,'name', 'width='+w+', height='+h+', scrollbars=yes,resizable=no,top='+TopPosition+',left='+    LeftPosition+'');
	if (window.focus) {newwindow.focus()}
	
}
var newwindow;
function samlepagepopup(url)
{
	w=620
	h=400
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;
	newwindow=window.open(url,'name', 'width='+w+', height='+h+', scrollbars=yes,resizable=no,top='+TopPosition+',left='+    LeftPosition+'');
	if (window.focus) {newwindow.focus()}
	
}
//////////////////
 /*
* Constructor for the Search validation 
* @author Ajay Shukla 
* @return false
*/ 
/////////////////
function chkNew_Validation()
{
	/* var x = document.getElementById("data[Search][citystate]"); -- Generating prob. in Firefox */
     if(document.getElementById("SearchCitycountry"))
	    {
		  var x        = document.getElementById("SearchCitycountry");
	    }
	    else
	    {
	      var x         = document.getElementById("SearchCitystate");
	    }
	
	var minPrice = document.getElementById("SearchMinprice");
	var maxPrice = document.getElementById("SearchMaxprice");
	var lisType  = document.getElementById("SearchListingType");
	
	 
	var y        = document.getElementById("SearchZip");
	var minArea  = document.getElementById('SearchMinarea');
	
	
	
	if (lisType.options[0].selected)
	{
		lisType.focus();
		return false;
	}
      if((Trim(x.value) == '') && (Trim(y.value) == ''))
		{
			alert("Required Field : City, State/Country  or Zip Code.");
			x.focus();
			return false;
		}
    if((x.value != '') || (y.value != '') || (minPrice.value != "") || (maxPrice.value != "") || (minArea.value != "") )
	 {
		 var getcity  = specialCharactersValidation(x);
		 var getzip   = specialCharactersValidation(y);
	 	 var getMinPrice = IsNumeric(Trim(minPrice.value));
		 var getMaxPrice = IsNumeric(Trim(maxPrice.value));
		 var getMinArea = IsNumeric(Trim(minArea.value));
		 var minP = parseInt(Trim(minPrice.value));
	     var maxP = parseInt(Trim(maxPrice.value));
		if( getcity == false)
		   { 
			        alert ("Special Characters are not allowed.\n Please remove them and try again.");
					return false;
		   }
		if( getzip == false)
		   { 
					alert ("Special Characters are not allowed.\n Please remove them and try again.");
					return false;
		   }
		  // alert(getcity + "=" + getzip);
	    if( getMinPrice == false)
		{
			alert ("Minimum Price must be numeric!");
			minPrice.focus();
	        return false;
		}
	    if( getMaxPrice == false)
		 {
			alert ("Maximum Price must be numeric!");
			maxPrice.focus();
		    return false;
		 }
  	    if( minP > maxP || maxP < minP)
	     {
		    alert ("Maximum Price should be either greater than \n or equal  Minimum Price!");
		    maxPrice.focus();
		    return false;
	     }
		if(getMinArea == false) 
		 {
			alert ("Area must be numeric!");
			minArea.focus();
		    return false;
		 }
	 // alert( minPrice.value + "=" + maxPrice.value );
	 }
	
 	return true;
}
	/**
	* @author - Ajay Shukla (18th June 2007)
	* @name - chkValidation()
	* @desc - Function is responsible for the validation of req. fields for the 'Search Box'.
	* @return - Boolean value (true/false)
	*/ 
function chkValidation()
	{

	//alert("yes");
	    if(document.getElementById("SearchCitycountry"))
	    {
		  var x        = document.getElementById("SearchCitycountry");
	    }
	    else
	    {
	      var x         = document.getElementById("SearchCitystate");
	    }
	    var minPrice   = document.getElementById("SearchMinprice");
	    var maxPrice   = document.getElementById("SearchMaxprice");
		
		var Id          = document.getElementById("SearchId");
		var MlsId       = document.getElementById('SearchMlsId');
		
		var y          = document.getElementById("SearchZip");
		var minArea    = document.getElementById('SearchMinarea');
		
		//var minReward  = document.getElementById('SearchIncentive');
			if(Id == null &&  MlsId == null)
			{
			 if((Trim(x.value) == '') && (Trim(y.value) == ''))
		        {
				alert("Required Field : City, State/Country  or Zip Code.");
				x.focus();
				return false;
				}

			}
			else
			{
				if((Trim(x.value) == '') && (Trim(y.value) == '') && (Trim(Id.value) == '') && (Trim(MlsId.value) == ''))
		        {
				alert("Required Field : City, State/Country  or Zip Code or Mwendo Listing ID or MLS ID.");
				x.focus();
				return false;
				}
			}
    if((x.value != '') || (y.value != '') || (minPrice.value != "") || (maxPrice.value != "") || (minArea.value != ""))
	 {
		 var getcity  = specialCharactersValidation(x);
		 var getzip   = specialCharactersValidation(y);
	 	 var getMinPrice = IsNumeric(Trim(minPrice.value));
		 var getMaxPrice = IsNumeric(Trim(maxPrice.value)); 
		 var getMinArea = IsNumeric(Trim(minArea.value));
		 var minP = parseInt(Trim(minPrice.value));
	     var maxP = parseInt(Trim(maxPrice.value));
		if( getcity == false)
		   { 
			        alert ("Special Characters are not allowed.\n Please remove them and try again.");
					return false;
		   }
		if( getzip == false)
		   { 
					alert ("Special Characters are not allowed.\n Please remove them and try again.");
					return false;
		   }
		  // alert(getcity + "=" + getzip);
	    if( getMinPrice == false)
		{
			alert ("Minimum Price must be numeric!");
			minPrice.focus();
	        return false;
		}
	    if( getMaxPrice == false)
		 {
			alert ("Maximum Price must be numeric!");
			maxPrice.focus();
		    return false;
		 }
  	    if( minP > maxP || maxP < minP)
	     {
		    alert ("Maximum Price should be either greater than \n or equal  Minimum Price!");
		    maxPrice.focus();
		    return false;
	     }
		if(getMinArea == false) 
		 {
			alert ("Area must be numeric!");
			minArea.focus();
		    return false;
		 }
	 // alert( minPrice.value + "=" + maxPrice.value );
	 }
	//return true;
	
	
	getHTML();
	
	
	
}
//////////////////
 /*
* Constructor for the Save Search validation 
* @author Ajay Shukla 
* @return false
*/ 
/////////////////
function chkUSSaveValidation()
{
	/* var x = document.getElementById("data[Search][citystate]"); -- Generating prob. in Firefox */
	var uSSave = document.frm_USSave.SaveSearchSearchName;
	if((uSSave.value== '') || (uSSave.value== null))
	{
		//alert("Required Field : City, State (or province) or Zip Code.");
		uSSave.focus();
		return false;
	}   
	return true;
}
//////////////////
 /*
* Constructor for the Save Search validation 
* @author Ajay Shukla 
* @return false
*/ 
/////////////////
function chkLSSaveValidation()
{
	/* var x = document.getElementById("data[Search][citystate]"); -- Generating prob. in Firefox */	
	var lSSave = document.frm_LSSave.SaveSearchSearchName;
	
    if((lSSave.value== '') || (lSSave.value == null))
	{
		//alert("Required Field : City, State (or province) or Zip Code.");
		lSSave.focus();
		return false;
	}
	return true;
}
//////////////////
 /*
* Constructor for the reset Save criteria box 
* @author Ajay Shukla 
* @return false
*/ 
/////////////////
function set()
{   
    var lisType      = document.getElementById("SearchListingType");
    var searchCtySte = document.getElementById("SearchCitystate");
    var searchZip    = document.getElementById("SearchZip");
    var bedrooms     = document.getElementById("SearchBedrooms");
    var bathrooms    = document.getElementById("SearchBathrooms");
    var minprice     = document.getElementById("SearchMinprice");
    var maxprice     = document.getElementById("SearchMaxprice");
	var minarea      = document.getElementById("SearchMinarea");
	var phOnly       = document.getElementById("ckphoto");
	var incOnly      = document.getElementById("ckincentive");
	
	  // set control
	    lisType.options[0].selected   = true;
		searchCtySte.value            = '';
		searchZip.value               = '';
		bedrooms.options[0].selected  = true;
		bathrooms.options[0].selected = true;
		minprice.options[0].selected  = true;
		maxprice.options[0].selected  = true;
		minarea.value                 = '';			  
	    phOnly.checked                = false;
	    incOnly.checked               = false;
   
	return false;	
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
/**
	* @author - Ajay  Shukla (02 Aug 2007)
	* @name - IsNumeric(strString)
	* @desc - Function is responsible for the validation of numeric value.
	* @return - Boolean value (true/false)
	*/ 
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   //var strValidChars = "0123456789.-";
   var strValidChars = "0123456789"
   var strChar;
   var blnResult = true;
   //  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;
   }
  
   //////////////////////////////////////////////////////////////////////////////////
/**
	* @author - Ajay  Shukla (02 Aug 2007)
	* @name - IsNumeric(strString)
	* @desc - Function is responsible for the validation of special characters.
	* @return - Boolean value (true/false)
	*/ 
function specialCharactersValidation(strString)
 {
 // var iChars = "!@#$%^&*()+=-[]\\\';/{}|\":<>?";
  var iChars = "!@#$^&*()+=[]\\\';/{}|\":<>?";
  var blnResult = true;
  for (var i = 0; i < strString.value.length; i++)
   {
  	if (iChars.indexOf(strString.value.charAt(i)) != -1)
	{
  	 blnResult = false;
  	}
  }
   return blnResult;
 }

 //////////////////////////////////////////////////////////////////////////////////
/**
	* @author - Ajay  Shukla (02 Aug 2007)
	* @name - Trim(strString)
	* @desc - Function is responsible remove space from string
	* @return - Boolean value (true/false)
	*/
function Trim(s) 
   {
   	// Remove leading spaces and carriage returns
   	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   	 { s = s.substring(1,s.length); }
     
   	// Remove trailing spaces and carriage returns
 while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   	 { s = s.substring(0,s.length-1); }
     
   	return s;
   }
   /************
   *******For Load Image********
   ****************/
   function loadImage() { 
  document.getElementById('load_image_upper').innerHTML = '<img src=/mwendo2/img/progress.gif> Loading..';
  document.getElementById('load_image_lower').innerHTML = '<img src=/mwendo2/img/progress.gif> Loading..';
 
}
   
                    ///////////////////////////////////////////////////////////////////////////
   //////////////////////////////////////////////////////////END Work`s  AJAY /////////////////////////////////////////////