﻿//used in header
function linkForm(action)
{
	document.getElementById('globalLinkForm').action = action;
	document.getElementById('globalLinkForm').submit();
}


function styledisp(id, disp)
{
    var id = document.getElementById(id);
    if(id)
    {
        id.style.display = disp;
    }
}

function curl(url)
{
    window.location = url.replace(/___/g, "'");
}

function ShipSameDayWindow(bOverrideSameDayMessage,customerZoneID) 
{
  ShipWindow=window.open('','ShipTime','height=200,width=430,resizable=yes,top=100,left=100');

  var tmp = ShipWindow.document;
  
  tmp.write('<html><head><title>Ship Time</title>');

  tmp.write('</head><body><p style=\"font-family:Verdana;font-size:12px;\"><b>Ship Time</b></p>');

  if (!bOverrideSameDayMessage)
  {
    if(customerZoneID == 3) 
    {
        tmp.write('<p style=\"font-family:Verdana;font-size:12px;line-height:120%\">Items that are designated by "Usually ships within 24 hours" normally leave our facilities on the same business day if the order is placed before 5:00pm EST.</p>');
     }
     else
     {
        tmp.write('<p style=\"font-family:Verdana;font-size:12px;line-height:120%\">Items that are designated by "Usually ships within 24 hours" normally leave our facilities on the same business day if the order is placed before 16:00GMT.</p>');
     }   
  }
  
  tmp.write('<p style=\"font-family:Verdana;font-size:12px;line-height:120%\">Ship time indicates the typical number of business days it takes for your item(s) to leave our facilities but does not include transit time from our facilities to the final destination.</p>');
  
  tmp.write('<p style=\"font-family:Verdana;font-size:12px;line-height:120%\">Orders that contain multiple items with different ship times will be shipped out based on the item with the longest ship time.</p>');
  
  //tmp.write("<p><div style=\"font-family:Verdana;font-size:12px;cursor:pointer;color:#000077\" onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\" onclick=\"window.open('\/asp\/customerservice\/shipping.asp','','height=678,width=900,scrollbars=yes,resizable=yes,titlebar=yes,toolbar=yes,menubar=yes')\">Shipping FAQ</div>");
  
 // tmp.write("<div style=\"font-family:Verdana;font-size:12px;cursor:pointer;color:#000077\" onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\" onclick=\"window.open('\/asp\/ship_rates.asp','','height=678,width=900,scrollbars=yes,resizable=yes,titlebar=yes,toolbar=yes,menubar=yes')\">Shipping Rates</div><br/></p>");
  
  tmp.write('</body></html>');

  tmp.close();

}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +value+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";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 "";
}

function checkcookie()
{
    alert("all cookie:" + document.cookie);
    alert("ENDECA cookie:" + getCookie("ENDECA"));
}

function selectNs(val)
{

    setEndecaCookie(val, "&Ns=");
    var url = redirectNtt(changePg(window.location, 1));
    window.location = url;
}

function selectNn(toRecordPerpage, curRecordPerpage, curPageNumber, totalRecords)
{
    
    setEndecaCookie(toRecordPerpage, "&Nn=");
    var toPageNumber = calcPageNumber(toRecordPerpage, curRecordPerpage, curPageNumber, totalRecords);
    var url = redirectNtt(changePg(window.location, toPageNumber));
    window.location = url;
}

function calcPageNumber(toRecordPerpage, curRecordPerpage, curPageNumber, totalRecords)
{
    var toRecordPerpage = parseInt((parseInt(curRecordPerpage) * parseInt(curPageNumber-1)) / parseInt(toRecordPerpage))+1;
    
    return toRecordPerpage;
} 

function redirectNtt(url)
{
    
    if(ntt && ntt.length>0 && url.indexOf("searchstring")==-1)
    {
        var index = url.lastIndexOf("/");
        if(index>-1)
        {
            // The format of the url is changed as the search querysting is getting append at last now.
            url = url.substring(0, index) + url.substring(index) + "&searchstring=" + ntt;
           // alert(url);
        }
    }
        
    return url;
}

var ntt;
function addSearchString(ntt)
{
    this.ntt = ntt;
   
}

function gobacktosearch(ntt)
{
    this.ntt = ntt;
    var url = window.location.toString();
    url = url.replace(/___/g, "'");
    window.location = redirectNtt(url);
}

function setEndecaCookie(val, pname)
{
   
    var endeca = getCookie("ENDECA");
   
    //var before = endeca;
    if(endeca.length>0)
    {
        endeca = endeca.replace(/\+\&\+/g,"___");
        var tokens = endeca.split("&");
        var new_endeca = "";
        var found = false;
        for(var i=0; i<tokens.length; i++)
        {
            if(tokens[i].indexOf(pname)==0)
            {
                tokens[i] = pname + val;
                found = true;
            }
            new_endeca += "&" + tokens[i];
        }
        endeca = new_endeca.substring(1);
        if(!found)
        {
            endeca += "&" + pname + val;
        }
    }
    else
    {
        endeca = pname + val;
      //  alert(endeca + 'in else');
    }

    endeca = endeca.replace(/&&/g, "&");
    endeca = endeca.replace(/___/g, escape("+&+"));
    //alert("before:" +before + "\nafter:" + endeca);
   
    setCookie("ENDECA",endeca, 365);
}
    
