<!--
/**
 * Read the JavaScript cookies tutorial at:
 *   http://www.netspade.com/articles/javascript/cookies.xml
 */

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



// opens custom window for pfd
function openSpecials() {
	var special = window.open("./index_includes/custom/pfd_specials.php", "special", "location=no,toolbar=no,status=no,scrollbars=no,resizable=yes,width=700,height=500");
	special.opener = window;
}
// opens custom window for vendor list in AE backend 
function openVendorWindow(vendor_id, client_id) {
	if (client_id == "") { client_id = "NULL"; }
	var vendor = window.open("./index_includes/custom/vendor_list.php?vendor_id=" + vendor_id + "&client_id=" + client_id, "vendor", "location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=840,height=760");
	vendor.opener = window;
}
// opens custom window for becky
function openPromotions(series) {
	if (series == 1) { url = "./index_includes/custom/syn_promos1.php"; }
	else { url = "./index_includes/custom/syn_promos2.php"; } 
	var promotional = window.open(url, "promotional", "location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=755,height=800");
	promotional.opener = window;
}
function coeShippingGrid() {
	var shipping = window.open("./index_includes/custom/coe_shipping.php", "shipping", "location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=600,height=500");
	shipping.opener = window;
}
function open830Chat() {
	var chat = window.open("http://www.newclients.com/chat/chatlive.html", "chat", "location=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=625,height=625");
	chat.opener = window;
}

// rotate code for Gillian Moyer bluedragonflymarketing.com
currentImage = 2;
function rotateImages(section) {
	if (document.rotate.complete) {
		document.rotate.src = "./images/14/" + section + "/dragonfly_" + section + "_" + currentImage + ".jpg";
		currentImage++
		if (currentImage == 9 && section != "about") { currentImage = 1; }
		if (currentImage == 10 && section == "about") { currentImage = 1; }
		
	}
	setTimeout("rotateImages('" + section + "')", 2500);
}

// rotation code for MTO mtoonline.com
MTOImage = 1;
function MTOrotate() {
	if (document.MTOrotate.complete) {
		document.MTOrotate.src = "./images/18/rotate/" + MTOImage + ".jpg";
		MTOImage++
		if (MTOImage == 6) { MTOImage = 1; }
	}
	setTimeout("MTOrotate()", 2500);
}

// rotation code for brand candy brandcandyshowcase.com
var holder = "R";
function rotateBrandCandy(holder) {
	if (document.rotateR.complete && document.rotateC.complete && document.rotateL.complete) {
		
		// get all image sources			
		var rightimage  = document.rotateR.src;
		var centerimage = document.rotateC.src;
		var leftimage   = document.rotateL.src;
		
		// setup regexs
		var pattern1   = /(http:\/\/(www\.)?brandcandyshowcase\.com\/images\/17\/rotate\/small_bc)(\d{1})(\.jpg)/;
		var pattern2   = /(http:\/\/(www\.)?brandcandyshowcase\.com\/images\/17\/rotate\/large_bc)(\d{1})(\.jpg)/;
		
		// match patterns
		var finalR = rightimage.match(pattern1);
		var finalC = centerimage.match(pattern2);
		var finalL = leftimage.match(pattern1);
		
		// increase count
		var currentRImage = parseInt(finalR[3]);
		var currentCImage = parseInt(finalC[3]);
		var currentLImage = parseInt(finalL[3]);
		currentRImage++;
		currentCImage++;
		currentLImage++;
		
		// fix overlaps
		if (currentRImage > 4) { currentRImage = 1; }
		if (currentCImage > 6) { currentCImage = 1; }
		if (currentLImage > 4) { currentLImage = 1; }
		
		if (holder == "R") { document.rotateR.src = "./images/17/rotate/small_bc" + currentRImage + ".jpg"; next_one = "C"; }
		if (holder == "C") { document.rotateC.src = "./images/17/rotate/large_bc" + currentCImage + ".jpg"; next_one = "L"; }
		if (holder == "L") { document.rotateL.src = "./images/17/rotate/small_bc" + currentLImage + ".jpg"; next_one = "R"; }
	}
	setTimeout("holder = rotateBrandCandy(holder)", 2500);
	return next_one;
}

function rotateBrandCandyHome(numrows, time, words) {



	var rotateOne = time;
	var rotateTwo = time * 2;
	var rotateThree = time * 3;
	
	if (document.getElementById("boxesContainer")) {
		// change image 1 and switch box colors
		holderOne = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(0, holderOne)', time);
		
		// change image 2 and switch box colors
		holderTwo = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(1, holderTwo)', rotateTwo);

		
		// change image 3, switch box colors, and call function recusively
		holderThree = checkRandomNumber(randomNumber(numrows), numrows);
		setTimeout('changeProduct(2, holderThree)', rotateThree);

		setTimeout("rotateBrandCandyHome(" + numrows + ", " + time + ",words)", rotateThree);
	}

	return true;
}

function showHideSideNav() {

	var menuStatus = document.getElementById("showCats").style.display;

	if (menuStatus == "none") { document.getElementById("showCats").style.display = "block"; }
	else { document.getElementById("showCats").style.display = "none"; }
	
}

function showHideSearch() {

	var menuStatus = document.getElementById("showDogs").style.display;

	if (menuStatus == "none") { document.getElementById("showDogs").style.display = "block"; }
	else { document.getElementById("showDogs").style.display = "none"; }
	
}

function carolinaRotate() {
	setTimeout("carolinaBottomRotate(2)", 5000);
	setTimeout("carolinaTopRotate(2)", 3000);
}

function carolinaTopRotate(number) {
	document.carolinaTop.src = eval("imgT" + number + ".src");
	
	if (number == 10) { number = 1; }
	else { number++; }
	
	setTimeout("carolinaTopRotate(" + number + ")", 3000);
}

function carolinaBottomRotate(number) {
	document.carolinaBottom.src = "./images/carolina/homeBottom/" + number + ".jpg";
	if (number == 14) { number = 1; }
	else { number++; }
	setTimeout("carolinaBottomRotate(" + number + ")", 5000);
}

function blinkButton() {
	if (document.getElementById("button687")) {
		if (document.getElementById("button687").style.display == "none") {
			document.getElementById("button687").style.display = "block";
		} else { document.getElementById("button687").style.display = "none"; }
	}
}
setInterval('blinkButton()', 1500);

// opens custom pdf win for bashas website
function openBashasPDF() {
	var flier = window.open("./pdfs/Bashas_CS_flier.pdf", "flier", "location=no,toolbar=no,status=no,scrollbars=no,resizable=yes,width=700,height=500");
	flier.opener = window;
}
//-->
