function changeParentLocationAndClosePopup(href){
    (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Chrome") != -1)? window.open(href,"_blank") : window.opener.location = href;
    window.close();
}

function selectOrDeselectAllCheckboxInSaleAdmin(select){
    var checboxes = $$('.add_to_sale');
    checboxes.each(function(el){
	el.checked=select;
    });
}
var OrderSearchPage = {
    addBottomArithmeticExpression: function(link){
	var linkName = link.innerHTML;
	var bottimArEx = $('bottom_arithmetic_expression_tr');
	var arExOption = $('arithmetic_expression_arg_tr')
	var bottomInput = $('total_price_bottom_id');

	if(linkName == "add"){
	    link.innerHTML = "remove";
	    bottimArEx.show();
	    arExOption.show();
	}else{
	    link.innerHTML = "add";
	    bottomInput.value = "";
	    bottimArEx.hide();
	    arExOption.hide();
	}

    },
    clearStatusOnOrderSearchPage:function (self,name1,name2,name3,name4,name5,name6){
	var mySelf = $(self);
	var tab = document.getElementsByName(name1);
	var obj1 = $(name2);
	var obj2 = $(name3);
	var obj3 = $(name4);
	var obj4 = $(name5);
	var obj5 = $(name6);
	
	if(mySelf.id == 'status_date_id'){
	    if(mySelf.selectedIndex != 0){
		for (var index = 0; index < tab.length; ++index) {
		    tab[index].checked=false;
		}
		obj5.checked=false;
		obj1.disabled=true;
		obj2.disabled=true;
		obj3.disabled=false;
		obj4.disabled=false;
	    }else{
		obj5.checked=true;
		obj1.disabled=false;
		obj2.disabled=false;
		obj3.disabled=true;
		obj4.disabled=true;
	    }
	}else if(mySelf.id == "activate_date"){
	    $(name1).selectedIndex = 0;
	    obj1.disabled=false;
            obj2.disabled=false;
            obj3.disabled=true;
            obj4.disabled=true;
	}else{
	    $(name1).value = "";
	    obj5.checked=true;
	    obj1.disabled=false;
	    obj2.disabled=false;
	    obj3.disabled=true;
            obj4.disabled=true;
	}
	return false;
    }
}
    
function checkIfContentLoaded(counter) {
    var lwindow = $('lightwindow_contents');
    var div1 = $('mybuyspagezone4');
    var div2 = $('mybuyspagezone3');
    counter = (typeof(counter) == 'undefined') ? 1 : counter;
    var timerId = setTimeout(function() {
	if (div1.empty() && div2.empty()) {
	    checkIfContentLoaded(counter);
	    return false;
	} else {
	    clearInterval(timerId);
	    var cart_height = $('itemInBag').getHeight() + 167 + $('relatedLinksBox').getHeight();
	    if (cart_height != lwindow.getHeight() && $('lightwindow').visible()) {
		AjaxPopup.resizeAjaxPopup(lwindow, cart_height, AJAX_CART_WIDTH);
	    }
	    return true;
	}
    }, 250);
    counter += 1;
    if(counter > 20) {
	clearInterval(timerId);
	return false;
    }
}

function getValueFromCookie(cookie_name) {
    var value = Cookie.getCookie(cookie_name + '2');
    if (value !== null) {
        return value;
    }
    return Cookie.getCookie(cookie_name + '1');
}

function printShoppingBagCount() {
    var numItems = getValueFromCookie('num_items_in_cart');
    if (numItems == null) {
        numItems = 0;
    }
    if (numItems == 0 || location.href.indexOf('checkout_receipt.php') > 0) {
        items = '0 items';
    } else {
        items = numItems + ' item' + (numItems != 1 ? 's': '');
    }
    document.getElementById('shopping-bag-count').innerHTML = items;
}

function getCheckoutUrl(ssl_url,isChangeMethod,isCreditCard) {
    var currentPage = location.href;

    if(isChangeMethod == 1){
      isCreditCard = 1;
    }

    if (currentPage.indexOf('cart.php') > 0 && isCreditCard == 1) {
           return 'href="' + ssl_url + 'checkout_billing.php" onclick="Omniture.abFix();"';
    }
    if(currentPage.indexOf('checkout_receipt') > 0){
	return 'href="#" onclick="Omniture.abFix();"';
    }

    if (currentPage.indexOf('checkout_billing.php') > 0 && currentPage.indexOf('account.php?') > 0) {
        return 'href="/checkout_billing.php" onclick="Omniture.abFix();"';
    }

    if (currentPage.indexOf('checkout_') > 0) {
        return 'href="#" onclick="Omniture.abFix();document.registerfrm.submit();"';
    }
    return 'href="/cart.php" onclick="Omniture.abFix();"';
}

function printCheckoutLink(ssl_url,isChangeMethod,isCreditCard) {
    document.write('<a id="checkout-button" title="Checkout" ' + getCheckoutUrl(ssl_url,isChangeMethod,isCreditCard) + '><span>Checkout</span></a>');
}

var __priceId = 0;
var __registeredPrices = [];

function printLocalPricesOnCatalogPage(template){
    var country_cookie = Cookie.getCookie('country_info');
    var iso_code4  = getCurrencyIsoCode4FromCookie(country_cookie);
    var rate = getRateFromCookie(country_cookie);
    var symbol = getCurrencySymbolFromCookie(country_cookie);
    var is_in_front = getCurrencyIsInFrontFromCookie(country_cookie);
	    
    template = "<span class=\"local_prices\" style=\"display:" + (iso_code4 != "USD" ? "inline" : "none") + "; \">" + template + "</span>";
  	document.write(template.interpolate($A(arguments).slice(1).collect(function(price) {
			__registeredPrices.push(price);
			__priceId = __priceId + 1;
			if(symbol != "" && is_in_front != "N") {
		    return "<span id=\"__priceId_" + (__priceId - 1) + "\">" + symbol + (price * rate).toFixed(2) + (symbol === "$" ? "<small>"+iso_code4+"</small>" : "") + "</span>";
			}
			return "<span id=\"__priceId_" + (__priceId - 1) + "\">" + (price * rate).toFixed(2) +  (symbol != "" ? symbol :  "<small>"+iso_code4+"</small>") + "</span>";
    })));
}

function printLocalPrices(template){
    var country_cookie = Cookie.getCookie('country_info');
    var iso_code4  = getCurrencyIsoCode4FromCookie(country_cookie);
    var rate = getRateFromCookie(country_cookie);
    var symbol = getCurrencySymbolFromCookie(country_cookie);
    var is_in_front = getCurrencyIsInFrontFromCookie(country_cookie);
	    
	    template = "<tr class=\"local_prices\" style=\"display:" + (iso_code4 != "USD" ? "" : "none") + "; \">" + template + "</tr>";
	    document.write(template.interpolate($A(arguments).slice(1).collect(function(price) {
		__registeredPrices.push(price);
		__priceId = __priceId + 1;
		if(symbol != "" && is_in_front != "N"){
		    return "<span id=\"__priceId_" + (__priceId - 1) + "\">" + symbol + (price * rate).toFixed(2) + (symbol === "$" ? "<small>"+iso_code4+"</small>" : "") + "</span>";
		}
		return "<span id=\"__priceId_" + (__priceId - 1) + "\">" + (price * rate).toFixed(2) +  (symbol != "" ? symbol :  iso_code4) + "</span>";
	    })));
}

var __dollarPriceId = 0;
var __registeredDollarPrices = [];

function printDollarPrices(template) {
    var country_cookie = Cookie.getCookie('country_info');
    var usd = "";
    var last_part = "";
    if(country_cookie != null){
	var iso_code4  = getCurrencyIsoCode4FromCookie(country_cookie);
	var symbol = getCurrencySymbolFromCookie(country_cookie);
	if(symbol === "$" && iso_code4 != "USD") {
	    usd = "<small>USD</small>" ;
	    $$(".regprice").invoke("addClassName", "long-name");
	}else{
	    $$(".regprice").invoke("removeClassName", "long-name");
	}
    }
    
    document.write(template.interpolate($A(arguments).slice(1).collect(function(price) {
	__registeredDollarPrices.push(price);
	__dollarPriceId = __dollarPriceId + 1;
  	return "<span id=\"__dollarPriceId_" + (__dollarPriceId - 1) + "\">$" + (price.include(".") ? parseFloat(price).toFixed(2) : price) + usd + "</span>";
    })));
}

function updateDollarPrices(symbol,iso_code4){
		(symbol === "$" && iso_code4 != "USD") ? $$(".regprice").invoke("addClassName", "long-name") : $$(".regprice").invoke("removeClassName", "long-name");

    __registeredDollarPrices.each(function(price,i){
        var node = $("__dollarPriceId_" + i);
        if (node) {
	  		  node.update("$" + (price.include(".") ? parseFloat(price).toFixed(2) : price) + ((symbol === "$" && iso_code4 != "USD")? "<small>USD</small>" : ""));
        } });
    return false;
}

function updateLocalPrices(rate,iso_code4,symbol,is_in_front) {
    $$(".local_prices").invoke(iso_code4 == "USD" ? "hide" : "show");
    
    __registeredPrices.each(function(price,i){
        var node = $("__priceId_" + i);
        if (node) {
	    if(is_in_front != "N" && symbol != ""){
		node.update(symbol+(price * rate).toFixed(2) + (symbol === "$" ? "<small>"+iso_code4+"</small>" : ""));
	    }else{
		node.update((price * rate).toFixed(2)+ (symbol != "" ? symbol : iso_code4));
	    }
        }
    });
}

function isCountryInfoCookieExpired(){
    var country = Cookie.getCookie('country_info');
    var time_from_cookie = getTimeFromCountryCookie(country);
    var current_time = new Date().getTime();
    var milisecond_in_one_day = 86400000;
    return (current_time - time_from_cookie) > milisecond_in_one_day ? true : false;
}

function switchCountry(section,domain){
    var country = Cookie.getCookie('country_info');
    if(country == null || isCountryInfoCookieExpired()){
		new Ajax.Request('/ajax_requests/iso_code3.php', {
	    method: 'get',
			onSuccess: function(transport) {
		Cookie.setCookie('country_info',transport.responseText + '|' + new Date().getTime(),0,'/',domain);
		var countryCode = getCountryCodeFromCookie(transport.responseText);
		switchFlag(countryCode);
		var symbol = getCurrencySymbolFromCookie(transport.responseText);
		var iso_code4 = getCurrencyIsoCode4FromCookie(transport.responseText);
		var currency_rate = getRateFromCookie(transport.responseText);
		var is_in_front = getCurrencyIsInFrontFromCookie(transport.responseText);
		updateLocalPrices(currency_rate,iso_code4,symbol,is_in_front);
	    }});
    }else{
	var countryCode = getCountryCodeFromCookie(country);
	switchFlag(countryCode);
	switchHeader(countryCode);
    }
}

function getRateFromCookie(cookie_value) {
		if(cookie_value != null) {
  	  var result = cookie_value.split('|');
    	return result[2];
	}
	return '';
}

function getCurrencyIsoCode4FromCookie(cookie_value) {
    if(cookie_value != null){
			var result = cookie_value.split('|');
			return result[3];
    }
    return '';
}

function getCountryCodeFromCookie(cookie_value) {
    var result = cookie_value.split('|');
    return result[0];
}

function getCurrencyIsInFrontFromCookie(cookie_value) {
		if(cookie_value != null){
	    var result = cookie_value.split('|');
  	  return result[5] || "";
	}	
	return '';
}

function getIpFromCookie(cookie_value) {
    var result = cookie_value.split('|');
    return result[1] || '';
}
function getCurrencySymbolFromCookie(cookie_value) {
		if(cookie_value != null){
	    var result = cookie_value.split('|');
 	   return result[4] || "";	
	}
  return '';
}
function getTimeFromCountryCookie(cookie_value){
    var result = cookie_value.split('|');
    return result[6];
}

function switchFlag(country_code){
    var countryNodes = document.getElementsByClassName('flags active');
    for(var i = 0; i < countryNodes.length; i++) {
       countryNodes[i].className = "flags";
    }
    document.getElementById('flag_' + country_code).className += " active";
}

function switchHeader(country_code){
    var countryNodes = document.getElementsByClassName('fs_header active');
    for(var i = 0; i < countryNodes.length; i++) {
       countryNodes[i].className = "fs_header";
    }
    document.getElementById('header_' + country_code).className += " active";
}

function updateShippingImages(section){
    var url = '/ajax_requests/flag_image.php';
    new Ajax.Updater('country_flag', url, {asynchronous: true,evalScripts: true});    

    var url2 = '/ajax_requests/header_image.php?section=' + section;
    new Ajax.Updater('shipping_header_image', url2, {asynchronous: true,evalScripts: true});    
}

var updateCookiesCallbacks = [];	

function updateCookieAndShippingImages(iso_code3,section,domain,is_on_secure_page,currency_rate,iso_code4,symbol,is_in_front){
    var countryAndIp = Cookie.getCookie('country_info');
    var ip = getIpFromCookie(countryAndIp);
    var time = new Date().getTime();
    var newCookie = iso_code3 + '|' + ip + '|' + currency_rate + '|' + iso_code4 + '|' + symbol + '|' + is_in_front + '|' + time;
    Cookie.setCookie('country_info',newCookie,0,'/',domain);
    if(is_on_secure_page=='1'){
	updateShippingImages(section);
	reloadCurrencyOnCheckoutPayment();
    }else{
	switchFlag(iso_code3);
	switchHeader(iso_code3);
 	updateDollarPrices(symbol,iso_code4);
	updateLocalPrices(currency_rate,iso_code4,symbol,is_in_front);
	reloadCountryPaymentMethod();
    }
    updateCookiesCallbacks.each(function(fun) {fun.call(); });
}


function addUpdateCoockiesCallback(callback) {
   updateCookiesCallbacks.push(callback);	
}

function clearUpdateCoockiesCallbacks() {
   updateCookiesCallbacks.clear();
}
    
function addUpdateCoockiesCallback(callback) {
    updateCookiesCallbacks.push(callback);
}

function reloadCurrencyOnCheckoutPayment(){
    if (location.href.indexOf('checkout_payment.php') > 0){
	target = 'shopping_cart_table_wrapper';
	
	var url = 'ajax_requests/update_payment_method.php?change_method=N';
	new Ajax.Updater(target, url, {
	    asynchronous: true,
			      evalScripts: true,
			      onComplete: function() {new Ajax.Updater('shipping_type','ajax_requests/update_shipping_currency.php');}
	    
	});
    }
}

function reloadCountryPaymentMethod(){
    var currentPage = location.href;
    if(currentPage.indexOf('cart.php') > 0 || currentPage.indexOf('cart.php?e=t') > 0){
	var  page = "cart.php";
	var target = 'shopping_cart_table_wrapper';
	var url = 'ajax_requests/update_payment_method.php';
	new Ajax.Updater(target, url, {
	asynchronous: true,
	evalScripts: true
    });
    }
}

//footer newsletter signup 
function clearSignup(t) {
    clearFormField(t,"Enter Email Address");
}

function clearSearchBox(t){
    clearFormField(t,"Search");
}

function clearFormField(input,value){
    if(input.value == value){
        input.value = "";
    }
}

//legacy methods
function popUp(url) {
    sealWin = window.open(url, "win", 'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
    self.name = "mainWin";
}

function newWd(page, width, height, popup_name) {
    popup_name = typeof(popup_name) == 'undefined' ? 'BigPic' : popup_name;
    newwin = window.open(page, popup_name, 'left=20,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height);
    newwin.focus();
}

function newWdR(page, width, height) {
    newwin = window.open(page, 'BigPic', 'left=20,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height);
    newwin.focus();
}

function newWdS(page, width, height) {
    newwin = window.open(page, 'Freshpair', 'left=20,top=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
    newwin.focus();
}

function newWdF(page, width, height) {
    newwin = window.open(page, 'Freshpair', 'left=20,top=20,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
    newwin.focus();
}

function newWdE(page, width, height) {
    var putItThere = null;
    var chasm = screen.availWidth;
    var mount = screen.availHeight;
    var w = 0;
    var h = 0;

    newwin = window.open(page, 'BigPic', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5));
    newwin.focus();
}

function resizeWindowByElementId(elementId) {
    var element = document.getElementById(elementId);
    if(element){
	iWidth = element.offsetWidth - getWindowWidth();
	iHeight = element.offsetHeight - getWindowHeight();
	window.resizeBy(iWidth, iHeight);
    }
}

function getWindowWidth(){
    if(typeof(window.innerWidth) == 'number' ) { //Non-IE
	return window.innerWidth;
    } else if(document.documentElement && document.documentElement.clientWidth){ //IE 6+ in 'standards compliant mode'
	return document.documentElement.clientWidth;
    } else if(document.body && document.body.clientWidth){ //IE 4 compatible
	return document.body.clientWidth;
    }
    return 0;
}

function getWindowHeight(){
    if(typeof(window.innerHeight) == 'number' ) { //Non-IE
	return window.innerHeight;
    } else if(document.documentElement && document.documentElement.clientHeight){ //IE 6+ in 'standards compliant mode'
	return document.documentElement.clientHeight;
    } else if(document.body && document.body.clientHeight){ //IE 4 compatible
	return document.body.clientHeight;
    }
    return 0;
}

function getURLParam(strParamName) {
    var strReturn = "";
    var strHref = window.location.href;
    if (strHref.indexOf("?") > -1) {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}

function setMasterSizeCookie(master_size_id,category_id){
    var value = master_size_id + '|0|' + category_id;
    setPreferencesCoookie(value);
}

function setAliasCookie(alias_id,category_id){
    var value = '0|' + alias_id + "|" + category_id;
    setPreferencesCoookie(value);
}

function setPreferencesCoookie(value) {
    var aliasCookie = Cookie.getCookie('preferences');
    var master_size_id = value.split("|")[0];
    var alias_id = value.split("|")[1];
    var category_id = value.split("|")[2];
    if(aliasCookie) {
	var chunks = aliasCookie.split(";");

	var master_size_id_from_cookie;
	var alias_id_from_cookie;
	var category_id_from_cookie;
	
	var newCookie = new Array();
	for(var i = 0; i < chunks.length; i++){

	    master_size_id_from_cookie = chunks[i].split("|")[0];
	    alias_id_from_cookie = chunks[i].split("|")[1];
	    category_id_from_cookie = chunks[i].split("|")[2];

	    if(category_id_from_cookie != category_id && (master_size_id_from_cookie != master_size_id || alias_id_from_cookie != alias_id)) {
		newCookie.push(chunks[i]);
	    }
	}
	newCookie.push(value);
	newCookieValue = newCookie.join(';');
    } else {
	newCookieValue = value;
    }
    Cookie.setCookie('preferences',newCookieValue,0,'/');
}

function submitDeptMenu(t){
    var size_dropdown = t.form.alias_id;
    if(size_dropdown.type == 'select-one') {
	alias_id = size_dropdown.options[t.form.alias_id.selectedIndex].value;
	var category_id = t.form.id.value;
	setAliasCookie(alias_id,category_id);
    }
    
    if (typeof(t.form["occasion"])!="undefined"){
        if (t.form["id"].value=="" && t.form["occasion"].value!=""){
            t.form["occasion"].value="";
        }
    }
    t.form.submit();
}

function goToBackLink(){
    if (window.location.pathname.split('/').length == 2) { //is item page
	var cookie = Cookie.getCookie('referring_page');
	if(cookie){
	    window.location = cookie;
	    return false;
	}
	window.location = '/';
    }
    return false;
}

function openFreeShippingPopup(country_code){
    var cookie = Cookie.getCookie('fs_popup');
    var query_string = '';
    if(cookie){
	var data = cookie.split('|');
	query_string = '&id='+data[0];
    }
    AjaxPopup.showSimplePopup('/popup_shipping.php?code_of_country=' + country_code + query_string, {width:445,resize_x:false});
}

function creteReacapthaImage(popup){
    if(document.getElementById('recaptcha'+popup)){
	Recaptcha.create("6LfSEwYAAAAAAIDpQYAI312rsTz90EMGofFKCSPb", 'recaptcha'+popup, {
	    theme: 'red',
	    tabindex: 0,
	    callback: Recaptcha.focus_response_field
	});
	}
}


/* SPANX */

function switchTab(new_tab_id){
    $$('div.tab_content').each(function(element){
	element.style.display='none';
    });
    $(new_tab_id).style.display = 'block';
}

function toogleImageForContainer(content_container_name,image_path,label,link,element){
    $$('#' + content_container_name + '_content' + ' img')[0].src = image_path;
    $$('#' + content_container_name + '_content' + ' p')[0].innerHTML = label;
    var style_link = $$('#' + content_container_name + ' a')[0];
    if(link != ''){
	style_link.onclick = new Function("executeSpanxLink('"+link+"');return false;");
	style_link.style.display = 'block';
    }else{
	style_link.style.display = 'none';
    }
    var paragraphs = $$('#' + content_container_name + ' .paragraphs p');
    paragraphs.each(function(i){
	i.className = '';
    });
    element.parentNode.className = 'active';
}

function toogleImageForSubspan(content_container_name,image_path,label,link,element){
    $$('#' + content_container_name + '_content' + ' img')[0].src = image_path;
    $$('#' + content_container_name + '_content' + ' p')[0].innerHTML = label;
    var style_link = $$('#' + content_container_name + ' a')[0];
    if(link != ''){
	style_link.href = link;
	style_link.style.display = 'block';
    }else{
	style_link.style.display = 'none';
    }
    var paragraphs = $$('#' + content_container_name + ' .paragraphs p span.active');
    paragraphs.each(function(i){
	i.className = 'subparagraph';
    });
    element.parentNode.className = 'active';
}

function toogleSizechart(label,image_path){
    $$('#sizing_info_sizecharts img')[0].src = image_path;
    $$('#sizing_info_sizecharts p')[0].innerHTML = label;
}

function executeSpanxLink(href){
    window.opener.location = href;
    window.close();
}

function showFlowPlayer() {
    flowplayer("player", "/fp_content/swf/flowplayer/flowplayer.commercial-3.1.1.swf", {
	key: $("player").getAttribute('key'),
	clip: {
	    autoPlay: false,
	    autoBuffering: false
        }
    });
}

function offsetCalvinKleinEntry(offset,limit,operation){
    var offset = offset;
    var limit = limit;
    if(operation == "next"){
	var newOffset = offset + limit;
    }else{
	var newOffset = offset - limit;
    }
    var page = $('ck-content');
    var url = '/underwear-day-2009/Calvin-Klein.php?offset=' + newOffset;
    new Ajax.Updater(page, url, {
                                 asynchronous: true,
                                 evalScripts: true
				});

}

function checkCountryMethodPayment(countryLive,methodPaymentCreditCard,methodPaymentPaypal,self){

    var isCountryLive = $(countryLive);
    var methodPaymentCreditCard = $(methodPaymentCreditCard);
    var methodPaymentPaypal = $(methodPaymentPaypal);
    if(isCountryLive.checked && !methodPaymentCreditCard.checked && !methodPaymentPaypal.checked){
	alert("You can't switch off this method becouse Country will be without any payment method");
    }
}

function loadScript(url) {
    var newScript = document.createElement("script");
    var head = document.getElementsByTagName("head")[0];
    newScript.setAttribute("type", "text/javascript");
    newScript.setAttribute("src", url);
    head.appendChild(newScript);
}

function toggleElement(id) {
    if($(id)) {
	if($(id).style.display == 'none') {
	    $(id).show();
	} else {
	    $(id).hide();
	}
    }
}


/****** COOKIES LIBRARY ******/

function CookieClass() {};

var Cookie = new CookieClass;
/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.1
Last Update: 4 October 2007

Changes:
1.1.1 fixes a problem with Get_Cookie that did not correctly handle case
where cookie is initialized but it has no "=" and thus no value, the 
Get_Cookie function generates a NULL exception. This was pointed out by olivier, thanks

1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
CookieClass.prototype.getCookie = function(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f
    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');

        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
};

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
CookieClass.prototype.setCookie = function(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());
    // if the expires variable is set, make the correct expires time, the
    // current script below will set it for x number of days, to make it
    // for hours, delete * 24, for minutes, delete * 60 * 24
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
    var expires_date = new Date(today.getTime() + (expires));
    //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
    document.cookie = name + "=" + escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + //expires.toGMTString()
    ((path) ? ";path=" + path: "") + ((domain) ? ";domain=" + domain: "") + ((secure) ? ";secure": "");
};

// this deletes the cookie when called
CookieClass.prototype.deleteCookie = function(name, path, domain) {
    if (this.getCookie(name)) document.cookie = name + "=" + ((path) ? ";path=" + path: "") + ((domain) ? ";domain=" + domain: "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
/****** END OF COOKIES ******/


/****** VERISIGN ******/
dn="SECURE.FRESHPAIR.COM";lang="en";aff="VeriSignCACenter";tpt="transparent";vrsn_style="WW";splash_url="https://seal.verisign.com";seal_url="https://seal.verisign.com";u1=splash_url+"/splash?form_file=fdf/splash.fdf&dn="+dn+"&lang="+lang;u2=seal_url+"/getseal?at=0&&sealid=1&dn="+dn+"&aff="+aff+"&lang="+lang;function vrsn_splash(){tbar="location=yes,status=yes,resizable=yes,scrollbars=yes,width=560,height=500";sw=window.open(u1,'VRSN_Splash',tbar);sw.focus();}
v_ua=navigator.userAgent.toLowerCase();v_oie=(v_ua.indexOf("msie")!=-1);if(v_oie)v_oie=(v_ua.indexOf("msie 5")==-1&&v_ua.indexOf("msie 6")==-1);function v_mact(e){if(document.addEventListener){var s=(e.target.name=="seal");if(s){vrsn_splash();return false;}}else if(document.captureEvents){var tgt=e.target.toString();var s=(tgt.indexOf("splash")!=-1);if(s){vrsn_splash();return false;}}
return true;}
function v_mDown(){if(event.button==1){if(v_oie){return true;}else{vrsn_splash();return false;}}else if(event.button==2){vrsn_splash();return false;}}
function printVerisignImage(seal_path){document.getElementById('verisign').innerHTML="<a HREF=\""+u1+"\" tabindex=\"-1\" onmousedown=\"return v_mDown();\" target=\"VRSN_Splash\"><IMG NAME=\"seal\" BORDER=\"true\" SRC=\""+seal_path+"\" oncontextmenu=\"return false;\" alt=\"This Web site has chosen one or more VeriSign SSL Certificate or online payment solutions to improve the security of e-commerce and other confidential communication\"></A>";if(document.addEventListener){document.addEventListener('mouseup',v_mact,true);}
else{if(document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=v_mact;}}
function v_resized(){if(pageWidth!=innerWidth||pageHeight!=innerHeight){self.history.go(0);}}
if(document.layers){pageWidth=innerWidth;pageHeight=innerHeight;window.onresize=v_resized;}}
/****** END OF VERISIGN ******/
