/**
* @fileoverview ebiz.js: A module used for client specific functionality
*
* This module defines a single symbol named "Venda.Ebiz"
* all ebiz utility functions are stored as properties of this namespace
* functions that are spacific this site shoudl be added to this file only.
*/

//Declare namespace for ebiz
Venda.namespace("Ebiz");

/**
 * The following global variables (directly below) are NEEDED to support legacy javascript functions - DO NOT REMOVE! see RT#113376 for more details.
 * 1. shown
 * 2. hidden
 */

var shown = new Image();
shown.src = "/venda-support/images/bulleton.gif";
var hidden = new Image();
hidden.src = "/venda-support/images/bulletoff.gif";

/**
 * Split a string so it can be displayed on multiple lines so it does not break display layout - used on order confirmation and order receipt page
 * @param {string} strToSplit string that needs to be split 
 * @param {Integer} rowLen length of row which will hold the string
 * @param {string} displayElem the html container which will display the splitted string
 */
Venda.Ebiz.splitString = function(strToSplit, rowLen, dispElem) {
    var stringlist = new Array();
    while (strToSplit.length > rowLen) {
        stringlist.push( strToSplit.slice(0,rowLen));
        strToSplit=strToSplit.substr(rowLen);
    }
    if (strToSplit.length) {
        stringlist.push(strToSplit);
    }
    document.getElementById(dispElem).innerHTML = stringlist.join('<br>');
};

/**
 * A skeleton function for validating user extened fields - needs to be amended by the build team
 * @param {object} frmObj HTML form containing user extended field elements
 */


