var Error;

$(document).ready(function(){
	
	function selectOptionLoading()
	{
		return "<option value='-1'>"+AllLoading+"</option>";	
	}
	
	function selectOptionDefault()
	{
		return "<option value='-1'>"+All+"</option>";	
	}
	
	function selectOptionDefaultSelect()
	{
		return "<option value='-1'>"+Selected+"</option>";	
	}
		
	function ajaxError(value)
	{
		alert(value);	
	}
	$("#frmSearch #City").change(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=getTownship&SelectClass=DefaultSelectMenu&culture='+$("#lang").val()+'&ParentID='+$("#frmSearch  #City").val(),
				contentType: "application/json; charset=utf-4",
				
				beforeSend: function(result)
				{
					$("#frmSearch #Township").html(selectOptionLoading());
				},
				
				error: function(result)
				{
					ajaxError(result.responseText);
				},
				
				success: function(result) {
					$("#frmSearch #Township").html(result);
					$("#frmSearch  #Area").html(selectOptionDefault());
				}
			});		
	});
	
	$("#frmSearch  #Township").change(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=getArea&SelectClass=DefaultSelectMenu&culture='+$("#lang").val()+'&ParentID='+$("#frmSearch  #Township").val(),
				contentType: "application/json; charset=utf-8",
				
				beforeSend: function(result)
				{
					$("#frmSearch  #Area").html(selectOptionLoading());
				},
				
				error: function(result)
				{
					ajaxError(result.responseText);
				},
				
				success: function(result) {
					$("#frmSearch  #Area").html(result);
				}
			});		
	});
	
	
	$("#mail-list a").click(function(){
		var $first_last_name = $("#mail-list #first_last_name");
		var $email = $("#mail-list #email");
		var pattern  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
		
		if($first_last_name.val() == '')
		{
			alert(QuestionFirstLastName);
			$first_last_name.focus();
			return false;
		}
		
		if(!pattern.test($email.val()))
		{
			alert(QuestionEmail);
			$email.focus();
			return false;
		}

		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=addMailList&first_last_name='+$first_last_name.val()+'&email='+$email.val()+'&culture='+$("#lang").val(),
			contentType: "application/json; charset=utf-8",
			
			beforeSend: function(result)
			{
				$("#mail-list  span").html(''+Processing+'');
			},
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$("#mail-list  span").html(result);
			}
		});		
	});
	
	$("#pool .vote").click(function(){
	   	$("#frmPoll").submit();
	});
	
	$("#right-credit #BankName").change(function(){
		
		var $ParentID = $("#right-credit #BankName");
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getCreditCurrency&ParentID='+$ParentID.val()+'&culture='+$("#lang").val(),
			contentType: "application/json; charset=utf-8",
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$("#right-credit  #CreditCurrency").html(result);
			}
		});
	});
	
	$("#right-credit #CreditCurrency").change(function(){
		var $ParentID = $("#right-credit #BankName");
		var $Currency = $("#right-credit #CreditCurrency");
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getCreditFinancing&ParentID='+$ParentID.val()+'&Currency='+$Currency.val()+'&culture='+$("#lang").val(),
			contentType: "application/json; charset=utf-4",
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$("#right-credit  #CreditFinancing").html(result);
			}
		});
	
	});
	
	$("#right-credit .Calculate").click(function(){
		
		var $BankName = $("#right-credit #BankName");
		var $Amount = $("#right-credit #Amount");
		var $Currency = $("#right-credit #CreditCurrency");
		var $CreditFinancing = $("#right-credit #CreditFinancing");
		
		if($BankName.val() == -1)
		{
			alert(''+QuestionBankName+'');
			$BankName.focus();
			return false;
		}
		
		if($Amount.val() == 0 || $Amount.val() == '' || $Amount.val() < 1)
		{
			alert(''+QuestionAmount+'');
			$Amount.focus();
			return false;
		}
		
		if($Currency.val() == -1)
		{
			alert(''+QuestionCurrency+'');
			$Currency.focus();
			return false;
		}
		
		if($CreditFinancing.val() == -1)
		{
			alert(''+QuestionRate+'');
			$CreditFinancing.focus();
			return false;
		}
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getCreditResult&BankID='+$BankName.val()+'&Amount='+$Amount.val().replace(".","")+'&Currency='+$Currency.val()+'&CreditFinancing='+$CreditFinancing.val()+'&culture='+$("#lang").val(),
			contentType: "application/json; charset=utf-4",
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$("#right-credit  #CreditResult").css("display", "block");
				$("#right-credit  #CreditResult").html(result);
			}
		});
	});
	
	
	$("#currency-converter .calculate-convert").click(function()
	{
		var $FromAmount = $("#currency-converter #FromAmount");
		var $CurrencyFrom = $("#currency-converter #CurrencyFrom");
		var $CurrencyTo = $("#currency-converter #CurrencyTo");
		
		if($FromAmount.val() == 0 || $FromAmount.val() == '' || $FromAmount.val() < 1)
		{
			alert(''+QuestionAmount+'');
			$FromAmount.focus();
			return false;
		}
		
		if($CurrencyFrom.val() == -1)
		{
			alert(''+QuestionCurrency+'');
			$CurrencyFrom.focus();
			return false;
		}
		
		if($CurrencyTo.val() == -1)
		{
			alert(''+QuestionCurrencyTo+'');
			$CurrencyTo.focus();
			return false;
		}
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getCurrencyConverter&FromAmount='+$FromAmount.val().replace(".","")+'&CurrencyFrom='+$CurrencyFrom.val()+'&CurrencyTo='+$CurrencyTo.val()+'&culture='+$("#lang").val(),
			contentType: "application/json; charset=utf-4",
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$("#currency-converter  #ConvertResult").css("display", "block");
				$("#currency-converter  #ConvertResult").html(result);
			}
		});
	});
	
	$("#carousel").css("display", "block");
	
	$("#carousel").jCarouselLite({
		auto:2000,
		speed:800,
		visible:5,
		start:0,
		vertical:false
	});
	
	$("#main-advert li a").click(function(){
		$("#main-advert li").removeClass("main-advert-selected");
		$(this).parent().addClass("main-advert-selected");
		var $this = $(this);
		var $content = $this.html();
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: 'action=getMainAdvert&culture='+$("#lang").val()+'&type='+$this.attr("type"),
			contentType: "application/json; charset=utf-4",
			
			beforeSend: function(result)
			{
				$this.html(AllLoading);
			},
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			success: function(result) {
				$this.html($content);
				$("#main-advert-content").html(result);
			}
		});
	});
	
	$("#more-info-send").click(function(){
		var $first_last_name_more = $("#first_last_name_more");
		var $Phone_more = $("#Phone_more");
		var $Email_more = $("#Email_more");
		var $InfoMessages_more = $("#InfoMessages_more");
		var $image_text_more = $("#image_text_more");
		
		if($first_last_name_more.val() == '')
		{
			alert(''+QuestionFirstLastName+'');
			$first_last_name_more.focus();
			return false;
		}
		
		if($Phone_more.val() == '')
		{
			alert(''+QuestionPhone+'');
			$Phone_more.focus();
			return false;
		}
		
		var pattern  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
		if(!pattern.test($Email_more.val()))
		{
			alert(QuestionEmail);
			$Email_more.focus();
			return false;
		}
		
		if($InfoMessages_more.val() == '')
		{
			alert(''+QuestionMess+'');
			$InfoMessages_more.focus();
			return false;
		}
		
		if($image_text_more.val() == '')
		{
			alert(''+QuestionConfirmCode+'');
			$image_text_more.focus();
			return false;
		}
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: $("#frmInfo").serialize().replace("action_more","action"),
			contentType: "application/json; charset=utf-4",
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			beforeSend: function(result)
			{
					$("#more-information .process-more").css("display", "block");
			},
			
			success: function(result) {
				$("#more-information .process-more").css("display", "none");
				if(result.search("{:err:}") == 0)
				{
					
					alert(result.replace("{:err:}",""));
				}
				else
				{
					$("#more-information .module-content").html(result);
				}
			}
		});
	});
	
	$("#more-info-link").click(function(){
		$("#first_last_name_more").val("");
		$("#Phone_more").val("");
		$("#Email_more").val("");
		$("#InfoMessages_more").val("");
		$("#image_text_more").val("");
	});

	$("#send-friend-send").click(function(){
		
		var $first_last_name_friend = $("#first_last_name_friend");
		var $first_last_name_friend_friend = $("#first_last_name_friend_friend");
		var $Email_friend = $("#Email_friend");
		var $Email_friend_friend = $("#Email_friend_friend");
		var $image_text_friend = $("#image_text_friend");
		
		if($first_last_name_friend.val() == '')
		{
			alert(''+QuestionFirstLastName+'');
			$first_last_name_friend.focus();
			return false;
		}
		
		if($first_last_name_friend_friend.val() == '')
		{
			alert(''+QuestionFriendName+'');
			$first_last_name_friend_friend.focus();
			return false;
		}
		
		var pattern  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
		if(!pattern.test($Email_friend.val()))
		{
			alert(QuestionEmail);
			$Email_friend.focus();
			return false;
		}
		
		if(!pattern.test($Email_friend_friend.val()))
		{
			alert(QuestionFriendEmail);
			$Email_friend_friend.focus();
			return false;
		}
		
		if($image_text_friend.val() == '')
		{
			alert(''+QuestionConfirmCode+'');
			$image_text_friend.focus();
			return false;
		}
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: $("#frmFriend").serialize().replace("action_friend","action"),
			contentType: "application/json; charset=utf-8",
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			beforeSend: function(result)
			{
					$("#send-friend-main .process-friend").css("display", "block");
			},
			
			success: function(result) {
				$("#send-friend-main .process-friend").css("display", "none");
				if(result.search("{:err:}") == 0)
				{
					
					alert(result.replace("{:err:}",""));
				}
				else
				{
					$("#send-friend-main .module-content").html(result);
				}
			}
		});
		
	});
	
	$("#send-friend-link").click(function(){
		$("#first_last_name_friend").val("");
		$("#first_last_name_friend_friend").val("");
		$("#Email_friend").val("");
		$("#Email_friend_friend").val("");
		$("#image_text_friend").val("");
	});
	
	$("#sale-menu").hover(function(){
		var off = $(this).offset();
		$("#for-sale-dropdown").css( {left:off.left-1, top:off.top+33, zIndex :9999}).show();
		$("#frame-for-sale-dropdown").css( {left: off.left-2, top: off.top+35, height:$("#for-sale-dropdown").height()}).show();

		}, function () {
            $("#for-sale-dropdown").hide();
			$("#frame-for-sale-dropdown").hide();
    });
	
	$("#for-sale-dropdown").hover(function(){
		$("#for-sale-dropdown").show();
		$("#frame-for-sale-dropdown").show();
	}, function () {
        $("#for-sale-dropdown").hide();
		$("#frame-for-sale-dropdown").hide();
    });
	
	$("#rent-menu").hover(function(){
		var off = $(this).offset();
		$("#for-rent-dropdown").css( {left:off.left-1, top:off.top+33, zIndex :9999} ).show();
		$("#frame-for-rent-dropdown").css( {left: off.left-2, top: off.top+35, height:$("#for-rent-dropdown").height()}).show();
		}, function () {
            $("#for-rent-dropdown").hide();
			$("#frame-for-rent-dropdown").hide();
    });
	
	$("#for-rent-dropdown").hover(function(){
		$("#for-rent-dropdown").show();
		$("#frame-for-rent-dropdown").show();
	}, function () {
        $("#for-rent-dropdown").hide();
		$("#frame-for-rent-dropdown").hide();
    });
	
	$("#advert-detail-map").click(function(){
		window.open(''+$("#advert-detail-map a").attr("href")+'', 'GoogleMap', "location=0,status=0,scrollbars=0,width=730,height=500");
		return false;
	});
	
	$("#advert-detail-video a").click(function(){
		window.open(''+$(this).attr("href")+'', 'Video', "location=0,status=0,scrollbars=0,width=600,height=450");
		return false;
	});
	
	
	$("#contact-form a").click(function(){
		var $first_last_name = $("#FirstLastName");
		var $messages = $("#Messages");
		var $img_text = $("#image_text");
		
		if($first_last_name.val() == '')
		{
			alert(''+QuestionFirstLastName+'');
			$first_last_name.focus();
			return false;
		}
		
		if($messages.val() == '')
		{
			alert(''+QuestionMess+'');
			$messages.focus();
			return false;
		}
		
		if($img_text.val() == '')
		{
			alert(''+QuestionConfirmCode+'');
			$img_text.focus();
			return false;
		}
		
		$.ajax({
			type: 'GET',
			url: 'include/ajax.php',
			data: $("#frmContact").serialize().replace("action_friend","action"),
			contentType: "application/json; charset=utf-8",
			
			error: function(result)
			{
				ajaxError(result.responseText);
			},
			
			beforeSend: function(result)
			{
					$("#contact-form .process-contact").css("display", "block");
			},
			
			success: function(result) {
				$("#contact-form .process-contact").css("display", "none");
				if(result.search("{:err:}") == 0)
				{
					
					alert(result.replace("{:err:}",""));
				}
				else
				{
					$("#contact-form").html(result);
				}
			}
		});
		
	});
	
	$("#frmAddEstate #add_City").change(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=add-getTownship&SelectClass=DefaultSelectMenu&culture='+$("#lang").val()+'&ParentID='+$("#frmAddEstate  #add_City").val(),
				contentType: "application/json; charset=utf-8",
				
				beforeSend: function(result)
				{
					$("#frmAddEstate #add_Township").html(selectOptionDefaultSelect());
				},
				
				error: function(result)
				{
					ajaxError(result.responseText);
				},
				
				success: function(result) {
					$("#frmAddEstate #add_Township").html(result);
					$("#frmAddEstate  #add_Area").html(selectOptionDefaultSelect());
				}
			});		
	});
	
	$("#frmAddEstate  #add_Township").change(function(){
		$.ajax({
				type: 'GET',
				url: 'include/ajax.php',
				data: 'action=add-getArea&SelectClass=DefaultSelectMenu&culture='+$("#lang").val()+'&ParentID='+$("#frmAddEstate  #add_Township").val(),
				contentType: "application/json; charset=utf-8",
				
				beforeSend: function(result)
				{
					$("#frmAddEstate  #add_Area").html(selectOptionLoading());
				},
				
				error: function(result)
				{
					ajaxError(result.responseText);
				},
				
				success: function(result) {
					$("#frmAddEstate  #add_Area").html(result);
				}
			});		
	});
});

