var message="";

function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")

var ns6=document.getElementById&&!document.all?1:0
var head="display:''"
var folder=''

function expandit(curobj){
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style
if (folder.display=="none")
folder.display=""
else
folder.display="none"
}

//configure the two variables below to match yoursite's own info
var bookmarkurl="http://www.property-bangkok.net"
function addbookmark(lg)
{
var bookmarktitle="";
if(lg==1)
{
	bookmarktitle="Tailor made Shirts Trousers and Overcoats for men"
}


//else
//{
//	bookmarktitle="Hemden, Hosen, Anzuege und Maentel fuer Maenner nach Mass"
//}
if (document.all)
window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function notYet()
{
	alert("Sorry this item is not available yet!");
}

function printThis()
{
if (window.print != null) 
{ window.print(); }
 else
 { alert('Unfortunately, your browser does not support this shortcut. Please select Print from the File menu.'); }
}

function WholeNumberOnly(opt,msg)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }	 
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }
}

function WholeNumberOnlyEmpty(opt,msg)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }	 
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }
}

function TinyIntOnly(opt,msg)
{
	if(opt.value>255)
	{
		alert("The "+msg+" can not be greater than 255!");
		opt.value="";
		opt.focus();
	}
}

function NumericOnly(opt,msg)
{
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }
}

function NumericOnlyEmpty(opt,msg)
{
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be numbers!"); 
		opt.value="";
		opt.focus();
	  }
}

function SetZero(opt)
{
	if  (opt.value=="")
	  {
		opt.value=0;
	  }
}

function SetBlank(opt)
{
	if  (opt.value=="0")
	  {
		opt.value="";
	  }
}

function isDate(DateToCheck)
{
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){;return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){;
return true;
} 
else{;
return false;
}
}//end function

function FormatDate(DateToFormat,FormatAs){

if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}
var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

}

