// JavaScript Document

//String function to strip off all white spaces before and after the actual string.
String.prototype.trim = function () 
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


//Navigation Bar functions.
function nav_MouseOut(sImgId, sImgPathName)
{
  //var elmImg = "nav" + sName + "Img";  
  document.getElementById(sImgId).src = sImgPathName;
  //document.navMainImg.src = "images/navMain.gif"; 
}
function nav_MouseOver(sImgId, sImgPathName) 
{
  //var elmImg = "nav" + sName + "Img";  
  document.getElementById(sImgId).src = sImgPathName;
  //document.navMainImg.src = "images/navMain_mo.gif";
}


//Get the absolute coordinate of an element. sSide: "Left" (x) or "Top" (y).
function getAbsPos(element, sSide)
{
	var position = 0;
	while (element != null) 
	{
		position += element["offset" + sSide];
		element = element.offsetParent;
	}
    
	return position;
}
		
//Function to get the coordinates of an element.
function getElementCoord(sElmId, sCoordToGet)
{
	//return document.getElementById(sElmId).innerHTML;
	//return getAbsPos(document.getElementById(sElmId), "Top");
	
	if (sCoordToGet == "ycoord")
		//return document.getElementById(sElmId).style.top;
		return getAbsPos(document.getElementById(sElmId), "Top");
	else if (sCoordToGet == "xcoord")
		//return document.getElementById(sElmId).style.left;
		return getAbsPos(document.getElementById(sElmId), "Left");
	else if (sCoordToGet == "allcoord")
	{
		var tempCoord = new Array(2);
		//tempCoord[0] = document.getElementById(sElmId).style.left;	//Store x coord.
		//tempCoord[1] = document.getElementById(sElmId).style.top;	//Store y coord.
		tempCoord[0] = getAbsPos(document.getElementById(sElmId), "Left");	//Store x coord.
		tempCoord[1] = getAbsPos(document.getElementById(sElmId), "Top");	//Store y coord.
		return tempCoord;
	}
}

//Jump/scroll to the position of the indicated element.
function jumpToSection(sElmId)
{
	var ydest = getElementCoord(sElmId, "ycoord");
	//document.write('in function.. <br />' + ydest);
	window.scrollTo(0, ydest); 
	//return false;
}


//Set selected product value and highlight the selected product.
function setSelection(obj, sVal)
{
	var allPdt = document.getElementsByName("pdt");	
	
	//Remove highlights from all products.
	for(var i=0; i<allPdt.length; i++)
		allPdt[i].style.borderColor = "white";
	
	//Set the border of the clicked product.
	obj.style.borderColor = "pink";
	
	//Assign the selected product.
	var e = document.getElementById("gpcolor");
	e.value =  sVal;
	
	//alert(e.value);
}


//Check if input is a valid email address.
function checkemailaddr(sInput)
{
	//Check that there's @.
	//Check that @ is not first char.
	//Check that there are at least 1 "." after @.
	//Check that the "." after @, there is at least 2 char after it.
	
	var tmpStr = sInput.trim();	//Strip all whitespaces before and after the input string.
	
	if (tmpStr == "")
	{
		window.alert("Please enter an email address before submiting.");
		return false;
	}
	
	if ( (tmpStr.indexOf ( '@', 0 ) == -1) ||	//Check for @ sign.
		 (tmpStr.indexOf ( '@', 0 ) < 1) ||		//Check that there is at least 1 letter before @.
		 (tmpStr.indexOf ( '.', 0 ) == -1) )	//Check for period (.) char.
	{
		window.alert("Invalid email. Please enter again.");
		return false;
	}
	
	//document.write(tmpStr);
	
	return true;	//Return true if there is no fault.
}


//Check if input is a valid email address.
function checkemailandmsg(sIpEmail, sIpMsg)
{
	//If invalid email address, return false.
	if (!checkemailaddr(sIpEmail))
	{
		return false;
	}	
	
	var tmpStr = sIpMsg.trim();	//Strip all whitespaces before and after the input string.
	
	if (tmpStr == "")
	{
		window.alert("Please enter a message before submiting.");
		return false;
	}
	
	return true;	//Return true if there is no fault.
}