// For Linkshare Tracking tag
//Description: Returns the value of a specified URL parameter 
//Parameters:
//1. currURL = this is the URL which you wish to get the URL parameter value from
//2. urlParam = this is the name of the URL parameter you want to get the value for
//Returns: value for parameter specified urlParam.
function grabURL(currURL,urlParam) {
    //find out a value where is passed from current url
    var url = unescape(currURL);
    var spliter = '&';
    var sField = spliter+urlParam+'=';
	
    if (url.search(sField) == -1) {               
        sField = '?'+urlParam+'=';         
    }
	
    var urlArray = url.split(sField);
    if (urlArray[1]) {
        //get url param value
        var paramArray = urlArray[1].split(spliter);
        return(paramArray[0]);
    }
};
function createCookie(name,value,days) {
    if (days){
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
};
 
function getCookie(c_name){
    if (document.cookie.length>0){
        c_start = document.cookie.indexOf(c_name + "=");
  	 
        if (c_start!=-1){
            c_start = c_start + c_name.length+1;
            c_end = document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return null
};
function replaceData(s){
    var sdata=s;
    sdata=sdata.replace(/\+/g, '-');
    sdata=sdata.replace(/\//g, '_');
    return sdata;
};
  	 
function delete_cookie( cookie_name ){
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime());
    document.cookie = cookie_name+"=; expires=" + cookie_date.toGMTString()+"; path=/";
    return true;
};

/**
 * A sendEmailSignup function for sending Email to Newsletter page. 
 * @param {object} frmObj HTML form containing email address
 * @param {string} msg the Message that would like to alert when enter wrong email
 * @param {string} catlevel the Category level 1 of each category or product
 */
Venda.Ebiz.sendEmailSignup = function(frmObj,msg,catlevel) {
    if (checkemail(frmObj.email.value)) {
        if (catlevel==""){
            catlevel = Venda.Platform.getUrlParam(window.location.href,'termtextcatrestrict');
        }
        frmObj.action = frmObj.action + "&inputemail=" + frmObj.email.value + "&catlevel=" + catlevel;
        frmObj.submit();
    } else {
        alert(msg);
        frmObj.email.focus();
    }
};

/**
 * A addBasketDelivery function for adding standard delivery on Basket page.
 * @param {number} subtotal Number that translate from <venda_extsub>
 * @param {number} standardrate Number that get from order over subtotal of each order
 * @param {number} rate Number that translate from <venda_ohship>
 * @param {string} currsym the Current currency.
 * @param {string} estimatedtax the html container which will display the standard delivery rate
 * @param {string} baskettotal the html container which will display the order total
 */
Venda.Ebiz.addBasketDelivery = function(subtotal,standardrate,rate,currsym,estimatedtax,baskettotal) {
    if (rate == "0.00") {
        var standardrate = new Number(standardrate);
        estimatedtax.innerHTML = currsym + standardrate.toFixed(2);
        var subtotal = new Number(subtotal);
        var ordertotal = new Number(subtotal + standardrate);
        ordertotal = ordertotal.toFixed(2);
        baskettotal.innerHTML = currsym + ordertotal;
    }else {
        var rate = new Number(rate);
        estimatedtax.innerHTML = currsym + rate.toFixed(2);
        var subtotal = new Number(subtotal);
        var ordertotal = new Number(subtotal + rate);
        ordertotal = ordertotal.toFixed(2);
        baskettotal.innerHTML = currsym + ordertotal;
    }
};

Venda.namespace("Ebiz.catwalk");
Venda.Ebiz.catwalk=function(){};
Venda.Ebiz.catwalk.init=function(config){	
    this.catwalkwrapper=config[0];
    this.catwalk_link=config[1];
    this.productdetail_catwalk=config[2];
    this.productdetail_image=config[3];
    this.catwalklabel=jQuery("#"+config[4]).html();
    this.imglabel=jQuery("#"+config[5]).html();
    this.player=config[6];
    this.player_w=config[7];
    this.player_h=config[8];
    this.flashvars=config[9];
    this.flashparams=config[10];
    this.flashattributes=config[11];
    this.overlay_largeicon=config[12];
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).bind("click",Venda.Ebiz.catwalk.show);
};
Venda.Ebiz.catwalk.show=function(){
    var flashvars = Venda.Ebiz.catwalk.flashvars;
    var params = Venda.Ebiz.catwalk.flashparams;
    var attributes = Venda.Ebiz.catwalk.flashattributes;
    jQuery(".invtmedia .overlay,#"+Venda.Ebiz.catwalk.productdetail_image).hide();
    jQuery("#"+Venda.Ebiz.catwalk.overlay_largeicon).hide();
    jQuery("#"+Venda.Ebiz.catwalk.catwalkwrapper).show();
    jQuery("#productdetail-viewlarge").hide();
    swfobject.embedSWF(Venda.Ebiz.catwalk.player, Venda.Ebiz.catwalk.productdetail_catwalk, 
        Venda.Ebiz.catwalk.player_w,  Venda.Ebiz.catwalk.player_h, "9.0.0","expressInstall.swf", 
        flashvars, params, attributes);	
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).unbind("click",Venda.Ebiz.catwalk.show);
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).bind("click",Venda.Ebiz.catwalk.hide);
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).html(Venda.Ebiz.catwalk.imglabel);
    return false;
};
Venda.Ebiz.catwalk.hide=function(){
    jQuery("#"+Venda.Ebiz.catwalk.catwalkwrapper).hide();
    jQuery("#"+Venda.Ebiz.catwalk.overlay_largeicon).show();
    jQuery("#productdetail-viewlarge").show();
    jQuery(".invtmedia .overlay,#"+Venda.Ebiz.catwalk.productdetail_image).show();
    jQuery("#"+Venda.Ebiz.catwalk.catwalkwrapper).html('<div id="'+Venda.Ebiz.catwalk.productdetail_catwalk+'"></div>');
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).unbind("click",Venda.Ebiz.catwalk.hide);
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).bind("click",Venda.Ebiz.catwalk.show);
    jQuery("#"+Venda.Ebiz.catwalk.catwalk_link).html(Venda.Ebiz.catwalk.catwalklabel);
    return false;
};
function fnOpenWishlist(objX){
    window.parent.location = "/bin/venda/?ex=co_wizr-giftlist&bsref=wwrdus&step=glstlist&layout=myaccount";
};