function changePg(url, pg)
{
     // changed this method to handle new URL structure
    
   //alert("changepg"); 
    var sUrl = url.toString();
    var aPos = sUrl.indexOf("_p");
       
    // this is to handle Non SEO urls 
    var finalUrl=""; 
    var aPosGal= sUrl.indexOf("page=")
    if(aPosGal > 0)
    {
        var newPageno= "page=" + pg; 
        var regex=/page=\d+\b/;
        finalUrl = sUrl.replace(regex, newPageno);
    }      
   // End of logic to handle Non SEO urls 
      
    if(pg==1)
    {
        if(aPos>0)
        {
            var aStr = sUrl.substring(0, aPos);
            var cPos=sUrl.indexOf(".",aPos);
            var bStr = sUrl.substring(cPos);
          // to handle select on gallery page.
          sUrl=url; 
           // sUrl = aStr + bStr;
            
           
        }
    }
    if(pg>1)
    {
        var bPos = sUrl.lastIndexOf("_p");
        if(bPos>0)
        {
            var dPos=sUrl.indexOf(".",bPos);
            var dStr = sUrl.substring(dPos);
            sUrl = sUrl.substring(0, bPos) + "_p" + pg + "_" + dStr;
         //   alert(sUrl);
        }
    }
   
   if(finalUrl.length>0)
   {
        sUrl=finalUrl;
   }   
    
    return sUrl;
}


var XMLHttpFactories = [
    function () {return new XMLHttpRequest()},
    function () {return new ActiveXObject("Msxml2.XMLHTTP")},
    function () {return new ActiveXObject("Msxml3.XMLHTTP")},
    function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
    var xmlhttp = false;
    for (var i=0;i<XMLHttpFactories.length;i++) {
        try {
             xmlhttp = XMLHttpFactories[i]();
        }
        catch (e) {
            continue;
        }
        break;
    }
    return xmlhttp;
}


function getuid()
{
	var uid = document.getElementById("uid");
	if(uid) return uid.value;
	else return "";
}

function hidePromo()
{
	hideElem("dhtml_Email_Container");
	hideElem("CSModuleChangeLanguageContainer");
	hideElem("CSModuleChangeCountryContainer");
}

function hideElem(id)
{
	var elm = document.getElementById(id);
	if(elm) elm.style.display="none";
}

var reqObj, req, theURL;

function fireSearch(boxid){
   
    var searchbox = document.getElementById(boxid);
    if(searchbox)
    {
        var term = searchbox.value;
        term = term.replace(/@/g, "").replace(/#/g, "").replace(/$/g, "").replace(/%/g, "").replace(/^/g, "");
        term = term.replace(/^\s+|\s+$/g, "");
        if(term.length==0)
        {
            document.getElementById("yoursearch").innerHTML = "Please enter a valid search term.";
            searchbox.value = "";
            return ;
        }
        
        var f = document.forms['globalLinkForm'];
        if (!f) {
            f = document.aspnetForm;
        }
      //  alert(f);
        
        //f.action = "/asp/search_do-asp/_/posters.htm?ID=0&searchstring="+escape(term)+"&ui="+gup("ui");
   //     f.action="/gallery.asp?startat=/gallery.asp&CID=" + gup("CID") + "&txtSearch=" +escape(term)
     window.location.href= "/gallery.asp?startat=/gallery.asp&CID=" + gup("CID") + "&txtSearch=" +escape(term);

        f.submit();
    }
}

function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}

//banner popup window

function popOpen( url, name, attributes ) 
{ 
	windowHandle = window.open( url, name, attributes ); 
}

//banner popup window

function popOpen( url, name, attributes ) 
{ 
	windowHandle = window.open( url, name, attributes ); 
}

function openPop(pURL,pName,pWidth,pHeight,new_pop){
   var winWidth = 420;
   var winHeight = 325;
   var winName = "newWin";
   if (pWidth > 0){
      winWidth = pWidth;
   }//end if
   if (pHeight > 0){
      winHeight = pHeight;
   }//end if
   if (pName.length > 0){
      winName = pName;
   }//end if
   var newWin = window.open(pURL,winName,'width=' + winWidth + ',height=' + winHeight + ',status=no,toolbar=no,scrollbars=yes,resizable=yes,left=1,top=1')
      if(new_pop==0)
      {
         if (window.focus)
         { 
            newWin.focus()
         }
      }
      else
      {
         var newWin2 = window.open(pURL,winName,'width=' + winWidth + ',height=' + winHeight + ',status=no,toolbar=no,scrollbars=yes,resizable=yes,left=1,top=1')
         if (window.focus)
         { 
               newWin2.focus()
         }
      }        
}	