var sep = ".";
	function formatCurrency(str)
	{
		inpValue = str.value;
		var fromIndex = 0;
		var toIndex = 0;
		ytlVal = inpValue;
		var unformattedString = deCommafy(ytlVal) ;
		if ( unformattedString.length > 9 )
		{
			unformattedString = unformattedString.substring(0,9);
		}
		if ( !isNaN( parseInt(unformattedString,10) ) )
		{
			unformattedString = parseInt(unformattedString,10).toString(); 
		} 
		else
		{ 
			str.value = "";
			str.focus();
			return;
		}
		str.value = commafy( unformattedString );
	}	

	function deCommafy(inpValue)
	{
		if(inpValue != null)
		{
			var re = eval("/\\" + sep + "/g");
			return inpValue.replace(re,"");      
		}
	}

	function commafy(inpValue)
	{
		var re = /(\d+)(\d{3})/;
		while (re.test(inpValue))
		{
			inpValue = eval("inpValue.replace(re,'$1" + sep + "$2')");
		}
		return inpValue;
	}

function PopWin(val)
{
	var b = val.replace("normal", "big");
	popImage(b,'Images','middle_center',true,false);
	return false;
}

function openWindow(url, name, params) 
{ 
  window.open(url, name, params);
}


function trimAll(str) {
 var objRegExp = /^(\s*)$/;
    if(objRegExp.test(str)) {
       str = str.replace(objRegExp, '');
       if( str.length == 0)
          return str;
    }

    

   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;

   if(objRegExp.test(str)) {

       str = str.replace(objRegExp, '$2');

    }

	

  return str;

}