allDeliveryData = [];
var loaddeliveryData = function(delOpt,data) {
    allDeliveryData[delOpt] = data;
};

var getEstimateDate = function(shipmethoddate,satFlag){
    var today = new Date();
    var weekday=new Array(7);
    weekday[0]="Sunday";
    weekday[1]="Monday";
    weekday[2]="Tuesday";
    weekday[3]="Wednesday";
    weekday[4]="Thursday";
    weekday[5]="Friday";
    weekday[6]="Saturday";
    var todaytemp;
    var todayWeekday;
    var shipmethoddatetmp=0;
    var newshipmethoddate=0;
    todaytemp = new Date();
    /* loop for calculate real padding date */
    do{	
        newshipmethoddate++;
        todaytemp.setDate(today.getDate()+newshipmethoddate);		
        if(satFlag == 0){
            if(todaytemp.getDay()!=0 && todaytemp.getDay()!=6){
                shipmethoddatetmp++;
            }
        }else{
            if(todaytemp.getDay()!=0){
                shipmethoddatetmp++;
            }
        }
    }while(shipmethoddatetmp<shipmethoddate);
    todaytemp = new Date(today.setDate(today.getDate()+newshipmethoddate));
    todayWeekday=todaytemp.getDay();
    var todaytemp1 = (todaytemp.getMonth()+1) +"/"+ todaytemp.getDate() +"/"+ todaytemp.getFullYear();
    if (shipmethoddate && shipmethoddate!="undefined" && todaytemp1 !="" && todaytemp1 != "undefined"){
        document.getElementById('shipmethoddate'+x).innerHTML = todaytemp1;
    }
};
var EstimateDateToday = new Date();
var getEstimateDateGiftWrap = function(shipmethoddate,satFlag){
    var todaytemp;
    var todayWeekday;
    var shipmethoddatetmp=0;
    var newshipmethoddate=0;
    today = new Date(EstimateDateToday);
    todaytemp = new Date(EstimateDateToday);
    /* loop for calculate real padding date */
    do{	
        newshipmethoddate++;
        todaytemp.setDate(EstimateDateToday.getDate()+newshipmethoddate);		
        if(satFlag == 0){
            if(todaytemp.getDay()!=0 && todaytemp.getDay()!=6){
                shipmethoddatetmp++;
            }
        }else{
            if(todaytemp.getDay()!=0){
                shipmethoddatetmp++;
            }
        }
    }while(shipmethoddatetmp<shipmethoddate);
    todaytemp = new Date(today.setDate(today.getDate()+newshipmethoddate));
    todayWeekday=todaytemp.getDay();
    var year=todaytemp.getFullYear()+"";
    var date=todaytemp.getDate()+"";
    var month=todaytemp.getMonth()+1;
    month=month+"";
    year=year.substr(2,2);
    month=(month.length==1)?"0"+month:month;
    date=(date.length==1)?"0"+date:date;
    var todaytemp1 = month +"-"+ date +"-"+ year;
    return todaytemp1;
};
/*
Venda.Ebiz.Qty function, get minqty, deliverymultiple and product name from product detail and compare with current qty.
Venda.Ebiz.Qty.minqty : default minimum qty =1 
Venda.Ebiz.Qty.deliverymultiple: default delivery multi qty =1 
Venda.Ebiz.Qty.productname:  product name
*/
Venda.namespace("Ebiz.Qty");
Venda.Ebiz.Qty.minqty=1;
Venda.Ebiz.Qty.deliverymultiple=1;
Venda.Ebiz.Qty.productname="";
Venda.Ebiz.Qty.errorminqty="You must have a minimum qty of [minqty] for '[productname]'";
Venda.Ebiz.Qty.errordeliverymultiple="You must buy '[productname]' in multiples of [deliverymultiple]";
Venda.Ebiz.Qty.validate = function(sender){
    Venda.Ebiz.Qty.productname=jQuery(sender.form).find("#invtname").text();
    if(typeof(sender.form.deliverymultiple)!="undefined" && sender.form.deliverymultiple.value!=""){
        Venda.Ebiz.Qty.deliverymultiple=sender.form.deliverymultiple.value;
    }
    if(typeof(sender.form.minorderqty)!="undefined" && sender.form.minorderqty.value!=""){
        Venda.Ebiz.Qty.minqty=sender.form.minorderqty.value;
    }
    var currentQty=parseInt(sender.form.qty.value);
    if(currentQty < parseInt(Venda.Ebiz.Qty.minqty)){
        /* fail: qty >= minimum and qty mod Multi Delivery != 0 */
        var errormsg=Venda.Ebiz.Qty.errorminqty;
        errormsg=errormsg.replace("[minqty]",Venda.Ebiz.Qty.minqty);
        errormsg=errormsg.replace("[productname]",Venda.Ebiz.Qty.productname);
        alert(errormsg);
        return false;
    }
    if((currentQty%parseInt(Venda.Ebiz.Qty.deliverymultiple)) !=0){
        var errormsg=Venda.Ebiz.Qty.errordeliverymultiple;
        errormsg=errormsg.replace("[deliverymultiple]",Venda.Ebiz.Qty.deliverymultiple);
        errormsg=errormsg.replace("[productname]",Venda.Ebiz.Qty.productname);
        alert(errormsg);
        return false;
    }	
    return true;
};

