/*--------------------------------------------------------------------------------------------------
browserDisposal
pass in 4 different values for each browser. If blank, it'll return $macFirefox as default
--------------------------------------------------------------------------------------------------*/
function browserDisposal(macFirefox,safari,ie,winFirefox) {
	 
	 // Get the mac and browser name from the hidden field. It's put there by the php version of this function
	 if(document.getElementById("browserDisposal_hidden")) {
	 	var browserAndOs = document.getElementById("browserDisposal_hidden").value; // Should be something like Mac:firefox
	 	
	 	// Split it to seperate the os and browser
	 	browserAndOs = browserAndOs.split(":");
	 	var os 		= browserAndOs[0];
	 	var browser = browserAndOs[1];

	 }
	 
	 if(browser == "firefox") {
	 	if(os == "Mac") {
	 		returnValue = macFirefox;
	 	}
	 	else {
	 		returnValue = winFirefox;
	 	}
	 }
	 else if(browser.indexOf("ie") >= 0) {
	 	returnValue = ie;
	 }
	  else if(browser.indexOf("ie") >= 0) {
	 	returnValue = ie;
	 }
	  else if(browser.indexOf("ie") >= 0) {
	 	returnValue = ie;
	 }
	 else {
	 	returnValue = macFirefox;
	 }
	 
	return returnValue;
}



/*-------------------------------------------------------------------------------------------------
Find position functions
-------------------------------------------------------------------------------------------------*/
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y) 
		curtop += obj.y;
	return curtop;
}






/*-------------------------------------------------------------------------------------------------
Check enter
-------------------------------------------------------------------------------------------------*/
function checkEnter(e,submitFunction){ 
// Put this in the last field of a form like this : <input type="text" onKeyPress="checkEnter(event,hey)"> 
// e is the event.. its passed in just as event... It looks like this : keyup charCode=0, keyCode=13
// submit function is the function we'll call, pass it in as a string! 
// if params are needed for the submitFunction they get passed in too - as many as are needed. we'll invoke arguments to fetch all of them. 

// example - function with no paramters :  onKeyPress='checkEnter(event,\"checkZip\")'
// example - function with paramaters :    onkeyup='checkEnter(event,\"changeQuantity\",$optionId,this.value,\"cartText\")'  optionId,this.value,cartText are the paramaters to changeQuantity



	 // Build our paramaters for the submitFunction (if there are any)	
	 var theseParams = "";
	
	 // Go through all the params after the first 2 (first two are e and submitFunction)
	 for (var i = 2; i < checkEnter.arguments.length; i++) {
     	theseParams += "'" + checkEnter.arguments[i] + "'";
     	
     	// If this is the last one, don't add the comma at the end
     	if(i != checkEnter.arguments.length - 1) {
     		theseParams += ",";
     	}
     }
     
   	
	try{ // If i don't use this try statement, it'll throw an error when tab is pushed
		var characterCode;
		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)
			
			// Run our submit function with any paramaters
			eval(submitFunction + '('+theseParams+')');
			return false; 
		}
		else{
			return true;
		}
	}
	catch(err) {
	
	}

} 