function checkEmailValid(emailStr,msg)
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var errMsg="";   
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
	   errMsg=errMsg+"The "+msg+"email address seems incorrect!";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {
		errMsg=errMsg+"The "+msg+"email address seems incorrect!";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+"The "+msg+"email address seems incorrect!";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+"The "+msg+"email address seems incorrect!";
		 return errMsg;
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	   {
		 errMsg=errMsg+"The "+msg+"email address seems incorrect!";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+"The "+msg+"email address seems incorrect!";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}
function showTodayDate()	//this function has to be on each page please do not move!
{
	var myDate=new Date();
	var monthName="";
	dayNum=myDate.getDate()/1;
	monthNum=myDate.getMonth()/1;
	yearNum=myDate.getFullYear();

	if(monthNum==0)
	{
		monthName='January'
	}
	else if(monthNum==1)
	{
		monthName='February'
	}
	else if(monthNum==2)
	{
		monthName='March'
	}
	else if(monthNum==3)
	{
		monthName='April'
	}
	else if(monthNum==4)
	{
		monthName='May'
	}
	else if(monthNum==5)
	{
		monthName='June'
	}
	else if(monthNum==6)
	{
		monthName='July'
	}
	else if(monthNum==7)
	{
		monthName='August'
	}
	else if(monthNum==8)
	{
		monthName='September'
	}
	else if(monthNum==9)
	{
		monthName='October'
	}
	else if(monthNum==10)
	{
		monthName='November'
	}
	else if(monthNum==11)
	{
		monthName='December'
	}
	if(dayNum<10)
	{
		dayNum="0"+dayNum;
	}
	myDate=dayNum+' '+monthName+' '+yearNum;
	document.all('strTodayDate').innerText ="  "+myDate;
}

function checkRegister()
{
	var pw=document.frmData.strPassword.value;
	var cfpw=document.frmData.strConfPassword.value;

	var fname=document.frmData.strFullName.value;
	if (fname=="" || fname==" " || fname=="-" || fname=="_" || fname==".")
	{
		alert("Please enter your full name!");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	if (checkEmailValid(e)!="0") 
	{
		alert(checkEmailValid(e,'your'));
		return false;	
	}

	var tel=document.frmData.strTelephone.value;
	if (tel=="" || tel==" " || tel=="-" || tel=="_" || tel==".")
	{
		alert("Please enter your telephone number!");
		return false;
	}
	var addr=document.frmData.strAddress.value;
	if (addr=="" || addr==" " || addr=="-" || addr=="_" || addr==".")
	{
		alert("Please enter your address!");
		return false;
	}
	if (addr.length > 512)
	{
		  alert("The maximum characters of the address is 512!");
		  return false;
	}
		if(document.frmData.lngCountryId.value=="0")
		{
			alert("Please select a country!");
			return false;
		}
	if((pw=="" || pw==" " || pw=="-" || pw=="_" || pw==".") && (pw=="" || pw==" " || pw=="-" || pw=="_" || pw=="."))
	{
		alert("Please enter your password!");
		return false;
	}
	if((cfpw=="" || cfpw==" " || cfpw=="-" || cfpw=="_" || cfpw==".") && (cfpw=="" || cfpw==" " || cfpw=="-" || cfpw=="_" || cfpw=="."))
	{
		alert("Please confirm your password!");
		return false;
	}
	if(pw!=cfpw)
	{
		alert("Your password and confirm password do not match!")
		return false;
	}
	return true;
}
function checkProductSearch()
{
	var wkey=document.frmData.strWordKey.value;
	if (wkey=="" || wkey==" " || wkey=="-" || wkey=="_" || wkey==".")
	{
		alert("Please enter your key word!");
		return false;
	}
	return true;
}
function checkCustomerSign()
{
	var e=document.frmData.strUserName.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	else
	{
		if (checkEmailValid(e)!="0")
		{
			alert(checkEmailValid(e,''));
			return false;	
		} 
	}
	if(document.frmData.strPassword.value=="")
	{
		alert("Please enter your password!");
		return false;
	}
	return true;
}
function checkForgotpwd()
{
	var e=document.frmData.strEmail.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	else
	{
		if (checkEmailValid(e)!="0")
		{
			alert(checkEmailValid(e,''));
			return false;	
		} 
	}
	return true;
}

function checkQuantity()
{
	if(document.frmData.strQuantity.value=="0")
	{
		alert("Please select a quantity!");
		return false;
	}
	return true;
}





function checkContactUs()
{
	if (document.frmData.strContactName.value=="" || document.frmData.strContactName.value==" " || document.frmData.strContactName.value=="-" || document.frmData.strContactName.value=="_" || document.frmData.strContactName.value==".")
	{
		alert("Please enter your name!");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	if (checkEmailValid(e)!="0") 
	{
		alert(checkEmailValid(e,''));
		return false;	
	}
	if (document.frmData.strMessage.value=="" || document.frmData.strMessage.value==" " || document.frmData.strMessage.value=="-" || document.frmData.strMessage.value=="_" || document.frmData.strMessage.value==".")
	{
		alert("Please enter your message!");
		return false;
	}	
	return true;
}


function checkNewsletter()
{
	if (document.frmData.strContactName.value=="" || document.frmData.strContactName.value==" " || document.frmData.strContactName.value=="-" || document.frmData.strContactName.value=="_" || document.frmData.strContactName.value==".")
	{
		alert("Please enter your name!");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	if (checkEmailValid(e)!="0") 
	{
		alert(checkEmailValid(e,''));
		return false;	
	}
	return true;
}

function checkOurProperty()
{
	var wkey=document.frmData.strFullName.value;
	if (wkey=="" || wkey==" " || wkey=="-" || wkey=="_" || wkey==".")
	{
		alert("Please enter your Full Name!");
		return false;
	}
	var wkey=document.frmData.strNumber.value;
	if (wkey=="" || wkey==" " || wkey=="-" || wkey=="_" || wkey==".")
	{
		alert("Please enter your Contact Number!");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if(e=="" || e==" ")
	{
		alert("Please enter your email address!");
		return false;
	}
	if (checkEmailValid(e)!="0") 
	{
		alert(checkEmailValid(e,''));
		return false;	
	}
	if(document.frmData.chkAgree.checked==false )
	{
		alert("Please confirm your acceptance of our agent rates by clicking the agree box");
		return false;
	}
	return true;
}

function checkLink()
{
	var eng=document.frmData.strLinkTitle.value;
	if (eng=="" || eng==" " || eng=="-" || eng=="_" || eng==".") 
	{ 
		alert("Please enter the Link Title!");
		return false;
	}
	if(document.frmData.lngCategoryId.value=="0")
	{
		alert("Please select a Link Category!");
		return false;
	}
	var des=document.frmData.strDescription.value;
	if (des=="" || des==" " || des=="-" || url=="_" || des==".") 
	{ 
		alert("Please enter the Link URL!");
		return false;
	}
	if (document.frmData.strDescription.value.length > 512)
	{
		  alert("The maximum characters of the Description is 512!");
		  return false;
	}
	var url=document.frmData.strUrl.value;
	if (url=="" || url==" " || url=="-" || url=="_" || url==".") 
	{ 
		alert("Please enter the Link URL!");
		return false;
	}
	var use=document.frmData.strUsername.value;
	if (use=="" || use==" " || use=="-" || use=="_" || use==".") 
	{ 
		alert("Please enter the Username!");
		return false;
	}
	var e=document.frmData.strEmail.value;
	if (e=="" || e==" " || e=="-" || e=="_" || e==".") 
	{
		alert("Please enter your email address!");
		return false;
	}
	if (checkEmailValid(e)!="0") 
	{
		alert(checkEmailValid(e,''));
		return false;	
	}
	var bac=document.frmData.strBackUrl.value;
	if (bac=="" || bac==" " || bac=="-" || bac=="_" || bac==".") 
	{ 
		alert("Please enter the Link Back URL!");
		return false;
	}
	return true;	
}