/**
 * A language switch
 */
var doURL = function(repVal,newRepVal,cLog,desT){
    var cDes = jQuery("#ebizurl").text()+ "/ae/" + newRepVal + "/icat/" + desT + cLog;
    window.location.href = cDes;
};
function curLangSwitch(selRegion, uType, desT){
    var currRegion = jQuery("#currRegion").html();
    var chlogoff = "";
    if((selRegion != "") && (selRegion != currRegion)){ 
        if(uType == "R"){
            if(confirm(jQuery("#logonmessage").text())){
                chlogoff = "?log=4";
                doURL(currRegion,selRegion,chlogoff,desT);
            }
            else{
                return false;
            }
        }
        else if(jQuery("#updateItems").text() != "0"){
            if(confirm(jQuery("#confirmmessage").text())){
                doURL(currRegion,selRegion,chlogoff,desT);
            }
            else{
                return false;
            }
        }
        else{
            doURL(currRegion,selRegion,chlogoff,desT);
        }
    }
    else{
        doURL(currRegion,selRegion,chlogoff,desT);
    //return false;
    }
};
/**
* Media Code
* Hide noscript comment
* Add listeners to media code form elements
*/
var jq = jQuery.noConflict();
jq(document).ready(function(){
    jq(".nonjs").css("display","none");
});

/**
* Media Code
* Validate and submit media code using ajax if not on basket for in-page display
* Update minicart figures with ajax too if not on basket

Venda.Ebiz.checkVoucherForm = function(defaulttext) {
	var str = jq("#vcode").val();
	str = jQuery.trim(str);
	if(jq("#vcode_submit_shopcart").length > 0){ //if on workflow
		if(str === '' || str === defaulttext) {
			alert(jq("#tag-alert").html());
		} else {
			jq("#vcode").val(str.toLowerCase());
			// instead of submit, submit in background to check for errors
			if (document.createElement) {
				var oScript = document.createElement("script");
				oScript.type = "text/javascript";
				oScript.src = jq("#tag-protocol").html()+"?ex=co_wizr-vouchercode&curstep=vouchercode&step=next&mode=process&curlayout=errors&layout=errors&vcode="+jq("#vcode").val()+"&action=overwrite";
				document.getElementById("ajax-error").appendChild(oScript);
			}
		}
	}
};
Neway Tech ReviewPayReceipt
 */


