

// JavaScript Document

	//function used to reset the combo boxes values for city and county
function resetBoxes(typID)
{
   document.getElementById(typID).value="";
}
function resetBannerBox()
{
	$("#pageNum").attr("value","");
	$("#pageGroup").attr("value","");
//	document.getElementById("propertySearchLocation").value="";
}
	function resetPageVars()
	{
		$("#pageNum").attr("value","");
		$("#pageGroup").attr("value","");
	}

	function enterkey_submit(evt)
	{
	  var evt = (evt) ? evt : event
	  var charCode = (evt.which) ? evt.which : evt.keyCode
	  if (charCode == 13)
	  {
		document.getElementById('srch2').submit();
	  }
	}

	function lateAddition()
	{
		resetPageVars();
		document.getElementById("viewUpdatedProperties").value='';
		document.getElementById("lateAdditions").value="yes";
		var auctionID=document.getElementById('auctionID').value;
		update_contents(auctionID);
	}

	function viewUpdatedProperties()
	{
		resetPageVars();
		document.getElementById("lateAdditions").value='';
		document.getElementById("viewUpdatedProperties").value="yes";
		var auctionID=document.getElementById('auctionID').value;
		update_contents(auctionID);
	}

	function mouseX(evt)
	{
		if (evt.pageX) return evt.pageX;
		else if (evt.clientX)
		   return evt.clientX + (document.documentElement.scrollLeft ?
		   document.documentElement.scrollLeft :
		   document.body.scrollLeft);
		else return null;
	}

	function mouseY(evt)
	{
		if (evt.pageY) return evt.pageY;
		else if (evt.clientY)
		   return evt.clientY + (document.documentElement.scrollTop ?
		   document.documentElement.scrollTop :
		   document.body.scrollTop);
		else return null;
	}



	function closeLoginBox()
	{
		document.getElementById('loginBox').style.display="none";
	}

	//function for Email Checking
	function IsEmailAddressValid(objEmail,strErrorMesg)
	{
		var blnIsEmailAddress = true;
		var blnObjectPrm=false;
		var i=0;
		var strEmail='';
		var objThis;

		if (isIE)
			blnObjectPrm = (typeof(objEmail)=='object'?true:false) ;

		if (blnObjectPrm) {
			objThis = objEmail;
			strEmail=objEmail.value;
		}
		else
		{
			if (objEmail.substring(0,8)=='document')
			{
				objThis =eval(objEmail);
				strEmail=objThis.value;
				blnObjectPrm = true;
			}
			else
			strEmail=objEmail;
		}
		blnIsEmailAddress=(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1);
		if (!blnIsEmailAddress && strErrorMesg!='')
		{
			//alert(strErrorMesg);
			if (blnObjectPrm)
			{
				//objThis.select();
				objThis.focus();
			}
		}
		return blnIsEmailAddress;
	}

	function validateLoginForm(myform)
	{
		var MasterString="Sorry, we cannot complete your request. Kindly provide us the missing or incorrect information enclosed below.";
		var flag=false;
		var visitor="";

		if (!IsEmailAddressValid(myform.email.value,''))
		{
			visitor +=  "\n- Please enter valid email address.";
			document.getElementById('email').style.backgroundColor='#F9F3C1';
		}
		else
		{
			document.getElementById('email').style.backgroundColor='';
		}

		if (myform.password.value=="")
		{
			visitor +=  "\n- Please enter password.";
			document.getElementById('password').style.backgroundColor='#F9F3C1';
		}
		else
		{
			document.getElementById('password').style.backgroundColor='';
		}

		if (visitor!="")
		{
			MasterString=MasterString + visitor;
			flag=true;
		}

		if(flag==true)
		{
			alert(MasterString);
			return false;
		}
		return true;
	}





	function update_contents(pageID)
	{
            if(document.getElementById('shutOffMsg')) document.getElementById('shutOffMsg').style.display="none";
			var pageID_b = pageID;

		   var srchJoin=" > ";
		   var srchParas="";
		   window.location.hash = '#;';
		  // $('#dvMainContainer').hide(); // make it visible and then load all then make invisible ...
		  $('#dvMainContainer').show();
	      document.getElementById("dvMainContainer").innerHTML ='<div align="center"><img src="http://reskin.mlhstaging.com/images/loading1.gif" style="padding:100px;"></div>' ;
		   //$('#loddivcont').show();
		   var para="task=loadAuctionDetails";


		   //if area is given
		    var area=$("#area").attr("value");
		    if(area!=undefined)
		   para+="&area="+$("#area").val();

			//if venues checked
		   var chkdVenues=$("#venueIDs").attr("value");
		   if(chkdVenues!=undefined){
			   para+="&venueIDs="+chkdVenues;
		   }

			//view only removed properties
		   var chkRemovedVal=$("#chkRemoved").attr("value");
		   if(chkRemovedVal!=undefined && chkRemovedVal==1){
			 para+="&chkRemovedVal="+chkRemovedVal;
		   }

		   //view only escrow properties
		   var chkEscrowPropVal=$("#chkEscrowProp").attr("value");
		   if(chkEscrowPropVal!=undefined && chkEscrowPropVal==1){
			   para+="&chkEscrowPropVal="+chkEscrowPropVal;
		   }

		   var locate="";
			//page number
		   var pageNum=$("#pageNum").attr("value");

		   if(pageNum!=undefined){
			   para+="&page="+pageNum;
			   locate+="&page="+pageNum;
		   }

		   var pageGroup=$("#pageGroup").attr("value");
		   if(pageGroup!=undefined){
			   para+="&pagegroup="+pageGroup;
			   locate+="&pagegroup="+pageGroup;
		   }

		   var getVenueId=$("#getVenueId").attr("value");
		   if(getVenueId!=undefined){
			   para+="&getVenueId="+getVenueId;
		   }

			//show records per page
		   var recsPerPage=$("#recsPerPage").attr("value");
		   if(recsPerPage!=undefined){
			   resetPageVars();
			   para+="&listPaging="+recsPerPage;
			   locate+="&listPaging="+recsPerPage;
		   }

		   	//listing view type list or grid
		   var viewType=$("#viewType").attr("value");
		   if(viewType!=undefined){
			   para+="&view="+viewType;
			   locate+="&view="+viewType;
		   }

		   //show late addition properties
		   var lateAdditions=$("#lateAdditions").attr("value");
		   if(lateAdditions!=undefined){
			   para+="&lateAdditions="+lateAdditions;
		   }

			//viewUpdatedProperties
		   var viewUpdatedProperties=$("#viewUpdatedProperties").attr("value");
		   if(viewUpdatedProperties!=undefined){
			   para+="&viewUpdatedProperties="+viewUpdatedProperties;
		   }

		//nrDate
			var nrDt=$("#nrDt").attr("value");
			if(nrDt!=undefined){
			   para+="&nrDt="+nrDt;
		}

		var alertType=$("#alertType").attr("value");
		if(alertType!=undefined){
		   para+="&alertType="+alertType;
		}

		if(document.getElementById('minPrice'))
	{
		if(document.getElementById('minPrice').firstChild)
		{
			var minPrice=document.getElementById('minPrice').firstChild.nodeValue;
			minPrice=minPrice.replace(/\,/g,'');
		}
		else
		{
			var minPrice='';
		}
	}

	if(minPrice)
	{

		   if(minPrice!=undefined){
			   para.push('&minPrice=',minPrice);
			   //prepare the search result string to display
		}
	}

	if(document.getElementById('maxPrice'))
	{
		if(document.getElementById('maxPrice').firstChild)
		{
			var maxPrice=document.getElementById('maxPrice').firstChild.nodeValue;
			maxPrice=maxPrice.replace(/\,/g,'');
		}
		else
		{
			var maxPrice='';
		}

	}

	if(maxPrice)
	{


		   if(maxPrice!=undefined){
			    para.push('&maxPrice=',maxPrice);
			   //prepare the search result string to display
		}
	}

	   var minYearBuilt=$("#minYearBuilt").attr("value");
   var maxYearBuilt=$("#maxYearBuilt").attr("value");

    if(!isNaN(minYearBuilt))
      {
         //para+="&yearBuilt="+yearBuilt;
		 para.push('&startYear=',minYearBuilt);

        if(!isNaN(maxYearBuilt)) {
		   para.push('&endYear=',maxYearBuilt);
        }else{
           var curdate = new Date();
           maxYearBuilt = curdate.getFullYear();
           para.push('&endYear=',maxYearBuilt);
          }
         var prevV=$('#yearBuilt option:selected').text()
         //prepare the search result string to display
         if(srchParas!="")
         {
           srchParas+=" > ";
         }
         srchParas+="Year Built "+minYearBuilt+" - "+maxYearBuilt;
       }

		//show property loanStatus
		var loanStatus=$("#loanStatus").attr("value");
		if(loanStatus!=undefined){
		   para+="&loanStatus="+loanStatus;
			var loanStatusTxt=$('#loanStatus option:selected').text();
			if(srchParas!=""){
			  // srchParas+=" > ";
		  }
		  //srchParas+=loanStatusTxt;
		 }




		 var total=Array();
			var j=0;
			var el = document.getElementsByName('propertyType[]');
			  for(var i=0; i < el.length; i++){
				if(el[i].checked){
					total[j]=el[i].value;
					j++;
				}
			  }
			var propertyType=total.join(",");
			para+="&propertyType="+propertyType;

	 //show property region
	var geoRegion=$("#geoRegion").attr("value");
	if(geoRegion!=undefined){
	   para+="&geoRegion="+geoRegion;
	    var geoRegionTxt=$('#geoRegion option:selected').text();
		if(srchParas!=""){
		   //srchParas+=" > ";
	  }
	  //srchParas+=geoRegionTxt;
	 }
				//venueCode crieteria
	   var venueCode=$("#venueCode").attr("value");
	   if(venueCode!=undefined){
		   para+="&venueCode="+venueCode;
		   //prepare the search result string to display
		  if(srchParas!=""){
			  // srchParas+=" > ";
		   }
		  // srchParas+="Item# "+venueCode;
	   }

	   //propertyID crieteria
	   var propertyID=$("#propertyID").attr("value");
	   if(propertyID!=undefined){
		   para+="&propertyID="+propertyID;
			  //prepare the search result string to display
		   if(srchParas!=""){
			   //srchParas+=" > ";
		   }
		   //srchParas+="Property ID "+propertyID;
	   }
	//show propertystate
	   var propertyState=$("#propertyState").attr("value");
	   if(propertyState!=undefined){
		   para+="&propertyState="+propertyState;
		   var propertyStateTxt=$('#propertyState option:selected').text();
			if(srchParas!=""){
			   //srchParas+=" > ";
	   }
	   //srchParas+=propertyStateTxt;
	  }

	//show auctionType
	var auctionType=$("#SearchType1").attr("value");
	if(auctionType!=undefined){
	   para+="&auctionType="+auctionType;
		/*if(srchParas!=""){
		   srchParas+=" > ";
	  }	*/
	 }

	var propertyZip=$("#propertyZip").attr("value");
   if(propertyZip!=undefined)
   {
	   para+="&propertyZip="+propertyZip;
   }


   //show Address
   var propertyAddress=$("#propertyAddress").attr("value");
   if(propertyAddress!=undefined && propertyAddress !='Enter Address')
   {
	   para+="&propertyAddress="+propertyAddress;
   }


	var aucTState=$("#auctionState").attr("value");
   var State=$("#State").attr("value");
   if(aucTState!=undefined){
	   para+="&propertyState="+aucTState;
	   if(srchParas!=""){
		   srchParas+=" > ";
	   }
	    if($("#countyName").attr("value"))
	   {
		srchParas+="<a href='"+SITE_PATH+State.replace(" ","-")+"/notes-auctions.html'>"+State+"</a>";
	   }
	   else
	   {
		srchParas+=State;
	   }
   }
    //show State
		   var countyName=$("#countyName").attr("value");
		   if(countyName!=undefined){
			   para+="&propertyCounty="+countyName;
			   if(countyName!=""){
				   srchParas+=" > ";
			   }
			   if($("#cityName").attr("value"))
			   {
			   	srchParas+="<a href='"+SITE_PATH+State.replace(" ","-")+"/"+countyName.replace(" ","-")+"-County/notes-auctions.html'>"+countyName+"</a>";
			   }
			   else
			   {
			   	srchParas+=countyName;
			   }
		   }


			//show city
		   var cityVal=$("#cityName").attr("value");
		   if(cityVal!=undefined){
			   para+="&cityVal="+cityVal;
				if(cityVal!=""){
				srchParas+=" > ";
		   }
		   srchParas+=cityVal;
		  }



   if(srchParas!="")
   {
	 var srchStr=srchParas;
	 para+="&srchString="+srchStr;

   }
   else
   {
	   var srchStr="";
	   para+="&srchString="+srchStr;

   }

	$('#loddivcont').show();



	if(pageID)
	{
		var pgArr=pageID.split("|");
		$("#pageNum").attr("value",pgArr[0]);
		$("#pageGroup").attr("value",pgArr[1]);
		//window.location.hash="page="+pgArr[0]+"&pagegroup="+pgArr[1];
		if(pgArr[0]!=undefined){
		para+="&page="+pgArr[0];
		locate+="&page="+pgArr[0];
		}
		if(pgArr[1]!=undefined){
		   para+="&pagegroup="+pgArr[1];
		   locate+="&pagegroup="+pgArr[1];
		}
	}
	var featured='';
	if(document.getElementById('featured') && document.getElementById('featured').checked==true)
	{
		featured='Yes';
		document.getElementById('featured').value="Yes";
	}
	para+="&featured="+featured;

	var searchProperty=$("#searchProperty").attr("value");
	if(searchProperty!=undefined)
	{
		para+="&searchProperty="+searchProperty;
	}
	$("#loddivcont").show();
	var sortBy=$("#sortByValue").attr("value");
	if(sortBy!=undefined)
	{
	   para+="&sortBy="+sortBy;
	}
	var sortByOrder=$("#sortByOrder").attr("value");
	if(sortByOrder!=undefined)
	{
	   para+="&sortByOrder="+sortByOrder;
	}
	var chkPlatinum=$("#chkPlatinum").attr("checked");

		if(chkPlatinum==true)
		{
		   para+="&chkPlatinum=Yes";
		}
                
                var chkpropertyType_loan=$("#propertyType_loan").attr("checked");

		if(chkpropertyType_loan==true)
		{
		   para+="&propertyType_loan=Yes";
		}

	var alertSuccessUrl=$("#alertSuccessUrl").attr("value");
	if(alertSuccessUrl!=undefined)
	{
	   para+="&backUrl="+alertSuccessUrl;
	}

	// show map result as a list code: added by mayank
	if(document.getElementById('globalMap_mapzipcodelist') && document.getElementById('globalMap_mapzipcodelist').value != "")
	 para+="&mapzipcodelist="+escape(document.getElementById('globalMap_mapzipcodelist').value);

	 if(document.getElementById('globalMap_southWest_lat') && document.getElementById('globalMap_southWest_lat').value != "")
	 para+="&southWest_lat="+document.getElementById('globalMap_southWest_lat').value;
	  if(document.getElementById('globalMap_southWest_lng') && document.getElementById('globalMap_southWest_lng').value != "")
	 para+="&southWest_lng="+document.getElementById('globalMap_southWest_lng').value;
	  if(document.getElementById('globalMap_northEast_lat') && document.getElementById('globalMap_northEast_lat').value != "")
	 para+="&northEast_lat="+document.getElementById('globalMap_northEast_lat').value;
	  if(document.getElementById('globalMap_northEast_lng') && document.getElementById('globalMap_northEast_lng').value != "")
	 para+="&northEast_lng="+document.getElementById('globalMap_northEast_lng').value+"&mapSearch="+true;
	 // end here

	para+="&auctionType=notes";
        
          var srchdist=$("#srchdist").attr("value");
	if(srchdist!=undefined)
	{
		para+="&srchdist="+srchdist;
	}

	$.ajax({
			 type: "POST",
			 url: AJAX_PATH+"ajax/global-search-ajax-notes.php",
			 async: true,
			 global: true,
			 timeout: 15000,
			 data: para,
			 success: function(result){
			 result=result.split("||");
			 sugestCount=result[0];
			 flag=result[1];
			 result=result[2];

			  if(flag==0)
			  {


				showhideAlertdiv(); //--- email alert
				//document.getElementById('emailalert').innerHTML='';
				//document.getElementById('emailalert').innerHTML=result;
                                  if(document.getElementById('noResultDiv'))
				document.getElementById('noResultDiv').style.display='';
				if(sugestCount==0){
					//$('#iphoneDiv').show();
					//document.getElementById('iphoneDiv').style.display='';
				}
				else
				{
					//document.getElementById('iphoneDiv').style.display='none';
				}
                                //$('#dvMainContainer').hide();
								$('#dvMainContainer').show();
								document.getElementById("dvMainContainer").innerHTML =result;
			  }
			  else
			  {

				   $('#loddivcont').hide();
				   $('#alert').show();
				   $('#outer').show();
				   $('#emailalert').hide();
				   $('#emailalertsuccess').hide();
				   $('#emailalertsave').hide();
				   $('#dvMainContainer').show();
				  // $('#iphoneDiv').hide();
				  //document.getElementById('iphoneDiv').style.display='none';
                                    if(document.getElementById('noResultDiv'))
				  document.getElementById('noResultDiv').style.display='none';
				   //$('#loddivcont').html('');
				   $('#dvMainContainer').html(result);
				   //document.getElementById('pageNum').value=1;

					$("a.pageLnk").click(function(){
						$("a.pageLnk").each(function(){
							$(this).removeClass();
							$(this).addClass("page-off pageLnk");
						});
						$(this).removeClass();
						$(this).addClass("page-on");

						var pgID=$(this).attr("id");
						var pgArr=pgID.split("|");
						$("#pageNum").attr("value",pgArr[0]);
						$("#pageGroup").attr("value",pgArr[1]);
						var auctionID=$("#auctionID").attr("value");
						//window.location.hash="page="+pgArr[0]+"&pagegroup="+pgArr[1];
						//update_contents(pgID);
					});
					return false;
			  }
		 },
		 error: function(request, settings, execp)
		 {
			 $('#dvMainContainer').empty();
                           var ff = "update_contents('"+pageID_b+"');";
			// $('#loddivcont').html("<br><b>An error occurred, please try again.</b>");
                         var te = "<br><b>Request time out, <a href='javascript:void(0);' onclick=\""+ff+"\" >click here</a> to please try again.</b>";
			$('#dvMainContainer').html(te);
			//window.location = "auction-details.php?auctionID=<?php echo $_REQUEST['auctionID']?>";
		 }
	});
   }

   function  filterAuctionByRegion(geoRegion,auctionNum,auctID,overAllVenues)
{

	var para = "task=updateStateSelectBoxes&geoRegion="+geoRegion+"&auctionNum="+auctionNum+"&auctID="+auctID+"&overAllVenues="+overAllVenues;
	//alert(para);
	$.ajax({
		 type: "POST",
		 url: "ajax/auction-details-ajax-notes.php",
		 async: true,
		 global: true,
		 data: para,
		 success: function(result){

			document.getElementById("dvpropertyState").innerHTML="";
			document.getElementById("dvpropertyState").innerHTML=result;
		 // return false;
		 }
	});


}


