	// JavaScript Document
	var $D = YAHOO.util.Dom; 

	function checkQty(formInput,fallBack){
		//gets called onBlur of quantity input element
		var qty = formInput.value;
		//qty = parseInt(qty);
		if(!isNaN(qty) && isFinite(qty) && qty>=0 && (f = qty%1) == 0){
			return true;
		} else {
			formInput.value = fallBack;
			formInput.focus();
			alert('Please Enter a valid number. (no letters,negative values, or decimal values)');
			return false;
		}
	}

	function enterPressed(e, base_index_url){
		var keynum;
		if(window.event){
			keynum = e.keyCode;
		}
		else if(e.which){
			keynum = e.which;
		}
	
		if(keynum == 13){
			doSearch(base_index_url);
			return false;
		}
		else{
			return true;
		}
	}
	
	function doSearch(base_index_url, keywords){
		/*var base_url = base_index_url;
		var search_value = document.search_form.searchField.value;
		if(search_value.replace(/^\s+|\s+$/g,"").replace(/^\s+/,"").length)
			searchInvalidChars(search_value) ? document.location = base_url + "/browse/search/part_num_and_description/" + search_value : function(){}()	;
		
		return false;*/
		return doAdvancedSearch(base_index_url,keywords);
	} 
	
	

	function doAdvancedSearch(base_index_url,keywords){
		var base_url = base_index_url;
		if(keywords!="") {
			var search_value = document.search_form.searchField.value;
		} else {
			var search_value = keywords;				
		}
		if(search_value.replace(/^\s+|\s+$/g,"").replace(/^\s+/,"").length)
			searchInvalidChars(search_value) ? document.location = base_url + "/advanced_search/search/split_search/1/require_all/1/part_num_and_description/" + search_value  : function(){}();
		return false;
	}

	
	function searchInvalidChars (searchString) {
	   var ic = new Array();//illegal_chars  array 
	   ic.push("@");
	   ic.push("#");
	   ic.push("%");
	   ic.push("*");
	   ic.push("^");
	   ic.push("(");
	   ic.push(")");   
	   ic.push("!");
	   ic.push("{");
	   ic.push("}");
	   ic.push("`");   
	   ic.push("/");
	   ic.push(">");
	   ic.push("<");
	   ic.push(";");
	   ic.push("`");   
	   ic.push(",");
	   ic.push("|");
	   var searchpattern = /(#|@|%|\^|\$|;|\/|\}|\{|\(|\)|`|~|,|\*|<|>|\|)+/;
	   if(searchString.search(searchpattern) != -1){	
	        alert("Your search keyword contains one or more of the following DISALLOWED characters : \n"+ ic.join("  "));
		return 0;
	   }
	   else return 1;
	}
	
	/*
	function checkQty(){
		var qty = $D.get('qty').value;
		qty = parseFloat(qty);
		if(!isNaN(qty) && qty > 0){
			$D.get('add_cart_qty').value = qty;
			$D.get('buy_now_qty').value = qty;
			return true;
		}
		else{
			$D.get('qty').value = 1;
			alert("Your quantity must be greater than 0");
			return false;
		}
	}
	*/

	/********************************************@Ishtiaque******************************************************************************/
	//Adds a matrix item into the users current favoutire list (session fav id)
	
	function addToFav(wh,pn){
		
		var reqUrl = base_index_url;
	
		function getPostParam(wh,pn){
			return "&add_part_num="+pn+"&add_warehouse_id="+wh+"&add_qty="+1+"&isAjax=1";			
		}
		function getCallbackObject(){
			var callback = {
				success:function(o){
					alert('Successfully added to your favourite list.');
				},
				failure:function(o){
				},
				timeout:5000
				
			}
			return callback;
		
		}
		YAHOO.util.Connect.asyncRequest('POST', reqUrl + "/manage_favourites/add_details" ,getCallbackObject(),getPostParam(wh,pn));
	}
	/***********************************************************************************************************************************/
	
//	initLightbox();
	function sameAsBilling(){
		if($D.get('same_as_billing').checked){
			//move all billing info to the shipping side and disable the shipping side
			$D.get('shipping_name').value = $D.get('billing_name').value;
			$D.get('shipping_name').disabled = true;
	
			$D.get('shipping_line_1').value = $D.get('billing_line_1').value;
			$D.get('shipping_line_1').disabled = true;
	
			$D.get('shipping_line_2').value = $D.get('billing_line_2').value;
			$D.get('shipping_line_2').disabled = true;
	
			$D.get('shipping_line_3').value = $D.get('billing_line_3').value;
			$D.get('shipping_line_3').disabled = true;
			
			$D.get('shipping_line_4').value = $D.get('billing_line_4').value;
			$D.get('shipping_line_4').disabled = true;
			
			$D.get('shipping_city').value = $D.get('billing_city').value;
			$D.get('shipping_city').disabled = true;
			
			$D.get('shipping_country').value = $D.get('billing_country').value;
			$D.get('shipping_country').disabled = true;
			
			$D.get('shipping_country_division').value = $D.get('billing_country_division').value;
			$D.get('shipping_country_division').disabled = true;
			
			$D.get('shipping_postal_code').value = $D.get('billing_postal_code').value;
			$D.get('shipping_postal_code').disabled = true;			
			
			$D.get('shipping_phone').value = $D.get('billing_phone').value;
			$D.get('shipping_phone').disabled = true;
			
			//$D.get('shipping_ext').value = $D.get('billing_ext').value;
			//$D.get('shipping_ext').disabled = true;
			
			$D.get('shipping_fax').value = $D.get('billing_fax').value;
			$D.get('shipping_fax').disabled = true;
			
			$D.get('shipping_email').value = $D.get('billing_email').value;
			$D.get('shipping_email').disabled = true;		
			
		}else{
			//enable all the shipping side
			$D.get('shipping_name').disabled = false;
			$D.get('shipping_line_1').disabled = false;
			$D.get('shipping_line_2').disabled = false;
			$D.get('shipping_line_3').disabled = false;
			$D.get('shipping_line_4').disabled = false;
			$D.get('shipping_city').disabled = false;
			$D.get('shipping_country_division').disabled = false;
			$D.get('shipping_postal_code').disabled = false;
			$D.get('shipping_country').disabled = false;
			$D.get('shipping_phone').disabled = false;
			//$D.get('shipping_ext').disabled = false;
			$D.get('shipping_fax').disabled = false;
			$D.get('shipping_email').disabled = false;
		}
	}
	
	function setBillingEmail(){
		$D.get('billing_email').value = $D.get('email').value;
	}
	function fieldOn(elem){
		orig = $D.getStyle(elem.name, 'backgroundColor'); 
		$D.setStyle(elem.name,'backgroundColor','#000');
	}
	function fieldOff(elem){
		$D.setStyle(elem.name,'backgroundColor',orig);
	}
	// JavaScript Document