/**
 *
 * Site scripts
 *
 */

 /* clear/restore text field  --------------------------------------- */

 	function clickclear(myField, defaultText) {

	myField.value = "";
}

function clickrecall(myField, defaultText) {

	myField.value = defaultText;

}



/* main nav ------------------------------------------------------- */

var divs = new Array();
var elementsToHide = new Array();
var elementToShow = "";

function init(){
   //get divs which show/hide
   divs = getElementsByClassName(document,"div","subNav");
}


function mouseOver(elementId,object,xoffset,yoffset){

	//Menu is disabled for Mac IE
   if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac"){
   		return;
   }

   if(!xoffset) xoffset = 0;
   if(!yoffset) yoffset = 0;

   if(BrowserDetect.browser == "Safari"){
   		if(xoffset) xoffset = -195;
   }

    if(BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Mac"){
   		if(xoffset) xoffset = -195;
   }
   
    // start new (WH): position rollover in ie8
	 if(BrowserDetect.browser == "Explorer"){
   			checkVersion()			
	 }
	 
	 function getInternetExplorerVersion()
				// Returns the version of Internet Explorer or a -1
				// (indicating the use of another browser).
				{
				  var rv = -1; // Return value assumes failure.
				  if (navigator.appName == 'Microsoft Internet Explorer')
				  {
					var ua = navigator.userAgent;
					var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
					if (re.exec(ua) != null)
					  rv = parseFloat( RegExp.$1 );
				  }
				  return rv;
				}
	 function checkVersion()
				{
					if(!yoffset) yoffset = 0;					
				 	var ver = getInternetExplorerVersion();
				
				  if ( ver > -1 )
				  {
					if ( ver >= 8.0 ) 
					  document.getElementById(subNav).style.display = 'none';
					}
				}
				//end new: position rollover for ie8


   //get position of the callee object
   var pos = findPos(object);
   //reference our object
   var targetingObject = document.getElementById(elementId);
   //show object
   elementToShow = elementId;
   showTimeOut = window.setTimeout('showObject()',50);
   //set position of the showed object
   targetingObject.style.left = pos[0]+xoffset+'px';
   targetingObject.style.top = pos[1]+yoffset+'px';

   //alert(targetingObject.style.left);

   //hide other divs
   for(i=0; i < divs.length; i++){
      if(divs[i] != targetingObject){
         divs[i].style.display = "none";
      }
   }
}

function showObject(){
   document.getElementById(elementToShow).style.display = "block";
}


function mouseOut(elementId){

	//Menu is disabled for Mac IE
   if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac"){
   		return;
   }


   elementsToHide.push(document.getElementById(elementId));
   hideTimeOut = window.setTimeout(hideObject,500);

   if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac"){
   		//document.getElementById(elementId).style.display = "none";
   }

}


function divMouseOver(element){
   for(i=0;i<elementsToHide.length;i++){
      if(elementsToHide[i] == element){
         elementsToHide[i] = "isShown"; //it would be nicer to remove this element form array...
         break;
      }
   }
}

function divMouseOut(element){
   elementsToHide.push(element);

   if(hideTimeOut) window.clearTimeout(hideTimeOut);
   hideTimeOut = window.setTimeout(hideObject,500);
}



function hideObject(){

   for ( i = elementsToHide.length-1; i>= 0; i--){
		if(elementsToHide[i]!="isShown"){
			elementsToHide[i].style.display = "none";
			         //alert("hide");

		}
   }
   elementsToHide = new Array();
}



//------------------------------------------------------------------------------
// FINDING OBJECT POSITION
//------------------------------------------------------------------------------
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}


