// JScript File
//20101-01-15: Dynamic displayfunction displayBackOrderAlert(e, cText, show)
{
    //var nbr = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var nbr = 0;
    if (window.event)
    {
        nbr = event.keyCode;
    }
    else if (typeof e.charCode != "undefined")
    {
        if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 39)
            nbr = e.keyCode;
        else
            nbr = e.charCode;
    }
    else if (typeof e.which != "undefined")
    {
        alert("which");
        nbr = e.which;
    }
    var userVal = false;
    if ((nbr >= 48 && nbr <= 57) || (nbr == 8 || nbr == 46 || nbr == 37 || nbr == 39))
    {
        if (show == 'True')
        {
            userVal = confirm(cText);
        }
        else
        {
            userVal = true;
        }        
    }
    
    if (userVal)
    {
        document.getElementById('hdValue').value = "1";
        return true;
    }
    else 
    { 
        return false; 
    }
}//2010-01-08: Added for back Order javascriptfunction onlyNumsBackOrder(e, cText, item, store)
{ 
    //variables to set the validation to fire..
    var flagCan = true;
    var flagUS = false;
    //variable to return the value..
    var retValue = false;
    
    if ((store == '1' || store == '2') && flagUS)
    {
        retValue = alertBackOrder(e, cText, item, true);
    }
    else if ((store == '19') && flagCan)
    {
        retValue = alertBackOrder(e, cText, item, true);
    }
    else
    {
        retValue = specialChars(e);
    }
    return retValue;
}

function alertBackOrder(e, cText, item, fire)
{
    //var nbr = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var nbr = 0;
    if (window.event)
    {
        nbr = event.keyCode;
    }
    else if (typeof e.charCode != "undefined")
    {
        if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 39)
            nbr = e.keyCode;
        else
            nbr = e.charCode;
    }
    else if (typeof e.which != "undefined")
    {
        alert("which");
        nbr = e.which;
    }
    var userVal = false;
    if ((nbr >= 48 && nbr <= 57) || (nbr == 8 || nbr == 46 || nbr == 37 || nbr == 39))
    {
        if (fire)
        {
            if (item == '3000')
            {
                userVal = confirm(cText);                
            }
            else
            {
                userVal = true;
            }
        }
        else
        {
            userVal = true;
        }        
    }
    
    if (userVal)
    {
        document.getElementById('hdValue').value = "1";
        return true;
    }
    else 
    { 
        return false; 
    }
}//2008-08-07: Added for Quick order - Key entry and value change
function specialChars(e)
{ 
    //var nbr = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    var nbr = 0;
    if (window.event)
    {
        nbr = event.keyCode;
    }
    else if (typeof e.charCode != "undefined")
    {
        if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 37 || e.keyCode == 39)
            nbr = e.keyCode;
        else
            nbr = e.charCode;
    }
    else if (typeof e.which != "undefined")
    {
        alert("which");
        nbr = e.which;
    }
    if ((nbr >= 48 && nbr <= 57) || (nbr == 8 || nbr == 46 || nbr == 37 || nbr == 39))
    {
        document.getElementById('hdValue').value = "1";
        return true;
    }
    else 
    { 
        return false; 
    }
}function checkValueChange(msg)
{ 
    var retVal = false;
    if (document.getElementById('hdValue').value == "1")
    {
        retVal = window.confirm(msg);
    }
    else 
    { 
        retVal = true; 
    }
    return retVal;
}

