
function registerLog(logURL){
	var r		= parseInt(Math.random() * 1000);
	var oLogImg = new Image();
//	oLogImg.src = "/images/" + ad_qrystr + "&r="+r;
	oLogImg.src = logURL + "&r="+r;

}

function resizeSetting(){
	var h1	= document.getElementById("showAllRelated");
	var h2	= document.getElementById("showAllBrands");
	var h3	= document.getElementById("showAllLocation");
	var ww	= document.body.clientWidth;
	var wh	= document.body.clientHeight;
	var rm	= 15;
	var bm  = 10;
	if(h1)	h1.style.left 	= (ww - 710 - rm > 0) ? (ww - 710 - rm)+"px" : "0px";
	if(h2)	h2.style.left 	= (ww - 710 - rm > 0) ? (ww - 710 - rm)+"px" : "0px";
	if(h3)	h3.style.left 	= (ww - 710 - rm > 0) ? (ww - 710 - rm)+"px" : "0px";
	
	document.getElementById("frame2").style.left=document.getElementById("key").offsetLeft + "px";
}

function init(){
	var oShowAllRelated = document.getElementById("showAllRelated");
	if(oShowAllRelated) oShowAllRelated.style.display = "none";

	var oShowAllBrands = document.getElementById("showAllBrands");
	if(oShowAllBrands) oShowAllBrands.style.display = "none";

	var oShowAllLoc = document.getElementById("showAllLocation");
	if(oShowAllLoc) oShowAllLoc.style.display = "none";

	resizeSetting();
}


function showRelatedInfo(sShowAll){
	var oShowAll 		= document.getElementById(sShowAll);
	var sDisplay		= oShowAll.style.display;
	var posY		= parseInt(oShowAll.style.top);

	var objMovBanner = document.getElementById("movieBanner");

	if (sDisplay == "none"){
		oShowAll.style.display = "";
		if (objMovBanner.childNodes[0]){
			oShowAll.style.top = posY + 170;
			
		}
	} else {
		oShowAll.style.display = "none";
		if (objMovBanner.childNodes[0]){
			oShowAll.style.top = posY - 170;
		}
	}
}

function resizePageHeight(h){
	var oImg = document.getElementById("imgHeight");
	oImg.height=h;
}

function populateRelatedInfo(oRelated, oShowAll, oList){
//	var oContainer		= document.getElementById("container");

	var o			= document.getElementById(oRelated);
	var oShowAll 		= document.getElementById(oShowAll);
	var oShowAllList	= document.getElementById(oList);
	var s 			= "";
	if(!o) { 
		return false; 
	}
	var oLI		= o.getElementsByTagName("LI");
	var arrLI	= new Array();
	var i		= 0;	

	var nLI		= 0;
	for(i = 0; i < oLI.length; i++) {
		if(oLI[i].innerHTML != "" && oLI[i].innerHTML.indexOf("javascript:showRelated")<0) {
			arrLI[i] = oLI[i].innerHTML;
			nLI++;
		}
	}
	arrLI 		= arrLI.sort();

	var nCo		= Math.ceil(nLI / 3);


	for(i = 0; i < nCo; i++){
		s = s + "<li>" + arrLI[i] + "</li>";
	}
	co1 = "<div><UL>" + s + "</UL></div>";

	s = "";
	for(i = nCo; i < 2*nCo; i++){
		s = s + "<li>" + arrLI[i] + "</li>";
	}
	co2 = "<div><UL>" + s + "</UL></div>";
	
	s = ""
	for(i = nCo*2; i < nLI; i++){
		s = s + "<li>" + arrLI[i] + "</li>";
	}
	co3 = "<div><UL>" + s + "</UL></div>";

	oShowAllList.innerHTML	= co1 + co2 + co3;

	oShowAll.style.display = "none";

}

function getLocalDate(){

	var month=new Array(12)

	month[0]="January"
	month[1]="February"
	month[2]="March"
	month[3]="April"
	month[4]="May"
	month[5]="June"
	month[6]="July"
	month[7]="August"
	month[8]="September"
	month[9]="October"
	month[10]="November"
	month[11]="December"

	var now = new Date();
	var dateStr = (now.getDate() + " " + month[now.getMonth()] + " " + now.getFullYear());
	
	return(dateStr);
}

function setAction1(){
	
	var cty = document.searchForm.ctyCode.options[document.searchForm.ctyCode.selectedIndex].value;

	switch (cty) {

		case "SG": document.searchForm.action = "http://beta.eguide.com.sg/msidxsSearchList.asp"; 
			break;

		case "MY": document.searchForm.action = "http://beta.eguide.com.my/msidxsSearchList.asp"; 
			break;

		case "TH": document.searchForm.action = "http://beta.eguide.co.th/msidxsSearchList.asp"; 
			break;

		case "ID": document.searchForm.action = "http://beta.eguideindonesia.com.sg/msidxsSearchList.asp"; 
			break;

		case "VN": document.searchForm.action = "http://beta.eguidevietnam.com.sg/msidxsSearchList.asp"; 
			break;

		case "ASIA": document.searchForm.action = "http://beta.eguideglobal.com/msidxsSearchList.asp"; 
			break;

		default: document.searchForm.action = "http://localhost/msidxsSearchList.asp"; 

	}

}
var kCode;
var ctryCode;

