/************************** BrowserSniffer.js ***************************/
// load an additional css if this is for calibex
var theURL = location.href;



/************************** Header.js *************************************/
function canSupportBookmark() {
	if ((navigator.platform!="MacPPC") && (navigator.appName=="Microsoft Internet Explorer")) {
		var idx;
		var endIdx;
		var IEVersion = null;
		var major;
		var appVersion = navigator.appVersion;

		if (appVersion.indexOf("AOL") != -1)
			return false;

	    idx = appVersion.indexOf('MSIE');
	    endIdx = appVersion.indexOf(';', idx);
	    IEVersion = appVersion.substring(idx + 5, endIdx);
	    idx = IEVersion.indexOf(".");
	    if (idx == -1) {
	    	major = IEVersion;
	    } else {
		    major = IEVersion.substring(0, idx);
		}

    	if (major >= "4")
    		return true;
    }

	return false;
}

function setAction(selectObj, form) {
	form.action = selectObj.options[selectObj.options.selectedIndex].value;
}
// *********************** from javascript.js ******************************
// whitespace characters
var whitespace = " \t\n\r";

function showHelp2(page) {
	popupWindow("/buyer/help.jsp?page="+page,"Help","resizable=1,menubars=1,width=475,height=400");
}

function selectValue(slt) {
	return slt==null ? null : slt.options[slt.selectedIndex].value;
}

// Removes all characters which appear in string bag from string s.
function stripCharsInBag (s, bag) {   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) {
        	returnString += c;
        }
    }

    return returnString;
}

// Removes all characters which do NOT appear in string bag 
// from string s.
function stripCharsNotInBag (s, bag){   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is in bag, append to returnString.
    for (i = 0; i < s.length; i++) {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// Removes all whitespace characters from s.
// Global variable whitespace
// defines which characters are considered whitespace.
function stripWhitespace(s){   
	return stripCharsInBag(s, whitespace);
}

function popupWindow(url,name,features) {
	// kludged for IE
	var x = name;
	if( document[name]!=null && !document[name].closed ) {
//		document[name].focus();
		document[name].close();
		name += "x";
	}
	document[x] = window.open(url,name,features);
}
function load(url) {
location=url;
}
function click(url) {
open(url, "_blank");
}
function rating(url) {
location=url + '&#rating';
}
// for BBBOnline Window
function Certify(URL) {
  popupWin = window.open(URL, 'Participant', 'location,scrollbars,width=450,height=300');
  window.top.name = 'opener';
}

// Script for Pop-up Help Windows
	var helpWin = null;
	function showHelp(filename) {
 		var helpWin = window.open(filename,'Help','width=400,height=300,resizable=yes,scrollbars=yes,top=50,left=100');
	}

// Script for Signio pop-up window
	var signioWindow = null;
	function signioWin(name,url) {
	signioWindow = window.open(url,name,'width=500,height=350,resizable=yes,scrollbars=yes,top=50,left=50');
	}

var gsBlankIcon="/images/1x1blank.gif";
function showtip(current,e,text) //shows tooltips on images
{
    if (document.all) //Used to detect IE so that the tooltip renders correctly
    {
       thetitle=text.split('<br />');
       if (thetitle.length > 1)
       {
          thetitles="";
          for (i=0; i<thetitle.length; i++)
              thetitles += thetitle[i] + "\r\n";
          current.title = thetitles;
       }
       else current.title = text;
    }
}
// ************************** from EnterEmailJS.jsp **************************
function emailCheck (emailStr, ack) {
/*
The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain.
*/
var emailPat=/^(.+)@(.+)$/;
/*
 The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]
*/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
/*
 The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed.
*/
var validChars="\[^\\s" + specialChars + "\]";
/*
 The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address.
*/
var quotedUser="(\"[^\"]*\")";
/*
 The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required.
*/
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/*
 The following string represents an atom (basically a series of
   non-special characters.)
*/
var atom=validChars + '+';
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string.
*/
var word="(" + atom + "|" + quotedUser + ")";
/*
 The following pattern describes the structure of the user
*/
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/*
 The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above.
*/
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/*
   Finally, let's start trying to figure out if the supplied address is
   valid.

   Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze.
*/
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
/*
    Too many/few @'s or something; basically, this address doesn't
    even fit the general mould of a valid e-mail address.
*/
	alert("Please type a valid e-mail address");
	return false;
}
var user=matchArray[1];
var domain=matchArray[2];
/*
See if "user" is valid
*/
if (user.match(userPat)==null) {
/*
   user is not valid
*/
    alert("The username is invalid");
    return false;
}
/*
   if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid.
*/
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
/*
   this is an IP address
*/
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid");
		return false;
	    }
    }
    return true;
}
/*
   Domain is symbolic name
*/
var domainArray=domain.match(domainPat);
if (domainArray==null) {
	alert("The domain name is invalid");
    return false;
}
/*
   domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country.

   Now we need to break up the domain to get a count of how many atoms
   it consists of.
*/
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if ((domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>3) && domArr[domArr.length-1] != "name") {
/*
   the address must end in a two letter or three letter word.
*/
   alert("The e-mail address must end in a three-letter domain, or two letter country");
   return false;
}
/*
   Make sure there's a host name preceding the domain.
*/
if (len<2) {
   var errStr="This address is missing a hostname";
   alert(errStr);
   return false;
}
/*
   If we've gotten this far, everything's valid! 
*/
if (ack)
	alert("Thank you for submitting your e-mail");
