﻿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];}}
}
var http_request = false;
function init()
{
    //return;
    var URL;
    var index;
    if(!(document.URL.toLowerCase().match("localhost")))
    {
        if((document.URL.toLowerCase().match("/shoppingcart/")) || (document.URL.toLowerCase().match("/admin/")))
        {
            if(document.URL.toLowerCase().match("/shoppingcart/"))
            {
                index = document.URL.toLowerCase().lastIndexOf("/shoppingcart/");
                URL = document.URL.substr(index, document.URL.length)
                URL = 'https://secure.shopdress.com' + URL;
                //alert(URL);
            }
            if(document.URL.toLowerCase().match("/admin/"))
            {
                index = document.URL.toLowerCase().lastIndexOf("/admin/");
                URL = document.URL.substr(index, document.URL.length)
                URL = 'https://secure.shopdress.com' + URL;
                //alert(URL);
            }            
            if(document.URL.toLowerCase().match("http://"))
            {
                window.location.href = URL;
                //alert('secure');
            }
        }
        else
        {
            if(document.URL.toLowerCase().match("https://"))
            {
                index = document.URL.toLowerCase().lastIndexOf("shopdress.com");
                URL = document.URL.substr(index, document.URL.length)
                URL = 'http://www.' + URL;
                window.location.href = URL;
            }
        }
            
    }
}
function redirect(URL)
{
    location.href = URL;
}
init();
//MM_preloadImages();

function btnSearchClicked()
{
//	var searchValue = document.getElementById('ctl00_tbSearch').value;
//	if ((searchValue.toLowerCase().match("enter item") > 0) || (searchValue = '')) return;
//	try 
//	{
//		var pageTracker = _gat._getTracker("UA-189608-1");
//		pageTracker._trackPageview("/Search.aspx?Search2=" + searchValue);
//	} 
//	catch(err) {}
}

function GetCountryForMenu()
{   
    var d2 = new Date();  
    var _idn = ''; 
    if (location.href.match('localhost'))
    {
        _idn = d2.getTime(); 
	    GetSearchResultsFromCommon('http://localhost:2026/ShopDress/misc/Recieve.aspx', '?func=getcountry&d=' + _idn);
	}
	else
	{
        GetSearchResultsFromCommon('http://www.shopdress.com/misc/Recieve.aspx', '?func=getcountry&d=' + _idn);	
	} 
}
function GetSearchResultsFromCommon(url, parameters) 
{
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
        http_request.overrideMimeType('text/xml');
     }
  } else if (window.ActiveXObject) { // IE
     try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
        try {
           http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {}
     }
  }
  //alert(http_request);
  if (!http_request) {
     alert('Cannot create XMLHTTP instance');
     return false;
  }
  http_request.onreadystatechange = onreturnFromGetSearchResultsFromCommon;
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
}

function onreturnFromGetSearchResultsFromCommon() 
{
	var html = '';
    if (http_request.readyState == 4) 
    {
        if (http_request.status == 200) 
        {
        //if (!((http_request.responseText.toUpperCase() == 'UNITED STATES') || (http_request.responseText.toUpperCase() == 'CANADA') || (http_request.responseText == '')))
        //{
            html += '<div align="right">';
            html += '<table>';
            html += '<tr valign="center"><td width="40%"></td>';
            html += '<td width="40px"><a href="#" ><img src="http://www.shopdress.com/Images/Flags/'+http_request.responseText.replace(' ','_').replace(' ','_')+'_small.gif" /></a> </td>';
            html += '<td style="font-size:14px; font-weight:normal" nowrap=nowrap><a href="#" class="graylink" >'+http_request.responseText+'</a></td>';
            html += '</tr>';
            html += '</table>';
            html += '</div>';
            document.getElementById('spnCountryMenu').innerHTML = html;
        //}
        }
    }
}  