var http_request = false;
var c = 1;

function validateSearch(objForm)
{
	var searchTypeSelected = false;
	var keyword = objForm.key.value;
	if (trimStr(keyword) == "Enter Search")
	{
		alert ("Please enter search term to continue.");
		return false;
		
	}
	else if (trimStr(keyword) == "" || keyword.length < 2)
	{
		alert ("Please enter at least 2 characters to search.");
		return false;
	}
	return true;
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
   	Char = sText.charAt(i); 
      	if (ValidChars.indexOf(Char) == -1) 
        {
        	IsNumber = false;
        }
   }
   return IsNumber;
   
}
function addBookmarkForBrowser() {
	if(document.all){
		window.external.AddFavorite(document.location.href, document.title);
	}else{
		window.sidebar.addPanel(document.title, document.location.href,"");
	}
}
function makeHomepg(obj,homepageURL)
{
	obj.style.behavior='url(#default#homepage)';
	obj.setHomePage(homepageURL);
	return false;
}
function trimStr(sStr){
	var retStr   = "" ;
	var lLoop = true;
	var first = -1;
	var last  = sStr.length;
	for(var i=0; i < sStr.length && lLoop; i++){
		if(sStr.charAt(i) != " ") lLoop = false;
		else	first = i;
	}
	lLoop = true;
	for(var i=sStr.length-1; i>= 0 && lLoop; i--){
		if(sStr.charAt(i) != " ") lLoop = false;
		else	last = i;
	}
	for(var i=first+1; i<last; i++)
		retStr += sStr.charAt(i);
	return (retStr);
}

function checkEnquiry(objForm)
{
	var returnVal = true;
	var reg = new RegExp();
	reg.compile("[A-Za-z0-9._-]+@[^.]+\..+"); 
	with (objForm)
	{
		if (trimStr(enquiry.value) == "" || trimStr(name.value) == "" || trimStr(email.value) == "" || trimStr(phone.value) == "")
		{
			alert ("Please make sure that all those fields marked with * must be supplied.");
			returnVal = false;
		}
		else if (!reg.test(email.value))
		{
			alert ("Please enter a valid email address.");
			returnVal = false;
		}
		else if (!IsNumeric(phone.value) || !IsNumeric(postal.value) || !IsNumeric(fax.value))
		{
			alert ("Please make sure that the postal code, tel and fax must be in numeric values.");
			returnVal = false;
		}	
					
	}
	return returnVal;
}
function validateFields(objForm){
	var returnVal	= true;
	var objFunc	= validateFields;
	with (objForm){
		for(i=1; i < objFunc.arguments.length; i++){
			var fldname	= objFunc.arguments[i];
			var fldvalue	= trimStr(objForm.elements[fldname].value);
			if(fldvalue.length == 0){
				i 		= objFunc.arguments.length;
				returnVal	= false;
				alert("Please fill in all the fields provided, thank you.")
			}
		}
			
	}

	return returnVal;
}

function showMore(objMore, objLink){
	
	var txtLink = (document.all) ? trimStr(objLink.innerText) : trimStr(objLink.textContent);
	if(txtLink == "Show All"){
		objMore.style.display 	= "";
		if(document.all) 	objLink.innerText	= "Hide";
		else			objLink.textContent	= "Hide";
	}else{
		objMore.style.display 	= "none";
		if(document.all) 	objLink.innerText	= "Show All";
		else			objLink.textContent	= "Show All";
	}
}

function enlargeLook(path)
{
	window.open('enlargeLook.asp?p='+path,'largeimage','menubar=no,scrollbars=yes,width=450,height=450,resizable=no');

}
function changeLocationBrand(changeType)
{
	if (changeType == "brand" && document.getElementById("location_id"))
	{
		document.relatedLocationBrandFrm.location_id.value = "";
	}
	document.relatedLocationBrandFrm.submit();
}
function changeStateBrand(changeType)
{
	if (changeType == "brand" && document.getElementById("state_no"))
	{
		document.relatedLocationBrandFrm.state_no.value = "";
		if (document.getElementById("substate_no"))
			document.relatedLocationBrandFrm.substate_no.value = "";
	}
	if (changeType == "state" && document.getElementById("substate_no")) 
		document.relatedLocationBrandFrm.substate_no.value = "";

	document.relatedLocationBrandFrm.submit();
}


// following function added 16 Nov 09 
function otherJFunc(curr_key){
	$('.googletitle').click(function() {
		flagAds(curr_key);
	});

	$('.googleurl').click(function() {
		flagAds(curr_key);
	});

	$('#GA_Narrow1 .googletitle').click(function() {
		flagAds(curr_key);
	});

	$('#GA_Narrow1 .googleurl').click(function() {
		flagAds(curr_key);
	});

}

function flagAds(curr_key){
	$.get("/flagAds.asp?q=" + escape(curr_key));
	$.post("/flagAds.asp?q=" + escape(curr_key));
}