function checkPassCode()
{ 
    var retVal = false;
    var inputone = prompt("Enter your password mailed by GNLD","");
    if (inputone == "abc123")
    {
        retVal = true;
    }
    return retVal;
}    var pass = new Array();
    pass[0]="LkfRHlUXVRqhDIn";
    pass[1]="oSHbWG0iSo3pCku";
    pass[2]="x9zLW85ek8koXN5";
    pass[3]="bdolmnme9Oyh87S";
    pass[4]="7Ejczr09SUXjGH5i";
    pass[5]="22Ejczr09SUXjGH5";
    var extension=".html";
    var enablelocking=0;
    var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var temp3='';
    var cur=0;        function testit(input)
    {
        temp=numletter.indexOf(input);
        var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2));
        temp2=numletter.substring(temp2,temp2+1);
        return (temp2);
    }
    
    function max(which)
    {
        if (Math.ceil(which)+(3&15) < pass.length)
            return (pass[Math.ceil(which)+(3&15)].substring(0,1));
        else
            return '';
    }        function ValidatePrompt()
    {
        var t3='';
        var lim=7;
        
        var verification = prompt('Enter your password mailed by GNLD','');
        if (verification == null)
            return false;
        phase1=Math.ceil(Math.random())-6+(2<<2);
        var indicate=true;
        for (i=(1&2); i<window.max(Math.LOG10E); i++)
            t3+=testit(verification.charAt(i));
        for (i=(1&2);i<lim;i++)
        {
            if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i))
                indicate=false;
        }
        if (verification.length != window.max(Math.LOG10E))
            indicate=false;
        if (indicate)
            return true;
        else
            return false;
    }
// Image Ready Functions://////////////////////////////////////////////////////////////////////////////////function MM_preloadImages() { //v3.0  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}function MM_swapImgRestore() { //v3.0  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}function MM_findObj(n, d) { //v4.01  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);  if(!x && d.getElementById) x=d.getElementById(n); return x;}function MM_swapImage() { //v3.0  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}// Java Window Functions:///////////////////////////////////////////////////////////////////////////////////function popwin(winURL,winName,winWidth,winHeight,winLeft,winTop){
    window.open(winURL,winName,
    "height=" + winHeight +
    ",width=" + winWidth  +
    ",left="  + winLeft   +
    ",top="   + winTop    +
    ",menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0")
}function openNewWindow(URLtoOpen, windowName,windowFeatures) {    newWindow=window.open(URLtoOpen, windowName,windowFeatures);}function changeOpenerAndCloseMe(url) {
window.opener.window.location.href=url;
self.close()
}// Navigation Highlight Functions:///////////////////////////////////////////////////////////////////////////////////function navBar( tableCellRef, hoverFlag, navStyle ) {
	if ( hoverFlag ) {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.color = '#3A5530';
				break;
			default:
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#c00';
				}
		}
	} else {
		switch ( navStyle ) {
			case 1:
				tableCellRef.style.color = '#999999';
				break;
			default:
				if ( document.getElementsByTagName ) {
					tableCellRef.getElementsByTagName( 'a' )[0].style.color = '#000';
				}
		}
	}
}

function navBarClick( tableCellRef, navStyle, url ) {
	navBar( tableCellRef, 0, navStyle );
	goTo( url );
}

// Search and Store Dropdown functions:///////////////////////////////////////////////////////////////////////////////////
function goTo( url ) {
	window.location.href =  url;
}

function Search() { 
if (document.forms[0].QUERY.value=='') return;
//alert(window.location.protocol + '//' + window.location.hostname + '/Search.aspx?QUERY=' + escape(document.forms(0).QUERY.value));
//window.location.href = window.location.protocol + '//' + window.location.hostname + '/Search.aspx?QUERY=' + escape(document.forms(0).QUERY.value);
document.forms[0].action='/Search.aspx'; 
document.forms[0].submit();
} 		
	
function SetCookieAndSwitchStore() {
    setCookie('STORE_ID', document.forms[0].STORE_ID.value, 36500);
    SwitchStore(document.forms[0].STORE_ID.value);
}
				