function validateNotEmpty(str, msg) {	

   var strTemp = str.value;

   if(strTemp.length <= 0) {

	  str.focus();

	  Error = msg;

	  return false;

   }

}

function validateSelectMenu(str, msg) 
{
   if(str.val() == -1) 
   {
	  str.focus();
	  Error = msg;
	  return;
   }
}

  

function validateZero(str, msg) {	

   if(str.value == 0) {

	  str.focus();

	  Error = msg;

	  return;

   }

}

function validateZeroOne(str, msg) {	
   if(str.value == -1) {
	  str.focus();
	  Error = msg;
	  return;
   }
}




function validateEmail(str, msg) {	

 	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;

	

	if (!objRegExp.test(str.value)) {

		str.focus();

		Error = msg;

		return;		

	}

 }



function matchStr(str1, str2, msg) {	

	if (str1.value != str2.value) {

		str2.focus();

		Error = msg;

		return;			

	}

}



function matchStrErr(str1, str2, msg) {	

	if (str1.value == str2.value) {

		str2.focus();

		Error = msg;

		return;			

	}

}





function validatePassword(str, msg) {

	var objRegExp = /^[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*|[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*|[a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*|[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*|[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*|[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*/; 

	if (!objRegExp.test(str.value)) {

		str.focus();

		Error = msg;

		return;		

	}	

 }

 

function validateInteger(str, msg) {

  var objRegExp  = /(^-?\d\d*$)/;

 	if (!objRegExp.test(str.value)) {

	// if (!objRegExp.test(str.value) || str.value=='') {

		str.focus();

		Error = msg;

		return;		

	}	

}



function validateIntegerAndEmpty(str, msg) {

    var strTemp = str.value;

	var objRegExp  = /(^-?\d\d*$)/;

 	if (strTemp != '') {

		if (!objRegExp.test(str.value)) {

			str.focus();

			Error = msg;

			return;		

		}

 	}

}





function validateLenght(str, strMin, strMax, msg) {

	 var strTemp = str.value;

	 if (strTemp.length >= strMin && strTemp.length <= strMax ) {

	 } else {

		str.focus();

		Error = msg;

		return;	 

	 }

}


function validatePasswordTemp(str, msg) {

		  validateLenght(str, 6, 10, msg);

		  validatePassword(str, msg);

}



function validateLength(str, msg, min_value, max_value) 
{
		 validateInteger(str, msg);
		 validateLenght(str, min_value, max_value, msg);
}



function clickclear(thisfield, defaulttext) {
		if (thisfield.value == defaulttext) {
			thisfield.value = "";
			}
		}

function clickrecall(thisfield, defaulttext) {
		if (thisfield.value == "") {
			thisfield.value = defaulttext;
			}
		}

function getLang(val) 
{
	document.frmLang.ChangeLang.value = val;
	document.frmLang.submit();
}


function frmSubmitSearch() {
	var frm = document.frmSearch;
	Error = '';
	validateZeroOne(frm.City, ''+QuestionSelectCity+'');
	if (Error=='')
	{
		if (frm.m_min.value != ''+PWith+'' && frm.m_max.value != ''+PBetween+'')
		{
			if(parseInt(frm.m_min.value) > parseInt(frm.m_max.value))
			{
				Error = ''+QuestionSquareMeter+'';
			}
		}
	}
	
	if (Error=='')
	{
		if (frm.p_min.value != ''+PWith+'' && frm.p_max.value != ''+PBetween+'')
		{
			if(parseInt(frm.p_min.value) > parseInt(frm.p_max.value))
			{
				Error = ''+QuestionWithPrice+'';
			}
		}
	}
		
	if (Error=='')
		return true;
	else 
		alert(Error);
	return false;
}

function myFormSubmitSearch() 
{
	if (frmSubmitSearch()) 
	{ 
		document.frmSearch.submit();
	} 
	else 
	{
		return false;
	}
}

function frmSubmitRefNo() 
{
	var frm = document.frmRefNo;
	Error = "";
	validateNotEmpty(frm.RefNo, ''+QuestionRefNo+'');
	
	if (Error=='')
		return true;
	else 
		alert(Error);
	return false;
}

function myFormSubmitRefNo() 
{
	if (frmSubmitRefNo()) 
	{ 
		document.frmRefNo.submit();
	} 
	else 
	{
		return false;
	}
}

function frmSubmitEstate() {
	var frm = document.frmAddEstate;
	Error = "";
	validateZeroOne(frm.add_City, ''+QuestionSelectCity+'');
	if (Error=='')
	validateZeroOne(frm.add_Township, ''+QuestionSelectTownShip+'');
	if (Error=='')
	validateZeroOne(frm.add_EstateStatus, ''+QuestionEstateStatus+'');
	if (Error=='')
	validateZeroOne(frm.add_EstateType, ''+QuestionEstateType+'');
	if (Error=='')
	validateZero(frm.RentPrice, ''+QuestionRentPrice+'');
	if (Error=='')
	validateZeroOne(frm.RentCurrency, ''+QuestionRentCurrency+'');
	
	
	if (Error=='')
	validateNotEmpty(frm.FirstLastName, ''+QuestionFirstLastName+'');
	if (Error== '')
	validateNotEmpty(frm.Phone, ''+QuestionPhone+'');
	if (Error== '')
	validateEmail(frm.Email, ''+QuestionEmail+'');
	if (Error== '')
	validateNotEmpty(frm.Messages, ''+QuestionMess+'');
	if (Error== '')
	validateNotEmpty(frm.image_text, ''+QuestionConfirmCode+'');
	if (Error== '')
	validateNotEmpty(frm.image_text, ''+QuestionConfirmCode+'');
	
	if (Error=='')
		return true;
	else 
		alert(Error);
	return false;
}

function myFormSubmitEstate() 
{
	if (frmSubmitEstate()) 
	{ 
		document.frmAddEstate.submit(); 
	} 
	else 
	{
		return false;
	}
}

function formSubmitRequest() {
	var frm = document.frmAddEstate;
	Error = "";
	validateZeroOne(frm.add_City, ''+QuestionSelectCity+'');
	if (Error== '')
	validateZeroOne(frm.add_Township, ''+QuestionSelectTownShip+'');
	if (Error=='')
	validateZeroOne(frm.add_EstateStatus, ''+QuestionEstateStatus+'');
	if (Error=='')
	validateZeroOne(frm.add_EstateType, ''+QuestionEstateType+'');
	if (Error=='')
	validateNotEmpty(frm.EstateMaxPrice, ''+QuestionMaxPrice+'');
	if (Error=='')
	validateNotEmpty(frm.FirstLastName, ''+QuestionFirstLastName+'');
	if (Error== '')
	validateNotEmpty(frm.Phone, ''+QuestionPhone+'');
	if (Error=='')
	validateEmail(frm.Email, ''+QuestionEmail+'');
	if (Error== '')
	validateNotEmpty(frm.image_text, ''+QuestionConfirmCode+'');
				
	if (Error=='')
		return true;
	else 
		alert(Error);
	return false;
}

function myFormSubmitRequest() {
	if (formSubmitRequest() ) { 
		document.frmAddEstate.submit(); 
		} else {
			return false;
		}
}



function popImage(imageURL,imageTitle,pos,AutoClose,CopyRight){
	//Safari workaround
	is_safari=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1)?true:false;
	safari_version=Number(navigator.userAgent.substring(navigator.userAgent.indexOf("Safari/")+4));
	if (is_safari && safari_version<300){
		var f="top=0, left=0, width="+screen.width+",height="+screen.height+" ,scrollbars=yes";
		imgWin=window.open(imageURL,'im',f);
	}
	else{
		//Based on browser set correct resize mode
		if (parseInt(navigator.appVersion.charAt(0))>=4){
			if (navigator.appName=="Netscape" || is_safari){
				var f="width="+screen.width+",height="+screen.height;	
				var rs="var iWidth=window.innerWidth;iHeight=window.innerHeight";
				var adj="0";
			}
			if(document.all){
				var f="width=150,height=150";	
				var rs = "var iWidth=document.body.clientWidth;iHeight=document.body.clientHeight;";
				if(typeof window.opera != 'undefined'){ 
					 var adj="window.outerHeight-24";
				 }
				else{
					var adj="32";
				}	 
			} 
		}
		//
		v=pos.substring(0,pos.indexOf("_"));
		h=pos.substring(pos.indexOf("_")+1);
		f+=",left=0,top=0";
		imgWin=window.open('about:blank','',f);
		imDoc=imgWin.document;
		with (imDoc){
			writeln('<html><head><title>Loading...</title>');writeln('<sc'+'ript>');
			writeln('var sdstr=\"\";window.onerror=function(){return true;}');
			writeln('function resizeWin(){');
			//If the image size is bigger then screen resize window to the screen size
			writeln('sc=(navigator.userAgent.toLowerCase().indexOf("safari")!=-1)?15:"";');
			writeln('iW=document.images[0].width;iH=document.images[0].height;sW=screen.availWidth;sH=screen.availHeight;');
			writeln('if(iW>=sW || iH>=sH){window.resizeTo(sW,sH);window.moveTo(0,0)}else{');
			writeln(rs);
			writeln('var v=\"'+v+'\";var h=\"'+h+'\";');
			writeln('switch (v){case \"top\":vPos=0;break;case \"middle\":vPos=(sH-iH-'+adj+')/2;break;case \"bottom\":vPos=sH-'+adj+'-iH'+((is_safari)?'-20':'')+';break;default: vPos=0;}');
			
			writeln('switch (h){case \"left\":hPos=0;break;case \"center\":hPos=(sW-iW)/2;break;case \"right\":hPos=sW-iW'+((is_safari)?'-20':'')+';break;default: hPos=0;}');
			writeln('iWidth = document.images[0].width - iWidth;iHeight = document.images[0].height - iHeight;');
			writeln('window.resizeBy(iWidth+sc, iHeight+sc);');
			writeln('window.moveBy(hPos,vPos)}}');
			writeln('function doTitle(){document.title="'+unescape(imageTitle)+'";}'+'</sc'+'ript>');
			var cT=(!AutoClose)?"":"onBlur=\"sdstr=setTimeout('window.close(this)',1000)\"";
			//Prevent closing in IE
			var fL=(!AutoClose)?"":"onfocus=\"clearTimeout(sdstr)\"";
			var safari_fix=(is_safari)?" onload='resizeWin()'":"";
			if(!CopyRight){var cr1="";var cr2=""}else{var cr1=" galleryimg=\"no\" title=\"Copyright Protected\" onmousedown=\"window.close()\" ";var cr2="oncontextmenu=\"return false\" "}
			writeln('</head><body  leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"FFFFFF\"  onload="'+ ((!is_safari)?'resizeWin();doTitle();':'')+'self.focus()" '+cT+' '+fL+' '+cr2+'>');
			writeln('<div '+fL+' align=\"center\" style=\"width:100%;height:100%;overflow:auto\"><img src="'+imageURL+'" '+cr1+safari_fix+' ></div></body></html>');
			close();
		}
	}
}

function CheckNumberCode(e) {
		 ev = document.all ? window.event : e;
		 keyCode = document.all ? ev.keyCode : ev.which;
		 if(keyCode >= 48 && keyCode <= 57 || keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 46 || keyCode >= 96 && keyCode <= 105 || keyCode == 37 || keyCode == 39) {
			return true;
			} else {
			return false;
			}
	}
