/**
 *
 * 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';
		}
	}

}
