///////////////////////////////////////////////////////////
//
//  common.js
//  JavaScript Functions
//  Original author: Sridhar Ganji
//  
///////////////////////////////////////////////////////////
//  Modification history:
//  
//
///////////////////////////////////////////////////////////

//for home page image load
var vLogo;
vLogo = "images/kres_home.gif";

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

if (browserName == "Netscape" && browserVer >= 3 || browserName == "Microsoft Internet Explorer" && browserVer >= 4)  
	version = "n3";
else 
	version = "n2";

if (version == "n3") 
{
	//These are the active images on the side next to the border
	cartOn = new Image(32,  197);
	//cartOn.src = "/images/icon_cart_red.gif";
	cartOn.src = "images/icon_cart3.gif";

	//These are the inactive images on the top menu bar
	cartOff = new Image(42,  197);
	cartOff.src = "images/icon_cart3.gif";
}
	
function img_act(imgName) 
{
	if (version == "n3") 
	{
		imgOn = eval(imgName + "On.src");
		document[imgName].src = imgOn;
	}
}

function img_inact(imgName) 
{
	if (version == "n3") 
	{
		imgOff = eval(imgName + "Off.src");
		document[imgName].src = imgOff;
	}
}

//to disallow the text box as form submit
function PreventEnter()
{
	return !(window.event && window.event.keyCode == 13);
}

//set the focus on the form element -- login request
function SetFocus()
{
	if (document.frmLoginRequest.txtEmail)
		document.frmLoginRequest.txtEmail.focus();
	else if (document.frmLoginRequest.txtEmail1)
		document.frmLoginRequest.txtEmail1.focus();
}

//re-direct to a specific page
function RedirectToPage(vPage)
{
	switch(vPage)
	{
		case "Registration":
			window.location.href = 'registration.aspx?showblanks=true';	
			break;	
		case "Search":
			window.location.href = 'search_results.aspx?search=' + document.all("txtSearch").value;
			break;
		case "License":
			window.location.href = 'license_information.aspx';
			break;

	}
}

//generic methods to load a popup window
function LoadPopup(vUrl)
{	
	//alert(vUrl);
	window.open(vUrl, 'popup', 'menubar=no,toolbar=no,scrollbars=yes,width=650,height=550');
}

//ASP.NET custom validation for bookstores page
function ValidateBookStore(oSrc, args)
{
	//alert(document.all("ddlCategory").value);
	//alert(document.all("ddlCareerStage").value);
	//alert(document.all("ddlMediaType").value);
	if ((document.all("ddlCategory").value == "-2147483648") || (document.all("ddlCareerStage").value == "-2147483648") || (document.all("ddlMediaType").value == "-2147483648"))
	{
		alert('Please select a Professional Category, Carrer Stage, Media Type and click "Go" to search for products.');
		args.IsValid = false;
	}
	else
		args.IsValid = true;
}

//ASP.NET custom validation for email updates
function ValidateEmailUpdate(oSrc, args)
{
	/*
	alert(document.all("ctlEmailUpdates_txtEmailAddress").value);
	alert(document.all("ctlEmailUpdates_ddlSpecialEvents").value);
	args.IsValid = false;
	*/
	if ((document.all("ctlEmailUpdates_txtEmailAddress").value == "") || (document.all("ctlEmailUpdates_ddlState").value == "") || (document.all("ctlEmailUpdates_ddlSpecialEvents").value == ""))
	{
		alert('Please select a special interest area, state and enter email address and click "Go" to get email updates.');
		args.IsValid = false;
	}
	else
		args.IsValid = true;
}

//ASP.NET custom validation for search results page
function ValidateSearchCriteria(oSrc, args)
{
	/*
	alert(document.all("ddlCategory").value);
	alert(document.all("ddlFamily").value);
	alert(document.all("ddlState").value);
	args.IsValid = false;
	*/
	if ((document.all("ddlCategory").value == "-2147483648") || (document.all("ddlFamily").value == "-2147483648") || (document.all("ddlState").value == "-2147483648"))
	{
		alert('Please select a Professional Category, State and Career Stage and click "Go" to search for products.');
		args.IsValid = false;
	}
	else
		args.IsValid = true;
}

function SetBillTo()
{
	// set default
	document.getElementById("ctlCheckout_ddlBilling_State_Province").selectedIndex = 0;
   	
   				
   	// View source to see auto-generated names used below; Make sure consistent among different version of .Net Framework
   	// Use getElementById because auto-added "name" attribute contains a ":", which freaks out Javascript
   	//if (document.getElementById("setBillTo").getAttribute("checked"))
   	if (document.getElementById("chkSetBillingAddress").checked) // (getAttribute doesn't work for checked property in NS)
   	{
   		document.getElementById("ctlCheckout_txtBilling_First_Name").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_First_Name").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Last_Name").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Last_Name").getAttribute("value"));
   		//document.getElementById("billing_companyName").setAttribute("value",document.getElementById("shipping_companyName").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Address1").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Address1").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Address2").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Address2").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_City").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_City").getAttribute("value"));
   		//document.getElementById("billing_state").setAttribute("value",document.getElementById("shipping_state").getAttribute("value"));
   		//document.getElementById("billing_state").setAttribute("selectedIndex",document.getElementById("shipping_state").getAttribute("selectedIndex"));
   		document.getElementById("ctlCheckout_ddlBilling_State_Province").selectedIndex = document.getElementById("ctlCheckout_ddlShipping_State_Province").selectedIndex;
   		document.getElementById("ctlCheckout_txtBilling_Zip_Postal_Code").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Zip").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Country").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Country").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Email").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Email").getAttribute("value"));
   		document.getElementById("ctlCheckout_txtBilling_Daytime_Phone").setAttribute("value",document.getElementById("ctlCheckout_txtShipping_Daytime_Phone").getAttribute("value"));
   	}
   	else
   	{
   		document.getElementById("ctlCheckout_txtBilling_First_Name").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Last_Name").setAttribute("value","");
   		//document.getElementById("billing_companyName").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Address1").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Address2").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_City").setAttribute("value","");
   		//if (navigator.userAgent.indexOf("IE")>-1)
   		document.getElementById("ctlCheckout_ddlBilling_State_Province").selectedIndex = 0;
   		//document.getElementById("billing_state").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Zip_Postal_Code").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Country").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Email").setAttribute("value","");
   		document.getElementById("ctlCheckout_txtBilling_Daytime_Phone").setAttribute("value","");
   	}	
}
