var __oldDoPostBack;		// Used in the PostBack Override
var __oldFormOnSubmit;		// Used in the Form Override
var IsPostBack = false;		// Global Boolean

var lastExceptionLocation;	//used for debugging purposes
var lastException;			//used for debugging purposes


///////////////////////////////
//
//
//  CEL 17 March 2005
//
//		The APCI_DoPostBackOverRide is a function that is run on the Windows.Onload event to
//		override the standard Micrsoft function for DoPostBack and the Form OnSumbit function
//		DoPostBack calls on the page will call APCI_DoPostBack
//		The Form OnSumbit will call APCI_FormOnSubmit
//
//		Why: We would get errors when a user changed the page while waiting for the page reload
//
////////////////////////////////

	function APCI_DoPostBackOverRide(){
		//This function assumes the variable __oldDoPostBack exists	
		/*
		try{
			__oldDoPostBack = __doPostBack;
			__doPostBack = APCI_DoPostBack;	
			__oldFormOnSubmit = document.forms[0].onsubmit; 
			document.forms[0].onsubmit = APCI_FormOnSubmit;
		}catch(ex){			
			lastExceptionLocation = 'APCI_DoPostBack';
			lastException = ex;
		}
		*/
	}


	////
	//
	//	Maintain a global boolean IsPostBack and only submit the form 1 time
	//
	////
	
    function APCI_FormOnSubmit()
    {
     if (!IsPostBack){
		IsPostBack = true;
		__oldFormOnSubmit();
		}
		else
		return false;
	}

	////
	//
	//	Maintain a global boolean IsPostBack and only call DoPostBack - 1 time
	//
	////
	function APCI_DoPostBack(eventTarget, eventArgument){

		try{
			if (!IsPostBack) 
				{
					IsPostBack = true;
					__oldDoPostBack(eventTarget, eventArgument);	
				}
		}catch(ex){			
			lastExceptionLocation = 'runOnSubmitMethods';
			lastException = ex;
		} //end try-catch	
		
	}//end function 
	

function ViewProduct(strURL,lngProductCode,strRegion)
{
	var CompleteURL;
	var features = "menubar,toolbar,location,scrollbars,resizable,width=800,screenX=100,screenY=100,left=100,top=100";
	
	//build URL of product page
	CompleteURL = strURL + "controlled/product_description.asp?";
	CompleteURL += "intRegionalMarketSegment=0&pc=" + lngProductCode;
	
	//set region cookie
	document.cookie = 'reg=' + strRegion + '; expires=Sat, 1-Jan-2999 00:00:00 GMT;path=/;';
	
	//open page in new window
	window.open(CompleteURL, "", features);
}

//


function KeyDownHandler(e)
{
	if (!e) var e = window.event;
	var keyCode = (e.keyCode) ? e.keyCode : e.which;
	var element = (e.target) ? e.target : e.srcElement;
	
	// process only the Enter key
	if (keyCode == 13)
	{
	//  event.keyCode=0;
          if (document.getElementById('_searchButton'))
          {
          	document.getElementById('_searchButton').click();
	         return false;
          }
	}
}

if( document.captureEvents )
{
    //non IE
	if( Event.KEYDOWN )
	{
        //NS 4, NS 6+, Mozilla 0.9+
        document.captureEvents( Event.KEYDOWN );
    }
}
document.onkeydown = KeyDownHandler;