return true;
}
// ************************ from ProductCoreHTML.js **********************
function isChecked(a) {
	if( navigator.userAgent.indexOf("AOL") != -1 )
		return true;
	if( a.checked != null )
		return a.checked;
	for( i=0; i<a.length; i++ ) {
		if( a[i].checked )
			return true;
	}
	return false;
}

function doBid() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;

	if(  !isChecked(theForm.tags) ) {
		alert("Please select seller(s) to whom you wish to send this offer.");
		return;
	}
	theForm.cmd.value = "doBid";
	theForm.submit();
}

function counterOffer() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	if(  !isChecked(theForm.tags) ) {
		alert("Please select seller(s) to whom you wish to send this offer.");
		return;
	}
	var price = window.prompt("Please enter the Total Price you are willing to Pay","");
	if( price==null ) {
		return;
	}
	theForm.bidPrice.value = price;
	theForm.cmd.value = "doBid";
	theForm.submit();
}

function setShipping() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	theForm.cmd.value = "setShipping";
	theForm.submit();
}

function setZipCode() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	theForm.cmd.value = "changeZipcode";
	theForm.submit();
}

function changeZipCode(curZip) {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	var valid = false;
	var zip;
    while (!valid) {
		zip = prompt('Enter New Zip Code:', curZip);
		if ( zip == null )
			return;
		valid = validateZipCode(zip,"true");
    }
	theForm.zipcode.value = zip;
	setZipCode();
}

function getZipCodeErrors(zip,allowEmptyZip)
{
	var errors = "";

	len = zip.length;
	digits = "0123456789";
	
	if(len == 0)
	{
		if (allowEmptyZip){
			return errors;
		}
		return "Please enter a zip code";
	}

	if(len != 5)
	{
		errors = "Zip code is not the correct length";
	}

	for(i = 0; i < 5; i++)
	{
		if (digits.indexOf(zip.charAt(i))<0)
		{
			errors = "First five digits must be numeric";
		}
	}

	return errors;
}

function validateZipCodeForm(theForm)
{
	return validateZipCode(theForm.zipcode.value,"false");
}

function validateZipCodeForm(theForm,allowEmptyZip)
{
	return validateZipCode(theForm.zipcode.value,allowEmptyZip);
}

function validateZipCode(zip,allowEmptyZip)
{
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	var valid = true;

	errors = getZipCodeErrors(zip,allowEmptyZip);
	
	if(errors.length > 0)
	{
		alert(errors);
		try {
			theForm.zipcode.focus();
		} catch (err) { 
		}
		valid = false;	
	}
	
	return valid;
}

function clearDealsNLA() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	if(theForm.clearDealsNLA){
		theForm.clearDealsNLA.value = 'true';
		theForm.submit();
	}
	return false;
}

function showPriceWin(url) {
	popupWindow(url, "PriceHistory", "status=no,width=500,height=550,scrollbars=yes,resizable=1");
}

function rtUpdate() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	theForm.cmd.value = "rtUpdate";
	theForm.submit();
}

function deleteOffers() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;
	
	theForm.cmd.value = "deleteOffers";
	theForm.submit();
}

function showMessageWin(url) {
	popupWindow(url, "Message", "resizable=1,menubars=1,scrollbars=1,width=400,height=300");
}