function SwitchStore(STORE_ID) { 
    var hostname = location.hostname.toString().toLowerCase();
    if (hostname.indexOf("www.gnld.com") == -1 && hostname.indexOf("www.gnld.net") ==-1)
    { hostname = "www.gnld.com";}
//alert(STORE_ID);
    switch (STORE_ID) {
    case '10':
        goTo('http://www.gnld.jp');
        return;
    case '1': 
        //US
          document.forms[0].submit();
        return;
    case '2':
	//US Spanish
          document.forms[0].submit();
        return;
    case '3': 
        // Mexico
        document.forms[0].submit();
        return;
    case '4': 
        // Sweden
        document.forms[0].submit();
        return;
    case '5': 
        // Italy
        document.forms[0].submit();
        return;
    case '7': 
        // Africa
        document.forms[0].submit();
        return;    
    case '8': 
        // Australia
         goTo('http://www.gnld.com.au/?STORE_ID=8');
        return;
    case '9': 
        // New Zealand
         goTo('http://www.gnld.co.nz/?STORE_ID=9');
        return;
    case '11': 
        // UK
        document.forms[0].submit();
        return;
    case '12': 
        // Finland
        //2009-11-25:document.forms[0].submit();
         goTo('http://www.gnld.fi/?STORE_ID=12');
        return;
    case '13': 
        // Estonia
        document.forms[0].submit();
        return;
    case '14': 
        // Bosnia 
        document.forms[0].submit();
        return;
    case '15': 
        // Croatia 
        document.forms[0].submit();
        return;
    case '16': 
        // Slovenia
        document.forms[0].submit();
        return;
    case '17':  
        // Hungary
        document.forms[0].submit();
        return;
    case '18': 
        // Philippines
            goTo('http://www.gnld.com.ph/?STORE_ID=18');
        return;
    case '19': 
        // Canada
        document.forms[0].submit();
        return;
    case '20': 
	 // Germany
        document.forms[0].submit();
        return;
    case '21': 
	 // Romania
        document.forms[0].submit();
        return;
    case '22': 
	 // Carrib
        document.forms[0].submit();
        return;
    case '23': 
	 // Estonia Russian
        document.forms[0].submit();
        return;
    case '25': 
	 // Serbia
        document.forms[0].submit();
        return;
    case '26': 
	 // Montenegro
        document.forms[0].submit();
        return;
    case '27': 
	 // Lithuania
        document.forms[0].submit();
        return;
    default:
        if (STORE_ID == '10')
            goTo('http://www.gnld.jp');
        else
            goTo('http://ww1.gnld.com/?STORE_ID=' + STORE_ID);
        // document.forms[0].submit();
        return;
      }
	//if (=='10') goTo('http://www.gnld.jp');
	//else  document.forms[0].submit();
}// Flash Detection Functions:///////////////////////////////////////////////////////////////////////////////////// flash_detect.js - 3.1
// lowest flash version to check
flashContentVersion = 6;
// run flash detection and set flashCanPlay
var flashCanPlay;

runFlashDetect = function () {
	var foundPlugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (foundPlugin) {
		var words_array = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words_array.length; ++i) {
			if (isNaN(parseInt(words_array[i]))) continue;
			var PluginVersion = words_array[i];
		}
		flashCanPlay = PluginVersion >= flashContentVersion;
	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
		document.write('on error resume next \n');
		document.write('flashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & flashContentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
}
runFlashDetect();
// check flashCanPlay and write the appropriate code
var flashVars = "";

function loadFlash (flashSetup, flashVars, staticCode) {
      if (flashCanPlay) {
            // flashSetup array -> src, width, height, quality, bgcolor, scale, name
            var flashSetup = flashSetup.split(",");
            // check for flashVars and flashContentVersion, then append variables to the url
            if (flashVars != "" && flashContentVersion < 6) flashSetup[0] += "?" + flashVars; // otherwise, we use the v6+ FlashVars attribute
            // write the plugin code
            var objTag ='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +             ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ' +            ' width="'+flashSetup[1]+'" height="'+flashSetup[2]+'">' +            ' <param name="movie" value="'+flashSetup[0]+'">' +
            ' <param name="FlashVars" value="'+flashVars+'">' +
            ' <param name="quality" value="'+flashSetup[3]+'">' +  
            ' <embed src="'+flashSetup[0]+'" width="'+flashSetup[1]+'" height="'+flashSetup[2]+'" quality="'+flashSetup[3]+'" bgcolor="'+flashSetup[4]+'" scale="'+flashSetup[5]+'" FlashVars="'+flashVars+'" menu="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer/" salign="LT" name="' + flashSetup[6] +'"></embed>' + // added salign attrib for unidox menu
            '</object>';  
            document.write(objTag);
      } else {
            // write the static code
            document.write(staticCode);
      }
}


// COOKIE FUNCTIONS
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 setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000));
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate);
}


