/* GLOBAL FUNCTIONS
/* ------------------------------------------------ */
// PageType and PageSubtype needed for Topseller ajax call. The start.jsp calls setPageDetails
var pageType = '/';
var pageSubtype = 'laptops';

function setPageDetails(type,subtype) {

	pageType = type;
	pageSubtype = subtype;

}

function setTopNavSelection(id) {
	document.getElementById(id).className= "selected";
}

function getTopSellers(divElement) {
	new ajax().update("/showcase/explore/jsp/catalog/topsellersAjax.jsp",
			   divElement,
			   {
			       onLoading : function() { getElementById(divElement).innerHTML = "<img src='/images/assets/ajax_loader.gif' alt='Retrieving Topsellers..'/><b>Retrieving Topsellers..</b><br/>" },
			       onError   : function(request) { if(request.instance.status == 404) { getElementById(divElement).innerHTML = "<!-- Page not found -->"; } },
			       parameters: {type:pageType,subtype:pageSubtype}
			   }
			 );
}

function getProjectorModels(divElement,series) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/projectorsAjax.jsp",
		{series:series}
	);

}

function getRelatedModels(divElement,subBrand) {
	/*
	new ajax().update(pageContext + "/catalog/seriesAjax.jsp",
			   divElement,
			   {
			       parameters: {pageSubBrand:subBrand}
			   }
			 );
	*/
	jQuery("#" + divElement).load(
		pageContext + "/catalog/seriesAjax.jsp",
		{pageSubBrand:subBrand}
	);

}

function getBtoModels(divElement,subBrand) {
	/*new ajax().update(pageContext + "/catalog/btoSeriesAjax.jsp",
			   divElement,
			   {
			       parameters: {pageSubBrand:subBrand}
			   }
			 );*/

	jQuery("#" + divElement).load(
		pageContext + "/catalog/btoSeriesAjax.jsp",
		{pageSubBrand:subBrand}
	);

}

function getProductSpecs(divElement,subBrand,series) {
	
        
 	jQuery.ajax({
            type: "GET", /* IE does not cache any more with POST */
            url: pageContext + "/catalog/specAjax.jsp?pageSubBrand=" + subBrand + "&pageSeries=" + series,
            cache: true,
            success: function(data, textStatus) {
            	jQuery("#" + divElement).html(data);
                jQuery(".extrasSpecData").click(function(e){
		    if(!e) var e= window.event;
		    showSpecOverlay(this.getAttribute("specId"), e.pageX, e.pageY);
		    return false;
        	});
            },
            error: function(request, textStatus, errorThrown) {
                if (request.status == 404) {
                    jQuery("#" + divElement).html("<!-- Page not found -->");
                }
            }
        }); //end of ajax call
}

function getProductPriceByDisplayName(divElement,displayName) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{prodId:displayName,formatted:false}
	);
}

function getFormattedProductPriceByDisplayName(divElement,displayName) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{displayName:displayName,formatted:true}
	);
}

function getProductPriceByPartNum(divElement,partNum) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{partNum:partNum,formatted:false}
	);
}

function getFormattedProductPriceByPartNum(divElement,partNum) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{partNum:partNum,formatted:true}
	);
}

function getAccessoryPriceByPartNum(divElement,prodId) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{accProdId:prodId,formatted:false}
	);
}

function getFormattedAccessoryPriceByPartNum(divElement,prodId) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{accProdId:prodId,formatted:true}
	);
}

function getFormattedSeriesPrice(divElement,catPath, catName) {
	jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{fam:catPath,series:catName,formatted:true}
	);
}

function getSeriesPrice(divElement,catPath, catName) {
   jQuery("#" + divElement).load(
		pageContext + "/catalog/priceAjax.jsp",
		{fam:catPath,series:catName,formatted:false}
	);
}

/*
function getRatingValue(prodId,placeholder) {
	new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
			   placeholder,
			   {
			       parameters: {prodId:prodId,ratingValue:true,ratingImage:false}
			   }
			 );

}

function getRatingImage(prodId,placeholder) {
	new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
			   placeholder,
			   {
			       parameters: {prodId:prodId,ratingValue:false,ratingImage:true}
			   }
			 );

}

function getSeriesRatingValue(catPath, catName,placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
			   placeholder,
			   {
			       parameters: {catPath:catPath,catName:catName,ratingValue:true,ratingImage:false}
			   }
			 );

}

function getSeriesRatingImage(catPath, catName,placeholder) {
    new ajax().update("/showcase/explore/jsp/common/ratingsAjax.jsp",
			   placeholder,
			   {
			       parameters: {catPath:catPath,catName:catName,ratingValue:false,ratingImage:true}
			   }
			 );

}*/