function addToList() {
	var theForm = document.getElementById('theForm');
	if( theForm == null ) theForm = document.theForm;

	theForm.cmd.value = "addToList";
	theForm.submit();
}

/**************************** from x10.js *******************************/
/*
For use with X10.com Advertising PopUps
 */

/*THESE ARE THE DIFFERENT SETTINGS FOR THE POPUP*/

var pWidth  = 720; //Window Width

var pHeight = 320; //Window Height

var pTop = 20; // Align Top

var pLeft = 20;  //Align left

var pTitlebar = 1;   // 1 is on, 0 is off

var pToolbar  = 1;   // 1 is on, 0 is off

var pLocation = 1;   // 1 is on, 0 is off

var pMenubar  = 1;   // 1 is on, 0 is off

var pScrollbars = 1; // 1 is on, 0 is off

var pResizable = 1;  // 1 is on, 0 is off

var pStatus    = 1;  // 1 is on, 0 is off

var pUpDown = 0;     // 1 pop's up, 0 pop's down

//var pUrl = "http://ads.x10.com/?Z25leHRhZ1BVMS5kYXQ=[DECACHE]>nxtPU001"; // POPUP WINDOW URL
//var pUrl = "http://ads.x10.com/?Z25leHRhZ1BVMS5kYXQ=[DECACHE]>parrot";
//var pUrl = "http://www.webcreditreport.com/popunders/1.asp?sc=17257001";
var pUrl = "/serv/intel/buyer/OutPDir.jsp#ad";

//var pName = "X10" // POPUP WINDOW NAME THERE SHOULD NOT BE ANY SPACES
var pName = "INTEL";
//var pName = 'Click here for your Free Credit Report';

/*SETTING VALUES FOR THE COOKIE MONSTER*/

var domain = ".nextag.com"; // <<<-------- EDIT THIS ONE ADVERTISE DOMAIN
/************DON'T EDIT THIS PART************/

/*SETTING VALUES FOR THE COOKIE MONSTER*/
var CookieName = "x10cookiemonster";

function popUnder()
{

//alert("cookie = " + document.cookie);
        if(document.cookie.indexOf(CookieName) == -1)
        {
                /*IF COOKIE IS NOT FOUND WRITE COOKIE AND DISPLAY POPUP*/
                var today = new Date();
                var expires = new Date();
                expires.setTime(today.getTime() + 1000*60*60*12);
                var domain = "nextag.com";
                if (document.domain.indexOf(domain) == -1)
                	domain = '';
                if (domain.length > 0 )
                	domain = "domain=." + domain + ';';
                document.cookie = CookieName+"=1;expires="+expires.toGMTString()+"; path=/ ;"+domain;
        
var pSettings = "titlebar="+pTitlebar+",toolbar="+pToolbar;

//			    var pSettings = "width="+pWidth+",height="+pHeight+",titlebar="+pTitlebar+",toolbar="+pToolbar+",location="+pLocation;
        
//                pSettings += ",menubar="+pMenubar+",scrollbars="+pScrollbars+",resizable="+pResizable+",status="+pStatus;
//+",top="+pTop+",left="+pLeft;
        
//                window.open(pUrl,pName,pSettings);
				window.open(pUrl,pName);
        
                if(pUpDown == 0 )
                {
                        self.focus();
                }
        }
}

function popUp() {}

var now = new Date();
now = now.getTime();
function TimeStampURL(url) {
	return url + "&c=" + now;
}


function showRatingsPopup(url) {
	window.open(url,"","width=260,height=180,");
}

function showNamedPopup(url, name) {
	window.open(url,name,"width=260,height=180,");
}

function mailTo(name, domain, options) {
	var mailToString = null;
	if ((name != null) && (domain != null) && (options != null)) {
		mailToString = "mailto:"+name+"@"+domain+"?"+options;
	}
	else if ((name != null) && (domain != null)) {
		mailToString = "mailto:"+name+"@"+domain;
	}

	if (mailToString != null) {
		window.location = mailToString;
	}
}