Venda.Ebiz.checkVoucherForm = function(defaulttext, workflow) {
    var str = jq("#vcode").val();
    str = jQuery.trim(str);
    if(jq("#vcode_submit_shopcart").length > 0){ //if on workflow
        if(str === '' || str === defaulttext) {
            alert(jq("#tag-alert").html());
        } else {
            // Center panel on screen            
            jQuery('#promoPanel').css('visibility','visible');            
            jQuery('#promoPanel').css("left", ((jQuery(window).width() - jQuery('#promoPanel').outerWidth()) / 2) + jQuery(window).scrollLeft() + "px");

            jq("#vcode").val(str.toUpperCase());
            // instead of submit, submit in background to check for errors
            if (document.createElement) {
                var oScript = document.createElement("script");
                oScript.type = "text/javascript";

                if(workflow == 'orcf-screen'){
                    oScript.src = jq("#tag-protocol").html()+"?ex=co_wizr-vouchercodeorderconfirm&curstep=vouchercode&step=next&mode=process&curlayout=errorsorderconfirm&layout=errorsorderconfirm&vcode="+jq("#vcode").val()+"&action=add";
                } else {
                    oScript.src = jQuery('#tag-protocol').html()+'?ex=co_wizr-vouchercode&curstep=vouchercode&step=next&mode=process&curlayout=errors&layout=errors&vcode='+jQuery("#vcode").val()+'&action=add';
                }
                document.getElementById("ajax-error").appendChild(oScript);
            }            
        }               
    }
};

Venda.Ebiz.validateGiftcode = function(formName, msg) {
    if (document.forms[formName].giftcode.value == ""){
        alert(msg);
        document.forms[formName].giftcode.focus();
        return false;
    }
    Step2(document.forms[formName],"confirm","process","show","giftcert","_self","","","","");
};



/**
* Clear promotion on Unload window / Log out
*/
function clearPromo(destT){
    var destinationPath = destT;
    if(destinationPath){
        ajaxFunction('/bin/venda?ex=co_wizr-shopcart&curstep=handle_vouchercode&step=handle_vouchercode&mode=process&action=delete','currLang',null,function(){
            window.location.href = destinationPath;
        });
    }
    else{
        ajaxFunction('/bin/venda?ex=co_wizr-shopcart&curstep=handle_vouchercode&step=handle_vouchercode&mode=process&action=delete','currLang',null,function(){/* nothing */});
    }
};

/* custom function to reset EqualHeight once click on More/Less link on Refine */
function RenderEqualHeight(){
    jQuery('#col-one,#searchresults .prods,#productlist .products').removeAttr("style");
    /*jQuery('#col-one').removeAttr("style");
	jQuery('#searchresults .prods').removeAttr("style");
	jQuery('#productlist .products').removeAttr("style");*/
    if(typeof Venda.Platform.EqualHeight == "function"){
        var classtoset = new Array ('#col-one,#productlist .products','#col-one,#searchresults .prods');
        Venda.Platform.EqualHeight.init(classtoset);
        if(jQuery("#productlist .products").length>0){
            jQuery("#productlist .products").css((Venda.Platform.EqualHeight.jq.browser.msie && Venda.Platform.EqualHeight.jq.browser.version < 7 ? '' : 'min-') + 'height', parseInt(jQuery("#productlist .products").css((Venda.Platform.EqualHeight.jq.browser.msie && Venda.Platform.EqualHeight.jq.browser.version < 7 ? '' : 'min-') + 'height'),10)-160);
        }
        if(jQuery("#searchresults .prods").length>0){
            jQuery("#searchresults .prods").css((Venda.Platform.EqualHeight.jq.browser.msie && Venda.Platform.EqualHeight.jq.browser.version < 7 ? '' : 'min-') + 'height', parseInt(jQuery("#searchresults .prods").css((Venda.Platform.EqualHeight.jq.browser.msie && Venda.Platform.EqualHeight.jq.browser.version < 7 ? '' : 'min-') + 'height'),10)-240);
        }
    }
};