//****  Online product training AJAX functions start.*****//
function getTabContent(divElement, moduleId, tabId, moduleName, tabName) {
	jQuery("#" + divElement).load(
		pageContext + "/training/tabAjax.jsp",
		{moduleId:moduleId, tabId:tabId, moduleName:moduleName, tabName:tabName}
	);
	/*
	new ajax().update(pageContext + "/training/tabAjax.jsp",
			   divElement,
			   {
				   //onLoading : function() { getElementById(divElement).innerHTML = "<DIV WIDTH='950px'><img src='/images/channel/ui1/icons/ajax_loader.gif' alt='Retrieving Content for "+tabName+" ..'/><b>Retrieving Content for "+tabName+" ..</b></DIV>" },
				   parameters: {moduleId:moduleId, tabId:tabId, moduleName:moduleName, tabName:tabName}
			   }
			 );*/
}

function getQuizContent(divElement, moduleId, isQuizTab, noOfQuestions, moduleName, tabName, qdNumber) {
	jQuery("#" + divElement).load(
		pageContext + "/training/tabAjax.jsp",
		{moduleId:moduleId, isQuizTab:isQuizTab, noOfQuestions:noOfQuestions, moduleName:moduleName, tabName:tabName, qdNumber:qdNumber}
	);
	/*
	new ajax().update(pageContext + "/training/tabAjax.jsp",
			   divElement,
			   {
				   //onLoading : function() { getElementById(divElement).innerHTML = "<img src='/images/channel/ui1/icons/ajax_loader.gif' alt='Retrieving Content for "+tabName+" ..'/><b>Retrieving Content for "+tabName+" ..</b><br/>" },
				   parameters: {moduleId:moduleId, isQuizTab:isQuizTab, noOfQuestions:noOfQuestions, moduleName:moduleName, tabName:tabName, qdNumber:qdNumber}
			   }
			 );*/
}

function getTranscript(divElement, userId, qdNumber) {
	jQuery("#" + divElement).load(
		pageContext + "/training/reportAjax.jsp",
		{userId:userId, qdNumber:qdNumber}
	);
}

function requestPackingList(cust, order, id) {
	jQuery.ajax({
		type: "POST",
		url: "packingListAjax.jsp",
		data: "cust=" + cust + "&order=" + order,
		success: function(data, textStatus) {
			if (data.indexOf("SUCCESS") == 0) {
				window.open("packing-list.jsp?cust=" + cust + "&order=" + order, "_top");
			} else {
				jQuery("#" + id).html(data);
			}
		}
	}); //end of ajax call

}

function validateSearchKeyword(inputText) {
	if (inputText.search(/[A-Za-z0-9]/) != -1) {
		inputText.replace("\n", " ", "g");
		inputText.replace("\r", " ", "g");
		return true;
	}

	alert("Please enter a keyword or phrase to search.");
	return false;
}


//****  FUNCTIONS FROM CHANNEL_CS.JS STARTS.*****//
function toggleSubMenu(id) {
	if(id.style.display == "none"){
		id.style.display = "";
	}else{
		id.style.display = "none";
	}
}

function changeCellColor(id, state){
	var colorClass;
	if(state == "over"){
		colorClass = "leftNavOver";
	}else{
		colorClass = "leftNav";
	}
	id.setAttribute("class", colorClass);
	id.setAttribute("className", colorClass);
}

function popupWindow(url) {
	popWindow(url,'yes','yes',800,480)
}

function popWindow(url,sb,rz,w,h)
{
	if (typeof(myRemote) != "undefined") myRemote.close();
	myRemote = launch(url,
                "pop_window",
                "toolbar=no,status=no,menubar=no,scrollbars=" + sb + ",resizable=" + rz + ",width=" + w + ",height=" + h,
                "parent_opener");
}

function loginSubmit() {
	document.login.submit();
}

function checkLoginEnter(e)
{
	if (e.keyCode==13)
		loginSubmit();

	var characterCode  //literal character code will be stored in this variable

	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)
		loginSubmit(); //submit the form
		return false
	}
	else{
		return true
	}
}

function openFlashFile(newURL)
{
	window.open(newURL, "_blank",'width=850,height=520,resizable=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,toolbar=no,titlebar=no,hotkeys=no');
}

