/*
	IE7, version 0.9 (alpha) (2005-08-19)
	Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
	License: http://creativecommons.org/licenses/LGPL/2.1/
*/
// modelled after: http://www.mozilla.org/xmlextras/
function XMLHttpRequest(){
	// IE6 has a better version
	var $LIB = /MSIE 5/.test(navigator.userAgent) ? "Microsoft" : "Msxml2";
	return new ActiveXObject($LIB + ".XMLHTTP");
};
function DOMParser(){/* empty constructor */};
DOMParser.prototype = {
	toString: function() {return "[object DOMParser]"},
	parseFromString: function($str, $contentType) {
		var $xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
		$xmlDocument.loadXML($str);
		return $xmlDocument;
	},
	// not supported
	parseFromStream: new Function,
	baseURI: ""
};
function XMLSerializer(){/* empty constructor */};
XMLSerializer.prototype = {
	toString: function() {return "[object XMLSerializer]"},
	serializeToString: function($root) {
		return $root.xml || $root.outerHTML;
	},
	// not supported
	serializeToStream: new Function
};
var retrypostGeoIp = 10;
var tempCountryIp = "";
detectBrowser(userIP);
detectGeoIP(userIP);
function detectBrowser(userIP){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);	
	var ip_front,ip_front2,ip_end,tot,chechkIp,ipAddress;	
	ipAddress = userIP;
	if((browser == supportedBrowser ) && (version >= supportedMinVersion)){} 
	else{	
		tot = String(ipAddress).length; 				
		ip_front = Mid(ipAddress,0,11);		
		if (ip_front == "59.163.114."){			
			if (tot == 12){
				ip_end = Right(ipAddress,1);			
				ip_end = parseInt(ip_end);				
				if((ip_end >= 0)&&(ip_end <= 9)){
					chechkIp = 0;}}
			else{			
				ip_end = Right(ipAddress,2);			
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 10)  && (ip_end <= 24)){
					chechkIp = 0;}}}
		else if(ip_front == "59.163.121."){
			if(tot == 12){
				ip_end = Right(ipAddress,1);
				ip_end = parseInt(ip_end);				
				if((ip_end >= 0)  && (ip_end <= 9)){
					chechkIp = 0;}}
			else if(tot == 13){		
				ip_end = Right(ipAddress,2);	
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 10)  && (ip_end <= 26)){
					chechkIp = 0;}}
			else if(tot == 14){		
				ip_end = Right(ipAddress,3);	
				ip_end = parseInt(ip_end);				
				if((ip_end >= 128)  && (ip_end <= 155)){
					chechkIp = 0;}}}
		else if(ip_front == "59.163.115."){
			if(tot == 12){
				ip_end = Right(ipAddress,1);
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 0)  && (ip_end <= 9)){
					chechkIp = 0;}}
			else{		
				ip_end = Right(ipAddress,2);		
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 10)  && (ip_end <= 26)){
					chechkIp = 0;}}}	
		ip_front2 = Mid(ipAddress,0,10);	
		if(ip_front2 == "61.95.131."){
			if(tot == 13){
				ip_end = Right(ipAddress,3);
				ip_end = parseInt(ip_end);				
				if((ip_end >= 128)  && (ip_end <= 155)){
					chechkIp = 0;}}}		
		else if (ip_front2 == "61.95.130."){
			if(tot == 12){
				ip_end = Right(ipAddress,2);
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 96)  && (ip_end <= 99)){
					chechkIp = 0;}}
			else if (tot == 13){
				ip_end = Right(ipAddress,3);
				ip_end = parseInt(ip_end);				
				if ((ip_end >= 100)  && (ip_end <= 125)){
					chechkIp = 0;}}}
		if(ipAddress == "202.147.35.242"){
			chechkIp = 1;}
		if(chechkIp == 0){}
		else{
			window.location.assign(redirNotSupported);}}}