function checkCookie(c_name)
{
  c_name_value=getCookie(c_name)
  alert(c_name + '= '+ c_name_value );
}


// QUERYSTRING FUNCTIONS
function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    
    this.keyValuePairs = new Array();
    if(q) {
        for(var i=0; i < this.q.split("&").length; i++) {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    
    this.getKeyValuePairs = function() 
        { return this.keyValuePairs; }
    
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return null;
    }

    this.getParameters = function() {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }

    this.getLength = function() 
    { return this.keyValuePairs.length; } 
}

function queryString(key){
var page = new PageQuery(window.location.search); 
if (page.getValue(key) == null) { return null; }
else { return unescape(page.getValue(key)); }

}


//alert(getCookie('STORE_ID'));

//if (getCookie('STORE_ID') != '' && getCookie('STORE_ID') != null) {
//	SwitchStore(getCookie('STORE_ID'));
//}

//267


if (location.pathname.toLowerCase() == '/' || location.pathname.toLowerCase() == 'default.aspx') {
    if (queryString('STORE_ID') == null || queryString('STORE_ID') == '' ) {
            
           if (getCookie('STORE_ID') == null) {
                setCookie('STORE_ID', '1', 36500);    
            }
            else {
                if (getCookie('STORE_ID') == '10') {
                    goTo('http://www.gnld.jp');
                }
                else if (getCookie('STORE_ID')!= '1' && getCookie('STORE_ID') != '2'  && getCookie('STORE_ID') != '3' && getCookie('STORE_ID') != '4' && getCookie('STORE_ID') != '5' && getCookie('STORE_ID') != '7' && getCookie('STORE_ID') != '8' && getCookie('STORE_ID') != '9' && getCookie('STORE_ID') != '11' && getCookie('STORE_ID') != '12' && getCookie('STORE_ID') != '13' && getCookie('STORE_ID') != '14' && getCookie('STORE_ID') != '15' && getCookie('STORE_ID') != '16' && getCookie('STORE_ID') != '17' && getCookie('STORE_ID') != '18' && getCookie('STORE_ID') != '19' && getCookie('STORE_ID') != '20' && getCookie('STORE_ID') != '21' && getCookie('STORE_ID') != '22'&& getCookie('STORE_ID') != '23' && getCookie('STORE_ID') != '25' && getCookie('STORE_ID') != '26' && getCookie('STORE_ID') != '27') {
                    goTo('http://ww1.gnld.com/?STORE_ID=' + getCookie('STORE_ID'));
                }        
            }           
    }
    else {
          if (getCookie('STORE_ID') == null  || getCookie('STORE_ID')  == '' || queryString('STORE_ID') != getCookie('STORE_ID') ) {
                setCookie('STORE_ID', queryString('STORE_ID'), 36500);   
            }                                
            else {
            if (getCookie('STORE_ID') == '10') {
                    goTo('http://www.gnld.jp');
           }
           else if (queryString('STORE_ID') != '1' &&  queryString('STORE_ID') != '2'  &&  queryString('STORE_ID') != '3' &&  queryString('STORE_ID') != '4' && queryString('STORE_ID') != '5' && queryString('STORE_ID') != '7' && queryString('STORE_ID') != '8' && queryString('STORE_ID') != '9' && queryString('STORE_ID') != '11' && queryString('STORE_ID') != '12' && queryString('STORE_ID') != '13' && queryString('STORE_ID') != '14'  && queryString('STORE_ID') != '15' && queryString('STORE_ID') != '16' && queryString('STORE_ID') != '17' && queryString('STORE_ID') != '18' && queryString('STORE_ID') != '19' && getCookie('STORE_ID') != '20' && getCookie('STORE_ID') != '21' &&  queryString('STORE_ID') != '22'    &&  queryString('STORE_ID') != '23'  &&  queryString('STORE_ID') != '25'  &&  queryString('STORE_ID') != '26' &&  queryString('STORE_ID') != '27') {
                	goTo('http://ww1.gnld.com/?STORE_ID=' + getCookie('STORE_ID'));
		    }
        }
    }

} //if location.pathname