function validateFormElement( formElement,str)
{
    newInputValue = formElement.value
    var okay = true;
    strLen = 0;

    // remove all leading & trailing blanks
    newInputValue = newInputValue.replace(/^ +/, "");
    newInputValue = newInputValue.replace(/ +$/, "");

    if( newInputValue == null || newInputValue.length == 0 || newInputValue.value == ' ' )
    {
        alert ( str );
        formElement.value='';
        formElement.focus();
        okay = false;
    }
    return okay
 }

function isEmpty( formElement)
 {
    inputValue = formElement.value
    var okay = false;
    if( inputValue == null || inputValue.length == 0 || inputValue.value == ' ' )
    {
        formElement.focus();
        okay = true;
    }
    return okay
 }


function validEmail(tbox) {
	var str=tbox.value ;

	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported)
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	// Regular expression validation of RFC 28222 and RFC 1035 e-mail address
	// Borrowed from: http://www.codepost.org/browse/snippets/55
	var atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]";    // allowed characters for part before "at" character
	var domain = "([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)"; // allowed characters for part after "at" character

	var regex = '^' + atom + '+' +        	// One or more atom characters.
		'(.' + atom + '+)*' +             	// Followed by zero or more dot separated sets of one or more atom characters.
		'@' +                               // Followed by an "at" character.
		'(' + domain + '{1,63}.)+' +        // Followed by one or max 63 domain characters (dot separated).
		domain + '{2,63}' +                 // Must be followed by one set consisting a period of two
		'$';                                // or max 63 domain characters.

	var r1 = new RegExp(regex);
	var result = r1.test(str);
	if (!result)
		alert ("'" + str + "' is not a valid e-mail address.  Please check your entry and try again.");
	return (r1.test(str));
}


function Checknum(num)
 {
   var valid = true;
   var number = new String(num);
   for (var i = 0; i < number.length; i++){
     var n = number.charAt(i);
     //ONLY NUMERIC CHARACTERS ALLOWED
     if ((!((parseFloat(n) >= 0)||(parseFloat(n) <= 9)))||isNaN(n)){
       valid = false;
       break;
     }
   }
   return valid;
 }

function validatePhone(fName,numLen)
 {
   var fVal=fName.value;
   //if(Checknum(fVal)==false || (fVal.length >0 && fVal.length != numLen))
   if(Checknum(fVal)==false || (fVal.length != numLen))
   {
     alert("Please make sure the phone number field contains "+ numLen+" digit numbers.");
     fName.select();
     fName.focus();
     return false;
   }
   return true ;
 }


function isAlpha(str)
{
	var expObj = /^([a-zA-Z\s]+)$/;
	var alpha = str.match(expObj);
 	if (alpha == null)
		return false;

	return true;
}

function isNumeric(str)
{
	var expObj = /\D/;
	var number = str.match(expObj);
	if(number != null)
		return false;

	return true;
}

function isAlphaNumeric(str)
{
   	var expObj = /^([a-zA-Z0-9\s]+)$/;
	var alphaNum = str.match(expObj);
	if(alphaNum == null)
		return false;
	return true;
}