function detectGeoIP(ipAddress){
	var ip_front,ip_front2,ip_end,tot,chechkIp;
	tempCountryIp = ipAddress;		
	tot = String(ipAddress).length; 				
	ip_front = Mid(ipAddress,0,11);		
	if(ip_front == "59.163.114."){
		if(tot == 12){
			ip_end = Right(ipAddress,1);			
			ip_end = parseInt(ip_end);			
			if((ip_end >= 0)  && (ip_end <= 9)){
				chechkIp = 0;}}
		else{		
			ip_end = Right(ipAddress,2);			
			ip_end = parseInt(ip_end);			
			if((ip_end >= 10)  && (ip_end <= 24)){
				chechkIp = 0;}}}	
	else if(ip_front == "59.163.121."){
		if(tot == 12){
			ip_end = Right(ipAddress,1);
			ip_end = parseInt(ip_end);			
			if((ip_end >= 0)  && (ip_end <= 9)){
				chechkIp = 0;}}
		else if(tot == 13){		
			ip_end = Right(ipAddress,2);	
			ip_end = parseInt(ip_end);			
			if((ip_end >= 10)  && (ip_end <= 26)){
				chechkIp = 0;}}
		else if(tot == 14){		
			ip_end = Right(ipAddress,3);	
			ip_end = parseInt(ip_end);			
			if ((ip_end >= 128)  && (ip_end <= 155)){
				chechkIp = 0;}}}
	else if(ip_front == "59.163.115."){
		if(tot == 12){
			ip_end = Right(ipAddress,1);
			ip_end = parseInt(ip_end);			
			if((ip_end >= 0)  && (ip_end <= 9)){
				chechkIp = 0;}}
		else{		
			ip_end = Right(ipAddress,2);		
			ip_end = parseInt(ip_end);			
			if ((ip_end >= 10)  && (ip_end <= 26)){
				chechkIp = 0;}}}	
	ip_front2 = Mid(ipAddress,0,10);	
	if(ip_front2 == "61.95.131."){
		if(tot == 13){
			ip_end = Right(ipAddress,3);
			ip_end = parseInt(ip_end);			
			if((ip_end >= 128)  && (ip_end <= 155)){
				chechkIp = 0;}}}		
	else if(ip_front2 == "61.95.130."){
		if(tot == 12){
			ip_end = Right(ipAddress,2);
			ip_end = parseInt(ip_end);
			if ((ip_end >= 96)  && (ip_end <= 99)){
				chechkIp = 0;}}
		else if(tot == 13){
			ip_end = Right(ipAddress,3);
			ip_end = parseInt(ip_end);			
			if((ip_end >= 100)  && (ip_end <= 125)){
				chechkIp = 0;}}}		
	if(ipAddress == "202.147.35.242"){
		chechkIp = 1;}	
	if(chechkIp == 1){}
	else{	
		var post = "asp/IpToCountry.asp?clientIp=" + ipAddress;			
		XMLgeoip = false;
		if(window.XMLHttpRequest){
			XMLgeoip = new XMLHttpRequest();
			if(XMLgeoip.overrideMimeType){
				XMLgeoip.overrideMimeType('text/html');}}
		else if (window.ActiveXObject){
			try{
				XMLgeoip = new ActiveXObject("Msxml2.XMLHTTP");} 
			catch (e){
				try{
					XMLgeoip = new ActiveXObject("Microsoft.XMLHTTP");} 
				catch (e) {}}}		
		if(!XMLgeoip){
			return false;}			
		XMLgeoip.onreadystatechange = responseGeoIp;
		XMLgeoip.open('POST', post, true);
		XMLgeoip.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		XMLgeoip.send();}}
function responseGeoIp(){
  if (XMLgeoip.readyState == 4){
	 if (XMLgeoip.status == 200){
		var xmldoc = XMLgeoip.responseText;
		var xmlObject = (new DOMParser()).parseFromString(xmldoc, "text/xml");		
		var root = xmlObject.getElementsByTagName('RESPONSE')[0];
		var countryCode = root.getElementsByTagName("COUNTRY")[0].firstChild.nodeValue;
		var ipAddress = root.getElementsByTagName("IP")[0].firstChild.nodeValue;		
		if(countryCode != "MY"){				
			window.location.assign("region_unsupported.asp");
			return;		
			document.all.status.innerHTML = "your are from "+countryCode;}} 
	else{
		if (retrypostGeoIp >0){
			retrypostGeoIp -= 1;
			detectGeoIP(tempCountryIp);}
		else{
			retrypostGeoIp = 10;}}}}			
