// JavaScript Document
function GetObjectByID(ID) {
	// IE, FIrefox, opera
	if (document.getElementById) {
		// unfortunatly some browsers seem to think that a form element is not an element (firefox)
		if (document.getElementById(ID)==null) {
			if (navigator.appName == "Firefox")
				return eval("document." + ID);
			else
				return null;
		} else {
			return document.getElementById(ID);
		}

	//Netscape
	} else {

		return window[ID];
		
	} 
		
//}
}

function ImageSwap(img, sImgPath) { //v3.0
	iImgObject = GetObjectByID(img);
  	iImgObject.src=sImgPath;
}

function ToCurrency(expr) {
	var str = (Math.round(parseFloat(expr) * Math.pow(10,2))).toString();
 	while (str.length <= 2) {  
 		str = "0" + str;
 	}
 	var decpoint = str.length - 2;
 	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
 }

function AddToFavourites() {
	if (window.sidebar) {
		window.sidebar.addPanel(document.title,self.location,'');
	} else if (window.external) {
		window.external.AddFavorite(self.location,document.title);
	} else if (window.opera) {

	}
}

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function ValidateEmail(sEmailString) {
	var at="@";
	var dot=".";
	var lat=sEmailString.indexOf(at);
	var lsEmailString=sEmailString.length;
	var ldot=sEmailString.indexOf(dot);
	
	if (sEmailString.indexOf(at)==-1) {
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (sEmailString.indexOf(at)==-1 || sEmailString.indexOf(at)==0 || sEmailString.indexOf(at)==lsEmailString) {
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (sEmailString.indexOf(dot)==-1 || sEmailString.indexOf(dot)==0 || sEmailString.indexOf(dot)==lsEmailString) {
		alert("Invalid E-mail ID");
		return false;
	}

	 if (sEmailString.indexOf(at,(lat+1))!=-1) {
		alert("Invalid E-mail ID");
		return false;
	 }

	 if (sEmailString.substr(lat-1,lat)==dot || sEmailString.substr(lat+1,lat+2)==dot) {
		alert("Invalid E-mail ID");
		return false;
	 }

	 if (sEmailString.indexOf(dot,(lat+2))==-1) {
		alert("Invalid E-mail ID");
		return false;
	 }
	
	 if (sEmailString.indexOf(" ")!=-1) {
		alert("Invalid E-mail ID");
		return false;
	 }

	 return true;					
}

function checkText(oTxtBox) {
  if (oTxtBox.value == "find products") {
   alert('Sorry, you will have to type in a keyword first.');
   return false;
  } else {
   if (oTxtBox.value == "find products") {
     
     oTxtBox.value = "%"
   }
   return true;
  }
 }
 
function ShowHideLayer(LayerID, sShowHide) {
	var LayerObject = GetObjectByID(LayerID)
	
	if (LayerObject.style) 
		LayerObject.style.visibility = sShowHide;
	else
		LayerObject.visibility = sShowHide;
		
}

function CRePositionLayer(sLayerId, x, y, ObjName) {
	this.startX = x;
	this.startY = y;
	this.TargetLayer=GetObjectByID(sLayerId);	
	this.ObjName = ObjName;
	this.scrollTop = "";
		
	this.RePositionLayer=function() {
		this.TargetLayer.y += parseFloat((this.scrollTop.scrollTop + this.startY - this.TargetLayer.y)/8);
		if (x != "fix") this.TargetLayer.style.left = this.TargetLayer.x + 'px';
		if (y != "fix") this.TargetLayer.style.top = this.TargetLayer.y + 'px';
		setTimeout(this.ObjName + ".RePositionLayer()", 10);
	}
	
	if (navigator.appName == "Firefox" || navigator.appName == "Netscape" || navigator.appName == "Chrome") {
		this.scrollTop = document.body;
	} else {
		if((typeof(document.documentElement) == 'object' && typeof(document.documentElement.clientWidth) == 'number')) 
			this.scrollTop = document.documentElement;
		else
			this.scrollTop = document.body;
	}
	if(document.layers) this.TargetLayer.style=this.TargetLayer;
	this.TargetLayer.x = this.startX;
	this.TargetLayer.y = this.startY;	
	this.RePositionLayer();
}

function over(c) {
  c.style.backgroundColor='#FFCC00';
}

function out(c) {
  c.style.backgroundColor='#FFFFFF';
}
