// JavaScript Document
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}

function deleteRecord(id,a){
	if(id.length > 0) {
			if(!confirm("Do you really want to  delete these record?")) {
			return false;
			}
			else{
				window.location.href ="index.php?id="+id+"&a="+a;
				return true;
				}
		}
}

function deleteList(id,a,st,uId){

	if(id.length > 0) {
			if(!confirm("Do you really want to  delete these record?")) {
			return false;
			}
			else{
					if(trim( st ) ){
						window.location.href ="index.php?listid="+id+"&a=viewlistings&list=list&status="+st+"&id="+uId;
					}
				else{	
						window.location.href ="index.php?listid="+id+"&a=viewlistings&list=list&id="+uId;
						return true;
				   }
				}
		}
}
function reRun(id,status,st,uId){
	if(id.length > 0) {
			var txt="";
			switch(status){
					case '0':
						txt = "Activate";
						break;	
					case '1':
						txt = "Expire";
						break;	
					default :
						alert("Error is occured");
						return false;
			}
			if(!confirm("Do you really want to "+ txt +" the record?")) {
			return false;
			}
			else{
				  if(trim( st ) ){
	//alert(uId); return false;
					window.location.href ="index.php?moveid="+id+"&a=viewlistings&act="+status+"&status="+st+"&id="+uId;
				  }
				  else
				  	window.location.href ="index.php?moveid="+id+"&a=viewlistings&act="+status+"&id="+uId;
				return true;
				}
		}
}

function validateStep1(){
	var prz		= trim(document.up_form1.elements["h[Price]"].value);
	var addr	= trim(document.up_form1.elements["h[Address]"].value);
	var zip		= trim(document.up_form1.elements["h[Zip]"].value);
	if(prz.length<=0){
			alert("Pleae enter price");
			document.up_form1.elements["h[Price]"].focus();
			return false;
	}
	if(isNaN(prz))
	{
		alert("Price must be digits");
 	 	document.up_form1.elements["h[Price]"].focus();
  	 	return false;
	}
	if(!isNaN(prz) && prz < 100)
	{
		alert("Minimum Price must be 100$");
 	 	document.up_form1.elements["h[Price]"].focus();
  	 	return false;
	}
	if(addr.length<=0)
	{
	  alert("Please Enter the Listing Address");
	  document.up_form1.elements["h[Address]"].focus();
	  return false;
	}
	if(zip.length<=0)
	{
	  alert("Enter the zip code");
	  document.up_form1.elements["h[Zip]"].focus();
	   return false;
	}
}
function validateStep2(){
	var a		= trim(document.up_form2.a.value);
	var fName	= trim(document.up_form2.imgfile.value);
	if(a != "edit" && fName.length == 0){
			alert("Please select the required picture");
			document.up_form2.imgfile.focus();
			return false;
	}
	else 
	if(a == "edit" && fName.length == 0){
		if(!confirm("Are you sure you want to keep the current picure?"))
			return false;
		else 
			return true;
	}
}
function openWindow1(url,window_name,winWidth,winHeight,fscroll) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	

	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	if(fscroll == '') {fscroll = 0}
	//window.open(url,window_name,"width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=" + fscroll + ",resizable=0");
}
function openWindow() {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 350;
	winHeight = 200;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open('includes/addAgent.php',"Details","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
function editWindow() {
	sObj	= eval(document.getElementById('r[uRealtor]'));
	var id	= sObj.options[sObj.selectedIndex].value;
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 350;
	winHeight = 200;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open('includes/editagent.php?id='+id,"Details","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}
//Used in free magazine section
function openWindow1() {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 550;
	winHeight = 400;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;
	window.open('includes/freecopy.php',"Details","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
}

function valid(){
	var office		= trim(document.agent_form.a_name.value);
	if(office.length<=0)
	{
	  alert("Please enter the agent name");
	  document.agent_form.a_name.focus();
	   return false;
	}
	else if(office.length<3)
	{
	  alert("Agent name is too short, minimum 4 charactors..");
	  document.agent_form.a_name.focus();
	   return false;
	}
}
function validEdit(){
	var office		= trim(document.agent_form.e_name.value);
	if(office.length<=0)
	{
	  alert("Please enter the agent name");
	  document.agent_form.e_name.focus();
	   return false;
	}
	else if(office.length<3)
	{
	  alert("Agent name is too short, minimum 4 charactors..");
	  document.agent_form.e_name.focus();
	   return false;
	}
}
function showPhoto(photoUrl) {
		sWidth = screen.availWidth;
		sHeight = screen.availHeight;
		winWidth = 300;
		winHeight = 300;
		sLeft = (sWidth - winWidth) / 2;
		sTop = (sHeight - winHeight) / 2;
		window.open("includes/showIcon.php?iconUrl=" + photoUrl,"photoUrl","width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	}
function validateSearch(){
	var valu	= trim(document.srchFrm.sRealtors.value);
	if(valu.length<=0)
	{
	  alert("Please enter the search value");
	  document.srchFrm.sRealtors.focus();
	   return false;
	}
}

function selecting(){
		sObj	= eval(document.getElementById('r[uRealtor]'));
		alert(sObj.options[sObj.selectedIndex].value);
}
