function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

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_showHideLayers() { //v6.0
      var i,p,v,obj,args=MM_showHideLayers.arguments;
      for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
        obj.visibility=v; 
}
}

function SetExtendedProp(id)
{
    var querystr = document.location.search;
    var _f = document.forms[0];
    if (querystr!=''){
		querystr=querystr.substring(1,querystr.length);
    }
    if (querystr!=''){
        var prop_array = querystr.split('&');
        for (var i=0;i<prop_array.length;i++){
            var prop=prop_array[i].split('=');
            //check if page has field to update requested extended property 
            for (var j = 0; j < _f.elements.length; j++)
            {
                if (_f.elements[j].id.indexOf(id)>-1){ 
                            _f.elements[j].value=prop[1];
                }
            }           
        }
    }
 
}

function SetLogin(loginname)
{
    var mf = GetMainFormName();
    if (mf==null) return;
    var login = GetElementName("hidden_login",mf)
    if (login!= null)
        document.forms[mf].elements[login].value = loginname;
}
							
function Sethiddenloginvalue(val)
{
	var _f = document.forms[0];
	for (i=0;i<_f.elements.length;i++)
	{
		if (_f.elements[i].id.indexOf('hidden_login') != -1)
			_f.elements[i].value=val;
	}
 }
 									
function GetElementName(n, mf)
{
	if (n==null || n=="") return null;
	var i, s, j;
	for (i=0;i<document.forms[mf].elements.length;i++)
	{
	if (document.forms[mf].elements[i].name.toLowerCase().indexOf(n.toLowerCase()) != -1)
	return document.forms[mf].elements[i].name;

	}
	return null;
}

//Validate zipcode: Zip should have 5 numeric characters
function ValidateZip(zipTextbox)
{		
	//Check if zip code length is 5
	if(zipTextbox.value.length != 5)
	{
		return false;
	}				
	else			
	{
		//If zipcode length is 5, only allow 0-9 to be entered as the characters
		var checkOK = "0123456789";
		var allValid = true;
		for (var i=0; i < zipTextbox.value.length; i++) 
		{ 
			ch = zipTextbox.value.charAt(i);
			
			for (var j = 0;  j < checkOK.length;  j++)
			{							
				if (ch == checkOK.charAt(j))
					break;							
			}
			
			if (j == checkOK.length)
			{							
				allValid = false;
				break;
			}
		}
		if (!allValid) 
		{
			return false;
		}	
		else
		{
			return true;
		}						
	}
}

function gosearch(absoluteURL)
{	
	var mf = GetMainFormName();		
	if (mf==null) return;
	var searchVal = document.forms[mf].elements["SearchKeywords"].value;
	searchVal = searchVal.toLowerCase();
	if (typeof(absoluteURL)!='undefined') {
	document.forms[mf].action=absoluteURL + "/search/index.aspx?SearchKeywords=" + searchVal;
	}
	else {
	document.forms[mf].action="/search/index.aspx?SearchKeywords=" + searchVal;
	}
	document.forms[mf].submit();
}	

function search_onfocus(el)
{
	var mf = GetMainFormName();
	if (mf==null) return;
	//el.value = '';
	document.forms[mf].target = "_top";
	document.forms[mf].action="/search/index.aspx?SearchKeywords=" + document.forms[mf].elements["SearchKeywords"].value;
}

function isEnter(e,absoluteURL)
{
	if (e.keyCode == 13)
	{		if (typeof(absoluteURL)!='undefined') {
		    gosearch(absoluteURL);
		   }
		   else {
		       gosearch();
		  }
	}	
	return true;
}

var SUBMIT_ID='ctl00$ctl00$brandlayout0$ctl00$mainbody0$ctl00$ctl02$ctl00$ctl00$submit';
var SUBMIT_ID_STEP1_CHECKOUT="ctl00$ctl00$brandlayout0$ctl00$mainbody0$ctl00$ctl05$ctl00$ctl00$submit";

function SubmitForm_OnEnterPressed(e,buttonID) {
   if (e.keyCode == 13) {

          // var mf = GetMainFormName();
          //if (mf==null) return;
          //var _submitid=GetElementName(buttonID,mf);
          //__doPostBack(_submitid, '') ;
            __doPostBack(buttonID, '') ;
    }

}
function search_GoToURL(url)
{
	if (url!="") document.location.href= url;
}

/* 
 * Prevents user from entering more than specific number of characters in a textbox/textarea
 */
function LimitTextLength(textArea, maxLength)
{		
	if (maxLength == 0)
		maxLength = 150;

	if(textArea.value.length > maxLength )
	{		
		textArea.value = textArea.value.substring(0, maxLength);
		textArea.focus();
	}			
}
/* 
 * Opens a pop-up window with given URL
 */
var newWindow
function openPopup(url, popupWidth, popupHeight) {
	if (newWindow && !newWindow.closed)	{
		newWindow.close()
	}	
		
	var winl = (screen.width - popupWidth) / 2;
	var wint = (screen.height - popupHeight) / 2;
		//alert(popupWidth + " " + popupHeight);
	newWindow = open(url, 'Diesel', ("toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=" + wint + ",left=" + winl + ",width=" + popupWidth + ",height=" + popupHeight + "\""));
	newWindow.focus();
}	

/* VeriSign seal for secure checkout */
function GetSeal()
{
 document.write("<script src=https://seal.verisign.com/getseal?host_name=www.diesel-fragrances.com&size=S&use_flash=YES&use_transparent=YES&lang=en></script>") ;	
}