function removeOptions(selectbox)
{
	var i;
	for(i=document.getElementById(selectbox).options.length-1;i>=0;i--)
	{
		if(document.getElementById(selectbox).options[i].selected)
		document.getElementById('State').value=document.getElementById(selectbox).options[i].text;
	}
}
function clearFilter()
{
  $("#auctionType2").attr("value","notes");
  $("#auctionState").attr("value","");
  $("#countyName").attr("value","");
  $("#cityName").attr("value","");
  $("#geoRegion").attr("value","");
  $("#propertyType").attr("value","");
  $("#cityHidden").attr("value","");
  $("#venueCode").attr("value","");
  $("#propertyID").attr("value","");
  $("#collateralType").attr("value","");
  $("#loanStatus").attr("value","");
  $("#propertySearchLocation").attr("value","Address, City & State, or Zip");
  $("#address1").attr("value","");
  $("#hiddenClearFilter1").attr("value","1");
  document.getElementById('srch2').submit();

}


function submitOnClick()
{
	//zip=document.getElementById('propertyZip').value;
	if(document.getElementById('propertyZip') && document.getElementById('propertyZip').value!='')
	{
		zipValidate(document.getElementById('propertyZip').value);
		return false;
	}
	else
	{
		document.getElementById('srch2').submit();
	}


}