// Add Class
jQuery(document).ready(function(){
    jQuery(".ordertable tbody tr:first").addClass("first");
    //jQuery(".orderitems .wizrtable tbody tr:last").addClass("last");
    jQuery(".orderitems:last").addClass("orderlast");
    jQuery(".orderitems tbody").find("tr:last").addClass("last");
    jQuery("#ordersummary .orderdetails tbody tr:last").addClass("last");
    jQuery(".giftwrapitem").eq(0).addClass("first");
    jQuery(".giftwrapitem:last").addClass("last");
    jQuery("#paymentdetails tbody tr:last").addClass("last");
    jQuery(".ohSumDetail table tr:last").addClass("last");
});

/* IP GEO - start */
/**
 * Set region/location if user has no cookie set
 * when notify in URL, trigger function checkNotify
 * @param {string} venda_serveradd tag
 */
Venda.Ebiz.pushLocation = function(domain) {
    var vendaLocation = YAHOO.util.Cookie.get("locn"); //set by venda
    if(vendaLocation===null){
        // if venda location not set use Maxmind's JS to detect country
        var countryCode = geoip_country_code();
        var gotoRegion;
        var gotoLang;
        if (countryCode === 'US'){
            gotoRegion="us";
            gotoLang="ae";
        } else if (countryCode === 'CA'){
            ;
            gotoRegion="ca";
            gotoLang="ae";
        } else {
            gotoRegion="ca";
            gotoLang="ae";
        //window.location.href="http://www.wwrd.com";
        }
        var sURL = unescape(location.href);
        sURL = domain+"/"+gotoLang+"/"+gotoRegion+"/icat/waterford";
        window.location.href=sURL+"?notify=yes";
    };
};

/**
 * Change region popup message
 * Sourced by templates/menu/flags
 */
Venda.Ebiz.checkNotify = function() { 
    var query = window.location.search.substring(1);
    var params = query.split('&');
    for (var i=0; i<params.length; i++) {
        var pos = params[i].indexOf('=');
        if (pos > 0) {
            var key = params[i].substring(0,pos);
            var val = params[i].substring(pos+1);
            qsParam[key] = val;
        }
    }
};
/* IP GEO - end */
 
//Declare namespace for bklist
Venda.namespace("Ebiz.BKList");
Venda.Ebiz.BKList.jq = jQuery; 
Venda.Ebiz.BKList.configBKList = {
    bklist: "",
    divArray: ['#sortby','.sort_results', '.searchpsel', '.pagn', '.refinelist'],
    removeDivArray:['.categorytree'],
    enableBklist: true
};
/**
* Sets the config values to each config type
* @param {string} configType this is an configuration type name
* @param {array} settings this is the value of each configuration type
*/

Venda.Ebiz.BKList.init = function(settings) {
    for (var eachProp in settings) {
        this.configBKList[eachProp] = settings[eachProp];
    }
};
Venda.Ebiz.BKList.jq(document).ready(function() {
    if(Venda.Ebiz.BKList.configBKList.enableBklist){
        Venda.Ebiz.BKList.ChangeLink();
    }
});

Venda.Ebiz.BKList.getUrl = function(){
    var curUrl = document.location.href; 
    if(curUrl.indexOf("&amp;") != -1){
        curUrl = curUrl.replace(/&amp;/gi,'&');		
    }
    return Venda.Platform.getUrlParam(curUrl, "bklist");
};