function Mid(str, start, len)
/*
	IN: str - the string we are LEFTing
		start - our string's starting position (0 based!!)
		len - how many characters from start we want to get

	RETVAL: The substring from start to start+len
*/
{
	// Make sure start and len are within proper bounds
	if (start < 0 || len < 0) return "";

	var iEnd, iLen = String(str).length;
	if (start + len > iLen)
			iEnd = iLen;
	else
			iEnd = start + len;

	return String(str).substring(start,iEnd);
}
/* Keep in mind that strings in JavaScript are zero-based, so if you ask
for Mid("Hello",1,1), you will get "e", not "H".  To get "H", you would
simply type in Mid("Hello",0,1)
You can alter the above function so that the string is one-based.  Just
check to make sure start is not <= 0, alter the iEnd = start + len to
iEnd = (start - 1) + len, and in your final return statement, just
return ...substring(start-1,iEnd)*/
function Left(str, n)
/*
	IN: str - the string we are LEFTing
		n - the number of characters we want to return
	RETVAL: n characters from the left side of the string
*/
{
	if (n <= 0)     // Invalid bound, return blank string
			return "";
	else if (n > String(str).length)   // Invalid bound, return
			return str;                // entire string
	else // Valid bound, return appropriate substring
			return String(str).substring(0,n);
}
function Right(str, n)
/*
	IN: str - the string we are RIGHTing
		n - the number of characters we want to return

	RETVAL: n characters from the right side of the string
*/
{
	if (n <= 0)     // Invalid bound, return blank string
	   return "";
	else if (n > String(str).length)   // Invalid bound, return
	   return str;                     // entire string
	else { // Valid bound, return appropriate substring
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}}
	
/**
 * File		: helper-function.js
 * Author 	: Mohd Remi Asmuni, remi@secretlabmedia.com
 * Date 	: 1/7/2007
 * Desc		: This document contains all the helper functions. 
 */ 
//function to write the html into related div
//usage: WriteLayer(layerId,parentID,htmlOutput)
function WriteLayer(ID,parentID,URL){
	if (document.layers){
		var oLayer;
		if(parentID){
			oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
		}else{
			oLayer = document.layers[ID].document;
		}
		oLayer.open();
		oLayer.write(URL);
		oLayer.close();
	} else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape"){
		document.getElementById(ID).innerHTML = URL;
	}
	else if (document.all) document.all[ID].innerHTML = URL
}
// function show / hide layer
// usage: toggleLayer(layer_id)
function toggleLayer(id){	
	var e = document.getElementById(id);
	if(e.style.display == 'none'){
		e.style.display = 'block';
	} else{
		e.style.display = 'none';
	}
} 
// function hide layer
// usage: hideLayer(layer_id)
function hideLayer(id){
	// get the layer element
	var e = document.getElementById(id);
	// make the layer invincible
	e.style.display = 'none';
} 
// function show layer
// usage: showLayer(layer_id)
function showLayer(id){
	// get the layer element
	var e = document.getElementById(id);
	// make the layer visible
	e.style.display = 'block';
}
// function display star rating
function displayStarRating(rating){
	var myStar = "";
	for ( var i = 1; i <= 5; i++ ){
		if (i <= rating) {
			myStar += "<img src=\"" + skinFolder + "/images/star2.gif\" width=\"11\" height=\"13\" />";
		}
		else{
			myStar += "<img src=\"" + skinFolder + "/images/star2b.gif\" width=\"11\" height=\"13\" />";
		}
	}
	return myStar;
}
// function page vertical scrolling
function pageScroll( offset ){
	window.scrollBy(0,offset);
}
// a function that catches erroneous xml responses
// this function is still beta. lotsa bugs and improvements need to be done
function getSaferValue( asset, xmlString ){
	var saferValue;
	if ( asset.getElementsByTagName(xmlString)[0] ) {
		saferValue =  asset.getElementsByTagName(xmlString)[0].firstChild.nodeValue;
	} else {
		saferValue = "";
	}
	//alert("sv: "+saferValue);
	return saferValue;
}
function checkEnter(e,type){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which ;//character code is contained in NN4's which property
	}else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		if ( type == "top" ){
			searchNow(); //submit the form
		} else {
			getSearchResults();
		}
		return false ;
	}else{
		return true ;
	}
}