/*
	Written by Jonathan Snook, http://www.snook.ca/jonathan
	Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}



//--------------------------------------------------------------
//  SHOW NAV 2
//--------------------------------------------------------------

function showSub2(id){
		document.getElementById(id).style.display = "block";
	}


function isValidEmail(emailAddress) {

   var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);



}


//--------------------------------------------------------------
//
//  Show product detail tabs and content
// - - - - - - - - - - - - - - - - - - - -  - - - - - - - - - - -


function showTab(tab)
{

var tab1 = document.getElementById('tab1');
var tab2 = document.getElementById('tab2');

if (document.getElementById('tab3')) {
	var tab3 = document.getElementById('tab3');
	var tab3_content = document.getElementById('tab3_content');
}


var tab1_content = document.getElementById('tab1_content');
var tab2_content = document.getElementById('tab2_content');


	if(tab == 'tab1')
	{
		tab2.style.backgroundPosition = '0 -27px';
		tab1.style.backgroundPosition = '0 0';
		tab2_content.style.display = 'none';
		tab1_content.style.display = 'block';

		if (document.getElementById('tab3')) {
			tab3_content.style.display = 'none';
			tab3.style.backgroundPosition = '0 -27px';
		}
	}
	if (tab == 'tab3')
	{
		if (document.getElementById('tab3')) {
			tab3_content.style.display = 'block';
			tab3.style.backgroundPosition = '0 0';
		}

		tab1.style.backgroundPosition = '0 -27px';
		tab2.style.backgroundPosition = '0 -27px';
		tab1_content.style.display = 'none';
		tab2_content.style.display = 'none';

	}
	if (tab == 'tab2')
	{
		tab1.style.backgroundPosition = '0 -27px';
		tab2.style.backgroundPosition = '0 0';
		tab2_content.style.display = 'block';
		tab1_content.style.display = 'none';
		if (document.getElementById('tab3')) {
			tab3.style.backgroundPosition = '0 -27px';
			tab3_content.style.display = 'none';
		}
	}

}

/* centered popup */

/*/
/ /  Author: Jeremy Falcon
/ /    Date: November 08, 2001
/ / Version: 1.4
/*/

/*/ THIS FILE CONTAINS FUNCTIONS THAT WILL WRAP THE POP-UP PROCESS /*/

// this variable will hold the window obect
// we only allow one pop-up at a time
var popup = null;

/*/
/ / PURPOSE:
/ /		To create and center a pop-up window.
/ /
/ / COMMENTS:
/ /		It will replace to old pop-up if called
/ / 	without calling DestroyWnd() first..
/*/

function CreateWnd (file, width, height, resize)
{
	var doCenter = false;

	if((popup == null) || popup.closed)
	{
		attribs = "";

		/*/ there's no popup displayed /*/

		// assemble some params
		if(resize) size = "yes"; else size = "no";

		/*/
		/ / We want to center the pop-up; however, to do this we need to know the
		/ / screen size.  The screen object is only available in JavaScript 1.2 and
		/ / later (w/o Java and/or CGI helping), so we must check for the existance
		/ / of it in the window object to determine if we can get the screen size.
		/ /
		/ / It is safe to assume the window object exists because it was implemented
		/ / in the very first version of JavaScript (that's 1.0).
		/*/
		for(var item in window)
			{ if(item == "screen") { doCenter = true; break; } }

		if(doCenter)
		{	/*/ center the window /*/

			// if the screen is smaller than the window, override the resize setting
			if(screen.width <= width || screen.height <= height) size = "yes";

			WndTop  = (screen.height - height) / 2;
			WndLeft = (screen.width  - width)  / 2;

			// collect the attributes
			attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," + 
			"status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
		}
		else
		{
			/*/
			/ / There is still one last thing we can do for JavaScrpt 1.1
			/ / users in Netscape.  Using the AWT in Java we can pull the
			/ / information we need, provided it is enabled.
			/*/
			if(navigator.appName=="Netscape" && navigator.javaEnabled())
			{	/*/ center the window /*/

				var toolkit = java.awt.Toolkit.getDefaultToolkit();
				var screen_size = toolkit.getScreenSize();

				// if the screen is smaller than the window, override the resize setting
				if(screen_size.width <= width || screen_size.height <= height) size = "yes";

				WndTop  = (screen_size.height - height) / 2;
				WndLeft = (screen_size.width  - width)  / 2;

				// collect the attributes
				attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," + 
				"status=no,toolbar=no,directories=no,menubar=no,location=no,top=" + WndTop + ",left=" + WndLeft;
			}
			else
			{	/*/ use the default window position /*/

				// override the resize setting
				size = "yes";

				// collect the attributes
				attribs = "width=" + width + ",height=" + height + ",resizable=" + size + ",scrollbars=" + size + "," + 
				"status=no,toolbar=no,directories=no,menubar=no,location=no";
			}
		}

		// create the window
		popup = open(file, "", attribs);
	}
	else
	{
		// destory the current window
		DestroyWnd();
		// recurse, just once, to display the new window
		CreateWnd(file, width, height, resize);
	}
}

/*/
/ / PURPOSE:
/ /		To destroy the pop-up window.
/ /
/ / COMMENTS:
/ /		This is available if wish to destroy
/ / 	the pop-up window manually.
/*/

function DestroyWnd ()
{
	// close the current window
	if(popup != null)
	{
		popup.close();
		popup = null;
	}
}