function compareProd(nav_url_str)	{
	if (!document.getElementById('resultForm').cptitle) {
		alert('First select products to compare');
		return;
	}
	j = 0;
	for (i = 0; i<document.getElementById('resultForm').cptitle.length; i++) {
		if (document.getElementById('resultForm').cptitle[i].checked == true)
			j++;
	}
	if (j >= 2 && j <= 20) {
		document.getElementById('resultForm').action = nav_url_str;
		document.getElementById('resultForm').submit();
	} else {
		if (j > 20) {
			alert('Please select a maximum of 20 products to compare');
		} else {
			alert('First select up to 20 products to compare');
		}
	}
}


function updateOutpdirZipCode(curZip) {
	zip = document.getElementById('zipcode').value;
	if (zip == curZip)
		return false;
	
	valid = validateOutpdirZipCode(zip);

	if (valid) {
		document.getElementById('resultForm').zipcode.value = zip;
		document.getElementById('resultForm').submit();
	} else {
		document.getElementById('resultForm').zipcode.value = curZip;
	}
	
	return false;
}

function changeOutpdirZipCode(curZip) {
	zip = prompt('Enter new ZIP code:', curZip);
	if ( zip == null || zip == curZip)
		return;

	valid = validateOutpdirZipCode(zip);

	if (valid) {
		document.getElementById('resultForm').zipcode.value = zip;
		document.getElementById('resultForm').submit();
	}
}
function validateOutpdirZipCode(zip) {
	var valid = true;
	errors = getZipCodeErrors(zip, true);
	if(errors.length > 0) {
		alert(errors);
		valid = false;
	}
	return valid;
}

function largePhotos(ptid)
{
window.open("/buyer/More/Hotels/AllHotelPhotos.jsp?ptidPassToAllHotelPhotos="+ptid,"large_photos","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=800, height=580")
}

function popupImage(ptitle,width,height) 
{
	var options = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,copyhistory=yes';
	var w,h;
	w = width+50;
	h = height+60;
	options += ',width='+w+',height='+h;
	window.open("/buyer/product/PopupImage.jsp?pt="+ptitle,'large_img',options);
}

