// Finalized Code
var dispWindow = null; 
var chasm = screen.availWidth;
var mount = screen.availHeight;

function useSortBy(sortBy) {
	var url = 'http://www.costcentral.com';
	var currentUrl = parseUri(location.href);

	if (currentUrl.file.slice(currentUrl.file.indexOf(".")).toLowerCase() != '') {
		// php file extension
		url += currentUrl.path + '?sortby=' + sortBy;
		if (currentUrl.queryKey['vendorid'] != undefined)
			url += '&vendorid=' + currentUrl.queryKey['vendorid'];

		if (currentUrl.queryKey['keywords'] != undefined)
			url += '&keywords=' + currentUrl.queryKey['keywords'];

		if (currentUrl.queryKey['filterBrand'] != undefined)
			url += '&filterBrand=' + currentUrl.queryKey['filterBrand'];

		if (currentUrl.queryKey['filterCategory'] != undefined)
			url += '&filterCategory=' + currentUrl.queryKey['filterCategory'];

		if (currentUrl.queryKey['filterKeyword'] != undefined)
			url += '&filterKeyword=' + currentUrl.queryKey['filterKeyword'];
	} else {
		// no file extension
		url += currentUrl.directory + '?sortby=' + sortBy;
	}
	if (currentUrl.queryKey['filterPriceLow'] != undefined)
		url += '&filterPriceLow=' + currentUrl.queryKey['filterPriceLow'];

	location.href = url;
}

function useStock(inStock) {
	var url = 'http://www.costcentral.com';
	var currentUrl = parseUri(location.href);

	var query = (inStock == 1) ? 'stock=1' : 'stock=0';
	if (currentUrl.file.slice(currentUrl.file.indexOf(".")).toLowerCase() != '') {
		// php file extension
		url += currentUrl.path + '?' + query;
		if (currentUrl.queryKey['vendorid'] != undefined)
			url += '&vendorid=' + currentUrl.queryKey['vendorid'];

		if (currentUrl.queryKey['keywords'] != undefined)
			url += '&keywords=' + currentUrl.queryKey['keywords'];

		if (currentUrl.queryKey['filterBrand'] != undefined)
			url += '&filterBrand=' + currentUrl.queryKey['filterBrand'];

		if (currentUrl.queryKey['filterCategory'] != undefined)
			url += '&filterCategory=' + currentUrl.queryKey['filterCategory'];

		if (currentUrl.queryKey['filterKeyword'] != undefined)
			url += '&filterKeyword=' + currentUrl.queryKey['filterKeyword'];
	} else {
		// product-list
		url += currentUrl.directory + '?' + query;
	}

	if (currentUrl.queryKey['filterPriceLow'] != undefined)
		url += '&filterPriceLow=' + currentUrl.queryKey['filterPriceLow'];

	location.href = url;
}

function addtocart(ProductID) {
	var url = 'http://www.costcentral.com';
	location.href = url + '/addtocart.php?productid=' + ProductID;
}