Venda.Ebiz.BKList.ChangeLink = function(){
    var divArray = Venda.Ebiz.BKList.configBKList.divArray;  
    var removeDivArray = Venda.Ebiz.BKList.configBKList.removeDivArray;  
    var bklist = Venda.Ebiz.BKList.configBKList.bklist || Venda.Ebiz.BKList.getUrl() || "";
    var strBklist = "&bklist";
    if (bklist != "") {
        var addBklist =  strBklist + "=" + bklist;
        for (var i = 0; i < divArray.length; i++) {

            if(Venda.Ebiz.BKList.jq(divArray[i]+ " a").attr("href")){
                Venda.Ebiz.BKList.jq(divArray[i]+ " a").attr("href", function() {		
                    return Venda.Ebiz.BKList.jq(this).attr("href") + addBklist; 			
                });	
            }
			
            if(Venda.Ebiz.BKList.jq(divArray[i] + " option").attr("value")){
                Venda.Ebiz.BKList.jq(divArray[i] + " option").attr("value", function() {	
                    return Venda.Ebiz.BKList.jq(this).attr("value") + addBklist; 
                });				
            }
        }	
		
        for (var i = 0; i < removeDivArray.length; i++) {
            Venda.Ebiz.BKList.jq(removeDivArray[i]+" a").attr("href", function() {
                var currentLink = Venda.Ebiz.BKList.jq(this).attr("href");
                var newLink = currentLink;
                if (newLink.length > 2) {
                    if (currentLink.indexOf("&bklist=") != -1) {
                        newLink = currentLink.substring(0, currentLink.indexOf("&bklist="));
                    }
                    if (newLink.indexOf("&view=") != -1) {
                        newLink = newLink.substring(0, newLink.indexOf("&view="));
                    }
                }
                return newLink;
            });
        }
        if(Venda.Ebiz.BKList.jq("#tag-pageSearchurlFull")){
            var newUrl = Venda.Ebiz.BKList.jq("#tag-pageSearchurlFull").text()+ addBklist ;
            Venda.Ebiz.BKList.jq("#tag-pageSearchurlFull").text(newUrl);
        }
        if(Venda.Ebiz.BKList.jq("#tag-pageSearchurl")){
            var newUrl = Venda.Ebiz.BKList.jq("#tag-pageSearchurl").text()+ addBklist ;
            Venda.Ebiz.BKList.jq("#tag-pageSearchurl").text(newUrl);
        }		
        if(Venda.Ebiz.BKList.jq("#tag-pageIcaturl")){
            var newUrl = Venda.Ebiz.BKList.jq("#tag-pageIcaturl").text()+ addBklist ;
            Venda.Ebiz.BKList.jq("#tag-pageIcaturl").text(newUrl);
        }			
    }
};
function converQuote(srcQ){
    srcQ = srcQ.replace(/%20/g,"%5f");
    srcQ = srcQ.replace(/%27/g,"%5C%27");
    return unescape(srcQ);
};
function converQuoteNotSpace(srcQ){
    srcQ = srcQ.replace(/%27/g,"%5C%27");
    return unescape(srcQ);
};


function hasFPO(textParam) { 
    var upper = textParam.toUpperCase();
    upper = jQuery.trim(upper);
    if (upper =="FPO" || upper =="APO") {            
        return true;
    } 
    return false;    
}

function hasPOBOX(textParam) { 
    var upper = textParam.toUpperCase();
    if (upper.indexOf("ANAPOLIS") > -1){
        return false;    
    }
    if (upper.indexOf("P.O.BOX") > -1 || upper.indexOf("P.O. BOX") > -1 || upper.indexOf("POBOX") > -1 || 
        upper.indexOf("PO BOX") > -1 || upper.indexOf("PO  BOX") > -1 || upper.indexOf("P.O. BOX") > -1
        || upper.indexOf("P.O.  BOX") > -1 || upper.indexOf("P.O BOX") > -1 || upper.indexOf("P O BOX") > -1
        || upper.indexOf("P O  BOX") > -1) {            
        return true;
    } 
    return false;    
}

function checkPOBoxesValid1() {        
    var addr1 = document.getElementById("addr1");
    if (hasPOBOX(addr1.value)){
        throwErrorAndReset(addr1);
    }
}
   
function checkPOBoxesValid2() {        
    var addr2 = document.getElementById("addr2");           
    if (hasPOBOX(addr2.value)){
        throwErrorAndReset(addr2);
    }       
}
   
function checkPOBoxesCity() {        
    var city = document.getElementById("city");           
    if (hasFPO(city.value)){
        throwErrorAndReset(city);
    }        
}
   
function throwErrorAndReset(object) {         
    alert ("We are unable to ship to PO Box, FPO or APO addresses. Please try a different address.");
    object.value = "";       
}                