function popup(mylink, windowname, height, width)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=' + width + ',height=' + height + ',scrollbars=no');
return false;
}


	function reload(form, select) {
		form.cmd.value = '';
		form.submit();
	}

	function addTimeStamp(url) {
		var currTime = new Date();
		currTime = currTime.getTime();
		return url + "&c=" + currTime;
	}

	/*
	This will take text and truncate it to a certain length.
	if it truncates in the middle of a word (indicated by
	a space), then it will back off and cut off to the closest
	space while making sure the returned text is still under
	the limit.  In other words, it rounds down if it encounters
	truncated text.
	*/
	function truncateText(text, limit) {
		if( text.length < limit ) return text;

		var temp = text.substring(0, limit);
		var lastSpaceIndex = temp.lastIndexOf(' ');

		return temp.substring(0, lastSpaceIndex);
	}

	function showPartDescription(originalContent, elementIdToTruncate, cutOffLimit, graceCutOffLimit, moreText) {
		var link = "";
		var max = parseInt(cutOffLimit) + parseInt(graceCutOffLimit);
		if ( originalContent.length > max ) {
			link = createLink("javascript:showAllDescription('" + elementIdToTruncate + "', " + cutOffLimit + ")", moreText);
			document.getElementById(elementIdToTruncate).innerHTML = truncateText(originalContent, cutOffLimit) + " " + link;
		}
	}

	function showAllDescription(elementIdToShow, cutOffLimit) {
		if ( originalContent.length > cutOffLimit ) {
			link = createLink("javascript:showPartDescription('" + elementIdToShow + "')", "hide...");

		}
		document.getElementById(elementIdToShow).innerHTML = originalContent; //original content is in the jsp
	}

	function showOutpdirAllDescription(elementIdToShow, elementIdToHide) {
		document.getElementById(elementIdToShow).style.display = "inline";
		document.getElementById(elementIdToHide).style.display = "none";
	}
	
	function showExpandableDescription(elementId){
		showOutpdirAllDescription(elementId,elementId+'_tail');
		document.getElementById(elementId+'_head').style.cursor = 'default';
	}
	
	function createLink(href, value) {
		return "<a href=\"" + href + "\">" + value + "</a>";
	}

	/* hideAll, writeBrowseMore and showMore are used for the Browse page */
	function hideAll(tagname, classname, viewValue) {
	    var elements = document.getElementsByTagName(tagname);
	    for (var i=0; i < elements.length; i++) {
	        if (elements[i].className == classname) {
	            elements[i].style.display=viewValue;
	        }
	    }
	}

	/* hideAll, writeBrowseMore and showMore are used for the Browse page */
	function showMore(node) {
		var spanId = 'span_' + node;
		var moreId = 'more_' + node;
		document.getElementById(spanId).style.display='inline';
		document.getElementById(moreId).style.display='none';
	}
	/* hideAll, writeBrowseMore and showMore are used for the Browse page */
	function writeBrowseMore(node, moreText) {
		document.write('<span id="more_' + node + '" name="more_link">,&nbsp; <a href="javascript:showMore(\'' + node + '\')">' + moreText + '</a></span>');
	}

	/* Review Ratings.js */
	function popup(url) {
    window.open(url, "", "menubar=no,height=500,width=600,scrollbars,resizable");
	}
	
	function showMoreNodes(node, isBestRefinementView) {
		var divId = 'div_' + node;
		var moreId = 'more_' + node;
		document.getElementById(divId).style.display='inline';
		if ( !isBestRefinementView ) {
			document.getElementById(moreId).style.display='none';
		} else {
			document.getElementById(moreId).href = "javascript:showLessNodes('"+node+"', " + isBestRefinementView+ ")";
			document.getElementById(moreId).innerHTML = "&laquo; fewer categories";
		}
	}

	function showLessNodes(node, isBestRefinementView){
		var divId = 'div_' + node;
		var moreId = 'more_' + node;
		document.getElementById(divId).style.display='none';
		document.getElementById(moreId).href = "javascript:showMoreNodes('"+node+"', " + isBestRefinementView + ")";
		document.getElementById(moreId).innerHTML = "more categories &raquo;";
	}
	
	function showAdditionalItems(eleId) {
		var ele = document.getElementById(eleId);
		if (ele && ele.style) ele.style.display = "none";		
		while (ele.nextSibling) {
			if (ele.nextSibling.style) 
				ele.nextSibling.style.display="";
			ele = ele.nextSibling;
		}
	}
	
	// ===================================================================
	// Author: Matt Kruse <matt@mattkruse.com>
	// WWW: http://www.mattkruse.com/
	// ===================================================================

	// -------------------------------------------------------------------
	// tabNext()
	// Function to auto-tab phone field
	// Arguments:
	//   obj :  The input object (this)
	//   event: Either 'up' or 'down' depending on the keypress event
	//   len  : Max length of field - tab when input reaches this length
	//   next_field: input object to get focus after this one
	// -------------------------------------------------------------------
	var phone_field_length=0;
	function tabNext(obj,event,len,next_field) {
		if (event == "down") {
			phone_field_length=obj.value.length;
		}
		else if (event == "up") {
			if (obj.value.length != phone_field_length) {
				phone_field_length=obj.value.length;
				if (phone_field_length == len) {
					next_field.focus();
				}
			}
		}
	}

	function submitForm(url,formId,conId,buttonId,buttonText) {
		var x;
		if (buttonId) {
			x=document.getElementById(buttonId);
			x.disabled=true;
			if (buttonText)
				x.value=buttonText;
		}
		var u=url+'?';
		x=document.getElementById(formId);
		for (var i=0;i<x.length;i++) {
			if (i>0) u+='&';
			u+=x.elements[i].name+'='+x.elements[i].value;
		}

		if (typeof(nsinfo) != 'undefined'){
			if (nsinfo.chnl) u += "&chnl=" + nsinfo.chnl;
			if (nsinfo.as) u += "&style=" + nsinfo.as;
			if (nsinfo.ssb) u += "&ssb=" + nsinfo.ssb;
			if (nsinfo.bld) u += "&rv=" + nsinfo.bld;
		}
		document.body.style.cursor = 'wait';
		new NxtgHttpReq(u, 
				{cb: function(data) {
				var c = document.getElementById(conId);
				c.innerHTML = data;
				document.body.style.cursor = 'default';
				}
		}).send();
		return false;
	}

	function popupSTP(url) {
		var destUrl = '/buyer/sendtophone.jsp';
		if (typeof(nsinfo) != 'undefined'){
			destUrl = '/serv/'+nsinfo.chnl+destUrl;
		}
		window.open(destUrl+'?new=y&sendUrl='+url,'stp','width=350,height=220,resizable=no,scrollbars=no,location=no,status=no,toolbar=no,menubar=no');
	}