function openLiveHelp() {
	var dsWinW = 480;
	var dsWinH = 365;
	var url = 'https://www.costcentral.com';
	dispWindow = window.open(url + '/phplive/request_email.php?l=dave&x=1&deptid=0','winLiveHelp','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openFreeShipping() {
	var dsWinW = 445;
	var dsWinH = 180;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_freeshipping.html','winFreeShip','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openSecurityBit() {
	var dsWinW = 550;
	var dsWinH = 480;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_cardsecurity.php','winSecBit','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openRealtimePricing(prodID) {
	var dsWinW = 490;
	var dsWinH = 275;
	var url = 'http://www.costcentral.com';
	url += '/pu_realtimeavail.php?ProductID=' + prodID;
	dispWindow = window.open(url,'winRealtime','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openProductQuote(prodID) {
	var dsWinW = 475;
	var dsWinH = 500;
	var url = 'http://www.costcentral.com';
	url += '/pu_quote.php?ProductID=' + prodID;
	dispWindow = window.open(url,'winProdQuote','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openCartQuote() {
	var dsWinW = 475;
	var dsWinH = 500;
	var url = 'http://www.costcentral.com';
	url += '/pu_quote.php?from=cart';
	dispWindow = window.open(url,'winCartQuote','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function reviewProduct(prodID) {
	var dsWinW = 530;
	var dsWinH = 560;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_productreview.php?ProductID=' + prodID,'winProdReview','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function reviewHelpful(id, answer) {
	var url = 'http://www.costcentral.com';
	location.href = url + '/review-helpful.php?id=' + id + '&answer=' + answer;
}

function openStockNotify(prodID) {
	var dsWinW = 450;
	var dsWinH = 240;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_stocknotify.php?ProductID=' + prodID,'winStockNotify','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openFactorySealed() {
	var dsWinW = 450;
	var dsWinH = 200;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_factorysealed.html','winFactory','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openRefurbishedSealed() {
	var dsWinW = 450;
	var dsWinH = 200;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_refurbfactorysealed.html','winRefurb','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openRebate(id) {
	var dsWinW = 750;
	var dsWinH = 450;
	var url = 'http://costcentral.rebateplace.com/product.cfm?id=';
	dispWindow = window.open(url + id,'winRebate','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function printdocument(id) {
	var dsWinW = 700;
	var dsWinH = 700;
	var url = 'https://www.costcentral.com';
	dispWindow = window.open(url + '/pu_printdocument.php?id=' + id,'winPrintDoc','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function checkSelectAll(frm, fld, value) {
	frm.checkall.checked = value;
	var frmInputs = frm.getElementsByTagName('input');
	var length = frmInputs.length;
	for (i = 0; i < length; i++) {
		var regex = new RegExp(fld, "i");
		if (regex.test(frmInputs[i].getAttribute('name'))) {
			frmInputs[i].checked = value;
		}
	}
}

function openVerifiedByVisa() {
	var dsWinW = 406;
	var dsWinH = 462;
	dispWindow = window.open('https://verified.visa.com/aam/data/default/landing.aam','winVBV','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openScanAlert() {
	var dsWinW = 570;
	var dsWinH = 650;
	dispWindow = window.open('https://www.mcafeesecure.com/RatingVerify?ref=costcentral.com','winScanAlert','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openBMLCore() {
	var dsWinW = 503;
	var dsWinH = 400;
	dispWindow = window.open('https://www.securecheckout.billmelater.com/paycapture-content/fetch?hash=8PB32P86&content=/bmlweb/coreiw.html','winBML','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openBMLPromo() {
	var dsWinW = 503;
	var dsWinH = 400;
	dispWindow = window.open('https://www.securecheckout.billmelater.com/paycapture-content/fetch?hash=8PB32P86&content=/bmlweb/np90drollingiw.html','winBML','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openBMLTerms() {
	var dsWinW = 539;
	var dsWinH = 400;
	dispWindow = window.open('https://www.securecheckout.billmelater.com/paycapture-content/fetch?hash=8PB32P86&content=/bmlweb/bmlwebtnc.html','winBMLTerms','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openVerisign() {
	var dsWinW = 539;
	var dsWinH = 400;
	dispWindow = window.open('https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=www.costcentral.com&lang=en','winVerisign','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openBBB() {
	var dsWinW = 715;
	var dsWinH = 300;
	dispWindow = window.open('http://www.bbbonline.org/cks.asp?id=101102412202819834','winBBB','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openMasterCardSecureCode() {
	var dsWinW = 825;
	var dsWinH = 480;
	dispWindow = window.open('http://www.mastercard.com/us/personal/en/cardholderservices/securecode/index.html','winSecureCode','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function isEmpty(s) {
	return /\S/.test(s);
}

/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	http://blog.stevenlevithan.com/archives/parseuri
	MIT License
*/
function parseUri (str) { var	o = parseUri.options, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), uri = {}, i = 14; while (i--) uri[o.key[i]] = m[i] || ""; uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) uri[o.q.name][$1] = $2; }); return uri; }; parseUri.options = { strictMode: false, key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], q: { name: "queryKey", parser: /(?:^|&)([^&=]*)=?([^&]*)/g }, parser: { strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ } };

function toggleDiv(id){
	if (document.getElementById(id + 'div').style.display == 'none') {
		document.getElementById(id + 'img').src = '/images/icon_down.gif';
		document.getElementById(id + 'div').style.display = 'block';
	} else {
		document.getElementById(id + 'img').src = '/images/icon_right.gif';
		document.getElementById(id + 'div').style.display = 'none';
	}
}

function openHoliday() {
	var dsWinW = 418;
	var dsWinH = 200;
	var url = 'http://www.costcentral.com';
	dispWindow = window.open(url + '/pu_holidayhours.html','winBBB','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}


// Code that still needs work
function openW(myURL,dsWinW,dsWinH) {
  dispWindow = window.open(myURL,'winProc','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function changeURL(url) {
	location.href = url;
}

function openEmailQuote(prodID) {
	var dsWinW = 500;
	var dsWinH = 275;
	dispWindow = window.open('http://www.costcentral.com/pu_emailquote.php?productID=' + prodID,'winProc','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function openMapPricing() {
	var dsWinW = 450;
	var dsWinH = 200;
	dispWindow = window.open('http://www.costcentral.com/pu_mappricing.html','winProc','width=' + dsWinW + ',height=' + dsWinH + ',left=' + ((chasm - dsWinW - 10) * .5) + ',top=' + ((mount - dsWinH - 30) * .5) + ',scrollbars=yes,resizable=yes');
}

function leaveComment(id) {
	if (document.getElementById("reviewcomment" + id).style.display == "block") {
		document.getElementById("reviewcomment" + id).style.display = "none";
	} else {
		document.getElementById("reviewcomment" + id).style.display = "block";
	}
}