function validateAddress(address)
{
	var expObj = /^([a-zA-Z0-9\.\#\s]+)$/;
	var alphaNum = address.match(expObj);
	if(alphaNum == null)
		return false;

	return true;
}
// Client-side JS functions for form validation

function pr_ValidateOption( control, strName )
// ===================================================================
// pr_ValidateOption
// Parameters:		control		form control
//					strName		Userfriendly name for the control
// Returns:			alert message and False if validation fails, else True
// ===================================================================
{
	var coll = document.all.item( control );
	for(x=0;x<coll.length;x++)
	{
		if (coll.item(x).checked) return true;
	}
	alert( strName + ": this is a required field, and it must be filled in before your form can be published to the Web." );
	return false;
}

function pr_ValidateControl( control, strName, focus )
// ===================================================================
// pr_ValidateControl
// Parameters:		control		form control
//					strName		Userfriendly name for the control
//					focus		1: Set focus to control; 0: do not set focus to control
// Returns:			alert message and False if validation fails, else True
// ===================================================================
{
	var tmpValue	= control.value;
	if( control.type.substring(0,6) == "select" )
	{
		if( control.selectedIndex == -1) {
			tmpValue = ""
		} else {
			tmpValue = control.options[control.selectedIndex].value
		}
	}
	if( tmpValue == null || tmpValue == "" )
	{
		alert( strName + ": this is a required field." );
		if (focus) control.focus();
		return false;
	}
	return true;
}

function pr_ValidateNumber( control, strName, minLen, focus )
// ===================================================================
// pr_ValidateNumber
// Parameters:		control		form control
//					strName		Userfriendly name for the control
//					minLen		the minimum length the number should be
//					focus		1: Set focus to control; 0: do not set focus to control
// Returns:			alert message and False if validation fails, else True
// ===================================================================
{
	var checkStr	= control.value;
	var allValid	= true;

	if ( minLen!= 0 && (checkStr.length < minLen || !pr_IsNumber(control)) )
	{
		alert(strName + ": Must be numeric and at least " + minLen +
			" character(s).");
		if (focus) control.focus();
		return false;
	} else return true;
}

function pr_IsNumber( control )
// ===================================================================
// pr_IsNumber
// Parameters:		control		form control
// Returns:			True if number; False if not
// ===================================================================
{
	var checkStr	= control.value;
	var checkOk		= "0123456879";
	var allValid	= true;

	for(i=0;i<checkStr.length;i++)
	{
		ch = checkStr.charAt(i);
		for(j=0;j<checkOk.length;j++)
		{
			if ( ch == checkOk.charAt(j) ) break;
		}
		if ( j == checkOk.length )
		{
			allValid=false;
			break;
		}
	}
	if ( !allValid )
	{
		return false;
	} else return true;
}

function pr_RadioSelect( strForm, strField, intItem )
// ===================================================================
// pr_RadioSelect
// Parameters:		strForm		Form name (string)
// Parameters:		strField	Field name (string)
// Parameters:		intItem		Item to select (integer)
// Returns:				nothing
// ===================================================================
{
	var control = document.forms(strForm).item(strField);
	control.selectedIndex=intItem;
	control[control.selectedIndex].checked = true;
}

function getCookie(NameOfCookie) {
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) +
		((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function pr_setCookie(psQDNum, psLastName) {
	var lsValue	= psQDNum + '~' + psLastName + '~' +
					String.fromCharCode(
					Math.floor((26*Math.random())+97)
					,Math.floor((26*Math.random())+97)
					,Math.floor((26*Math.random())+97)
					,Math.floor((26*Math.random())+97)
					,Math.floor((26*Math.random())+97)) +
					Math.floor((899*Math.random())+100);
	setCookie('bvtmp', lsValue, 5);
}

/* ***********************************************************
** JS Browser/Version/Platform Detection Library
** =========================================================
** This library contains functions to detect/return the user's
** browser, version, and platform and to jump to a URL if
** the user is using a specified browser and/or version and/or
** platform. It's yours for free; please maintain this header!
**
*********************************************************** */

/* ***********************************************************
** Functions
** =========
** getBrowser()
**   returns browser: "netscape", "ie", "other"
** getBrowserVer()
**   returns browser version number or "n/a"
** getPlatform()
**   returns browser OS: "mac", "win", "unix", "other"
** isNetscape()
**   returns true if Netscape, false if not
** isIE()
**   returns true if IE, false if not
** isVer3()
**   returns true if version is 3.x, false if not
** isVer4()
**   returns true if version is 4.x, false if not
** isVer4up()
**   returns true if version is 4.0+, false if not
**   this is a quick way to test for DHTML capability
** isVer5()
**   returns true if version is 5.x, false if not
** isMac()
**   returns true if OS is Mac, false if not
** isWin()
**   returns true if OS is Windows, false if not
** isUNIX()
**   returns true if OS is UNIX, false if not
*********************************************************** */
function getBrowser()  // get the browser program name
  {
  if (navigator.appName == null || navigator.appName == "")
    return "other";
  else if (navigator.appName == "Netscape")
    return "netscape";
  else if (navigator.appName == "Microsoft Internet Explorer")
    return "ie";
  else
    return "other";
  }

function isNetscape()  // is browser Netscape?
  {
  if (getBrowser() == "netscape")
    return true;
  else
    return false;
  }

function isIE()  // is browser IE?
  {
  if (getBrowser() == "ie")
    return true;
  else
    return false;
  }

function getBrowserVer()  // get the browser version
{
  if (navigator.appVersion == null || navigator.appVersion == "")
    return "n/a";

  //if (isIE() )
  //{
  //	alert(navigator.userAgent);
  //	alert(navigator.appMinorVersion);
  //}
  // fix for IE 5.x appVersion bug, which returns 4.x instead of 5.x
  if (isIE() && navigator.userAgent.indexOf("5.") != -1)
  {
    var verNum = "";
    var str = navigator.userAgent;
    var pos = str.indexOf("IE ");  // real version num follows "IE "
    for (pos=pos+3; pos<str.length; pos++)  // build verNum string
      if (str.charAt(pos) == "." ||
         (str.charAt(pos) <= "9" && str.charAt(pos) >= "0"))
        verNum += str.charAt(pos);
      else
        break;

	return verNum;
  }
  // get version for Netscape/Gecko version 6 and up
  if (isNetscape() && navigator.userAgent.indexOf('Gecko') != -1)
  {
    var str = navigator.userAgent;
    var verNum = str.substring( str.lastIndexOf('/') + 1 );

    return verNum;
  }
  var verArray = navigator.appVersion.split(" ");
  return verArray[0];
}

function isVer3()  // is browser version 3.x?
  {
  if (getBrowserVer() >= 3.0 && getBrowserVer() < 4.0)
    return true;
  else
    return false;
  }

function isVer4()  // is browser version 4.x?
  {
  if (getBrowserVer() >= 4.0 && getBrowserVer() < 5.0)
    return true;
  else
    return false;
  }

function isVer4up()  // is browser version 4.0+? (for DHTML coding)
  {
  if (getBrowserVer() >= 4.0)
    return true;
  else
    return false;
  }

function isVer5()  // is browser version 5.x?
  {
  if (getBrowserVer() >= 5.0 && getBrowserVer() < 6.0)
    return true;
  else
    return false;
  }

function getPlatform()  // get the browser platform (OS)
  {
  if (navigator.platform == null || navigator.platform == "")
    return "other";
  else if (navigator.platform.indexOf("Mac") >= 0)
    return "mac";
  else if (navigator.platform.indexOf("Win") >= 0)
    return "win";
  else if (navigator.platform.indexOf("Unix") >= 0)
    return "unix";
  else
    return "other";
  }

function isMac()  // is browser OS Mac?
  {
  if (getPlatform() == "mac")
    return true;
  else
    return false;
  }

function isWin()  // is browser OS Windows?
  {
  if (getPlatform() == "win")
    return true;
  else
    return false;
  }

function isUNIX()  // is browser OS UNIX?
  {
  if (getPlatform() == "unix")
    return true;
  else
    return false;
  }

/* ***********************************************************
** END OF
** JS Browser/Version/Platform Detection Library
** =========================================================
*/

var itaWin = null;

function preferredRewardsLogin() {
	document.cookie = "pprewardswin=yes;path=/";
	window.location.href='login.jsp?nextpage=home.jsp&qs=' + escape('pprewards=yes');
}

function openPreferredRewards() {
	itaWin = window.open('preferredRewards.jsp', 'ita',
	'resizable=yes,location=no,directories=no,scrollbars=yes,menubar=no,status=no,toolbar=no,titlebar=no,hotkeys=no');

	setTimeout("checkPreferredRewards()", 700);
}

function checkPreferredRewards(){
	if ( (itaWin == null) || (typeof(itaWin) == "undefined")) {
  		alert('Popups are not supported by your browser.  You may have a popup blocker installed and it is preventing us from opening up the Toshiba Rewards Program window automatically.  If this is the case, please click on the Preferred Partners banner ad at the bottom of this page or the Channel home page image.  You may also enable popups for this site to allow popups in the future.');

	} else if (typeof(lbPreferredPartner) == "undefined" || !lbPreferredPartner) {
		window.location.href = "preferredApplication.jsp";

	}
}

function formatCurrency(amount)
{
    var i = parseFloat(amount);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return commaFormatted(s);
}

function commaFormatted(amount)
{
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.',2)
    var d = a[1];
    var i = parseInt(a[0]);
    if(isNaN(i)) { return ''; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    while(n.length > 3)
    {
        var nn = n.substr(n.length-3);
        a.unshift(nn);
        n = n.substr(0,n.length-3);
    }
    if(n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if(d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;

    return amount;
}
// end of function commaFormatted()


function checkOnKeyPress(e, numcheck) {
	var keychar;
	var keynum;
	if(window.event) {
		keynum = e.keyCode
	} else if(e.which) {
		keynum = e.which
	}
	keychar = String.fromCharCode(keynum)
	//alert ("keynum=" + keynum + ", keychar='" + keychar + "', numcheck=" + numcheck.toString() );
	return numcheck.test(keychar)
}

function alphanumericOnKeyPress(e) {
	// Allow tabs, delete, backspace in Firefox
	if (e.which != null && (e.which == 0 || e.which == 8)) {
		//alert ("e.which: " + e.which);
		return true;
	}
	return checkOnKeyPress(e, /[a-z0-9A-Z\-]/);
}

function numericOnKeyPress(e) {
	// Allow tabs, delete, backspace in Firefox
	if (e.which != null && (e.which == 0 || e.which == 8)) {
		//alert ("e.which: " + e.which);
		return true;
	}
	return checkOnKeyPress(e, /\d/);
}

function dateOnKeyPress(e) {
	// Allow tabs, delete, backspace in Firefox
	if (e.which != null && (e.which == 0 || e.which == 8)) {
		//alert ("e.which: " + e.which);
		return true;
	}
	return checkOnKeyPress(e, /[0-9\/\-]/);
}

function alphanumspaceOnKeyPress(e) {
	// Allow tabs, delete, backspace in Firefox
	if (e.which != null && (e.which == 0 || e.which == 8)) {
		//alert ("e.which: " + e.which);
		return true;
	}
	return checkOnKeyPress(e, /[a-z0-9A-Z \-]/);
}

//****  FUNCTIONS FROM CHANNEL_CS.JS ENDS.*****//

//****  begin enroll and profile functions  ****//

function Role() {
	this.role_id = null;
	this.parent_role_id = null;
	this.role_lvl = null;
}

function fcnRoleOptions(varFieldFrom, varFieldSet, varLevel) {
	if (varFieldFrom.selectedIndex == -1) {
		var lsParent = -1;
	} else {
		var lsParent = varFieldFrom.options[varFieldFrom.selectedIndex].value;
	}
	if (lsParent!=-1 || varLevel==1) {
		varFieldSet.length = 0;
		var x = 0;
		for (var i = 0; i < laRoles.length; i++) {
			if (varLevel==laRoles[i].role_lvl && (varLevel==1 || lsParent==laRoles[i].parent_role_id)) {
				varFieldSet.options[x] = new Option(laRoles[i].role_id, laRoles[i].role_id);
				x++;
			}
		}
	}
}

function pr_SubmitValidation(frmSearch, frmLookup) {
	// Must select an enrollment type
	if (!pr_ValidateControl(frmSearch.web_access_cd, "Enrollment Type", false)) {
		frmLookup.web_access_cd_temp[0].focus();
		return false;
	}

	// Must lookup a customer number if type other than Sales
	if (frmSearch.web_access_cd.value != frmLookup.web_access_default.value && frmSearch.QDNum.value == "") {
		alert(frmSearch.service_enroll_msg.value);
		frmLookup.a_qd_num.focus();
		return false;
	}

	// ensure customer number, if looked up, is 8 or 11 if enrolling as type 'service' or 'both'
	// if 'service' or 'both' selected, make sure they are entering an 8 or 11 digit number
	if (frmSearch.web_access_cd.value != frmLookup.web_access_default.value) {
		var lsQDCustNoHold = frmSearch.QDCustNoHold.value;
		if (lsQDCustNoHold.length != 8 && lsQDCustNoHold.length != 11) {
			alert(frmLookup.service_lookup_msg.value);
			frmLookup.a_qd_num.focus();
			return false;
		}
	}

	// only check validation on account info if not a successful lookup
	if (frmSearch.QDNum.value == '') {
		if (!pr_ValidateControl(frmSearch.a_name, "Company Name", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.a_addr_addr, "Address 1", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.a_addr_city, "City", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.a_addr_state, "State", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.a_addr_zipcode, "Zip", true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.a_main_ph_num_area, "Main Phone Area", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.a_main_ph_num_pre, "Main Phone Prefix", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.a_main_ph_num_suf, "Main Phone Suffix", 4, true)) {return false;}
		if (frmSearch.a_main_ph_num_ext.value != "") {
			if (!pr_ValidateNumber(frmSearch.a_main_ph_num_ext, "Phone Ext", 1, true)) {return false;}
		}
		if (frmSearch.a_main_fax_ph_num_area.value != "" || frmSearch.a_main_fax_ph_num_pre.value != "" ||
				frmSearch.a_main_fax_ph_num_suf.value != "" ) {
			if (!pr_ValidateNumber(frmSearch.a_main_fax_ph_num_area, "Main Fax Area", 3, true)) {return false;}
			if (!pr_ValidateNumber(frmSearch.a_main_fax_ph_num_pre, "Main Fax Prefix", 3, true)) {return false;}
			if (!pr_ValidateNumber(frmSearch.a_main_fax_ph_num_suf, "Main Fax Suffix", 4, true)) {return false;}
		}
	}

	if (!pr_ValidateControl(frmSearch.expertise, "Role", true)) {return false;}
	if (!pr_ValidateControl(frmSearch.role, "Responsibility", true)) {return false;}
	if (!pr_ValidateControl(frmSearch.c_con_fst_name, "First Name", true)) {return false;}
	if (!pr_ValidateControl(frmSearch.c_con_last_name, "Last Name", true)) {return false;}
	if (!pr_ValidateControl(frmSearch.c_con_job_title, "Job Title", true)) {return false;}

	if (!pr_ValidateControl(frmSearch.c_con_email_addr, "Email Address", true)) {return false;}

	if (frmSearch.use_acct_addr.value == "Yes") {
		fcnAccountToContactAddr(frmSearch);
	} else {
		if (!pr_ValidateControl(frmSearch.c_addr_addr, "Address 1", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.c_addr_city, "City", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.c_addr_state, "State", true)) {return false;}
		if (!pr_ValidateControl(frmSearch.c_addr_zipcode, "Zip", true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.c_con_work_ph_num_area, "Main Phone Area", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.c_con_work_ph_num_pre, "Main Phone Prefix", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmSearch.c_con_work_ph_num_suf, "Main Phone Suffix", 4, true)) {return false;}
		if (frmSearch.c_con_work_ph_num_ext.value != "" ) {
			if (!pr_ValidateNumber(frmSearch.c_con_work_ph_num_ext, "Phone Ext", 1, true)) {return false;}
		}
		if (frmSearch.c_con_fax_ph_num_area.value != "" || frmSearch.c_con_fax_ph_num_pre.value != "" ||
				frmSearch.c_con_fax_ph_num_suf.value != "" ) {
			if (!pr_ValidateNumber(frmSearch.c_con_fax_ph_num_area, "Main Fax Area", 3, true)) {return false;}
			if (!pr_ValidateNumber(frmSearch.c_con_fax_ph_num_pre, "Main Fax Prefix", 3, true)) {return false;}
			if (!pr_ValidateNumber(frmSearch.c_con_fax_ph_num_suf, "Main Fax Suffix", 4, true)) {return false;}
		}
	}

	return true;
}

function pr_SubmitValidationProfile(frmProfile) {

	if (!pr_ValidateControl(frmProfile.c_con_job_title, "Job Title", true)) {return false;}
	if (!pr_ValidateControl(frmProfile.c_con_email_addr, "Email Address", true)) {return false;}
	if (!pr_ValidateControl(frmProfile.c_addr_addr, "Address 1", true)) {return false;}
	if (!pr_ValidateControl(frmProfile.c_addr_city, "City", true)) {return false;}
	if (!pr_ValidateControl(frmProfile.c_addr_state, "State", true)) {return false;}
	if (!pr_ValidateControl(frmProfile.c_addr_zipcode, "Zip", true)) {return false;}
	if (!pr_ValidateNumber(frmProfile.c_con_work_ph_num_area, "Main Phone Area", 3, true)) {return false;}
	if (!pr_ValidateNumber(frmProfile.c_con_work_ph_num_pre, "Main Phone Prefix", 3, true)) {return false;}
	if (!pr_ValidateNumber(frmProfile.c_con_work_ph_num_suf, "Main Phone Suffix", 4, true)) {return false;}
	if (frmProfile.c_con_work_ph_num_ext.value != "" ) {
		if (!pr_ValidateNumber(frmProfile.c_con_work_ph_num_ext, "Phone Ext", 1, true)) {return false;}
	}
	if (frmProfile.c_con_fax_ph_num_area.value != "" || frmProfile.c_con_fax_ph_num_pre.value != "" ||
			frmProfile.c_con_fax_ph_num_suf.value != "" ) {
		if (!pr_ValidateNumber(frmProfile.c_con_fax_ph_num_area, "Main Fax Area", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmProfile.c_con_fax_ph_num_pre, "Main Fax Prefix", 3, true)) {return false;}
		if (!pr_ValidateNumber(frmProfile.c_con_fax_ph_num_suf, "Main Fax Suffix", 4, true)) {return false;}
	}
	if (frmProfile.Password1.value != frmProfile.Password2.value) {
		alert("Passwords do not match.");
		frmProfile.Password1.focus();
		return false;
	}
	return true;
}

function fcnAccountToContactAddr(frmSearch) {
	frmSearch.c_addr_addr.value = frmSearch.a_addr_addr.value;
	frmSearch.c_x_addr_2.value = frmSearch.a_x_addr_2.value;
	frmSearch.c_addr_city.value = frmSearch.a_addr_city.value;
	if (frmSearch.a_addr_state.type.substring(0,6) == "select" ) {
		frmSearch.c_addr_state[frmSearch.a_addr_state.selectedIndex].selected = true;
	} else {
		for (var x = 0; x < frmSearch.c_addr_state.length; x++) {
			if (frmSearch.c_addr_state[x].value == frmSearch.a_addr_state.value) {
				frmSearch.c_addr_state[x].selected = true;
				break;
			}
		}
	}
	frmSearch.c_addr_zipcode.value = frmSearch.a_addr_zipcode.value;
	frmSearch.c_con_work_ph_num_area.value = frmSearch.a_main_ph_num_area.value;
	frmSearch.c_con_work_ph_num_pre.value = frmSearch.a_main_ph_num_pre.value;
	frmSearch.c_con_work_ph_num_suf.value = frmSearch.a_main_ph_num_suf.value;
	frmSearch.c_con_work_ph_num_ext.value = frmSearch.a_main_ph_num_ext.value;
	frmSearch.c_con_fax_ph_num_area.value = frmSearch.a_main_fax_ph_num_area.value;
	frmSearch.c_con_fax_ph_num_pre.value = frmSearch.a_main_fax_ph_num_pre.value;
	frmSearch.c_con_fax_ph_num_suf.value = frmSearch.a_main_fax_ph_num_suf.value;
	return true;
}

function fcnClearContactAddr(frmSearch) {
	frmSearch.c_addr_addr.value = '';
	frmSearch.c_x_addr_2.value = '';
	frmSearch.c_addr_city.value = '';
	frmSearch.c_addr_state[0].selected = true;
	frmSearch.c_addr_zipcode.value = '';
	frmSearch.c_con_work_ph_num_area.value = '';
	frmSearch.c_con_work_ph_num_pre.value = '';
	frmSearch.c_con_work_ph_num_suf.value = '';
	frmSearch.c_con_work_ph_num_ext.value = '';
	frmSearch.c_con_fax_ph_num_area.value = '';
	frmSearch.c_con_fax_ph_num_pre.value = '';
	frmSearch.c_con_fax_ph_num_suf.value = '';
	return true;
}

function pr_LookupValidation(frmSearch) {
	// if 'service' or 'both' selected, make sure they are entering an 8 or 11 digit number
	if (frmSearch.web_access_cd.value != frmSearch.web_access_default.value) {
		var lsQDNum = frmSearch.a_qd_num.value;
		if (lsQDNum.length != 8 && lsQDNum.length != 11) {
			alert(frmSearch.service_lookup_msg.value);
			return false;
		}
	}
	return true;
}

function fcnEnrollAs(frmLookup, frmSignup, intIndex) {
	var control = frmLookup.web_access_cd_temp;

	if (intIndex != 0) {
		if (confirm(frmSignup.service_enroll_msg.value)) {
		} else {
			control.selectedIndex = 0;
			intIndex = 0;
			control[control.selectedIndex].checked = true;
		}
	}
	frmSignup.web_access_cd.value = control[intIndex].value;
	frmLookup.web_access_cd.value = control[intIndex].value;
	frmLookup.a_qd_num.focus();
}

function f_use_acct_addr(obj) {
	if (obj.checked) {
		document.getElementById("addressBlock").style.visibility = "hidden";
		fcnAccountToContactAddr(document.SIGNUP);
		document.SIGNUP.use_acct_addr.value = "Yes";
	} else {
		fcnClearContactAddr(document.SIGNUP);
		document.getElementById("addressBlock").style.visibility = "visible";
		document.SIGNUP.use_acct_addr.value = "No";
		document.SIGNUP.c_addr_addr.focus();
	}
}

//****  end enroll and profile functions  ****//

//****  begin product detail functions ****//
function openSpecSheet(link) {
    popWindow(link,'yes','yes',820,650,'no','no','no');
}

function showGallery() {
	document.getElementById("showgallery").style.display = "";
	document.getElementById("gallerypanel").style.visibility = "visible";
	document.getElementById("gallerypanel").style.top = (document.body.scrollTop + 75) + "px";
	document.getElementById("gallerypanel").style.zIndex = 9999;
}

function shareThis(link){
	window.open(link, "_blank",'width=640,height=480,resizable=no,location=no,directories=no,scrollbars=no,menubar=no,status=no,toolbar=no,titlebar=no,hotkeys=no');
}

//****  end product detail functions ****//