function f_ie4() {
	var nav = navigator.appVersion.indexOf("MSIE");
	return (nav>0) && (parseInt(navigator.appVersion.substring(nav+5, nav+6)) >= 4);
}

function f_ns6() {
	return ((navigator.appName == "Netscape") &&
				(parseInt(navigator.appVersion.substring(0, 1)) >= 5))
}


//Display Flash animation.
function f_ShowFlash(sCell, sFlash, sID, sAlign, sWidth, sHeight, sBgColor, sScale, sWmode, sFlashVars)
{			
	if(f_ie4())
	{			
        var el = document.all[sCell];		
		if (el) 
		{
			
			var temp = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' align='";
			temp += sAlign;
			temp += "' width='";
			temp += sWidth;
			temp += "' height='";
			temp += sHeight;
			temp += "' id='";
			temp += sID;
			temp += "' >";
			temp += "<param name='allowScriptAccess' value='sameDomain' />";
            temp += "<param name='quality' value='high' />";
            temp += "<param name='movie' value='";
			temp += sFlash;
			temp += "'>";
			temp += "<param name='bgcolor' value='";
			temp += sBgColor;
			temp += "' />";
			temp += "<param name='scale' value='";
			temp += sScale;
			temp += "' />";
			
			temp += "<param name='wmode' value='";
			temp += sWmode;
			temp += "' />";	
						
			temp += "<param name='FlashVars' value='";
			temp += sFlashVars;
			temp += "' />";		
			temp += "<embed allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high' align='";
			temp += sAlign;
			temp += "' src='";
			temp += sFlash;
			temp += "' bgcolor='";
			temp += sBgColor;
			temp += "' width='";
			temp += sWidth;
			temp += "' height='";
			temp += sHeight;
			temp += "' scale='";
			temp += sScale;	
			
			temp += "' wmode='";
			temp += sWmode;		
			
			temp += "' FlashVars='";
			temp += sFlashVars;					
			temp += "' name='";
			temp += sID;
			temp += "'> </embed> </object>";
				
			el.innerHTML = temp;
		}
	}
	else
	{
		var e = document.getElementById(sCell);
		if (e) 
		{
			var temp = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' ";
			temp = temp + "align='" + sAlign + "' ";
			temp = temp + "width='" + sWidth + "' ";
			temp = temp + "height='" + sHeight + "' ";
			temp = temp + "id='" + sID + "' >";
			temp = temp + "<param name='allowScriptAccess' value='sameDomain' />";
            temp = temp + "<param name='quality' value='high' />";
            temp = temp + "<param name='movie' value='" + sFlash + "'/>";
			temp = temp + "<param name='bgcolor' value='" + sBgColor + "' />";
			temp = temp + "<param name='scale' value='" + sScale + "' />";
			
			temp = temp + "<param name='wmode' value='" + sWmode + "' />";
			
			temp = temp + "<param name='FlashVars' value='" + sFlashVars + "' />";			
			temp = temp + "<embed allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' quality='high' ";
			temp = temp + "align='" + sAlign + " '";
			temp = temp + "src='" + sFlash + "' ";
			temp = temp + "bgcolor='" + sBgColor + "' ";
			temp = temp + "width='" + sWidth + "' ";
			temp = temp + "height='" + sHeight + "' ";
			temp = temp + "scale='" + sScale + "' ";
			
			temp = temp + "wmode='" + sWmode + "' ";
			
			temp = temp + "FlashVars='" + sFlashVars + "' ";
			temp = temp + "name='" + sID + "'> </embed> </object> ";
		
			e.innerHTML = temp;
		}	
	}
}


//To delete. Test function.
function testjs()
{
	document.write("can you see this?");
	var str = document.location.pathname;
	document.write(str);
}

