/* BACK ORDER DATE */
/* ------------------------------------------------------------------------ */

function DatePosition(dateString,dateType,messageString) {
/*
   function DatePosition 
   parameters: dateString dateType
   returns: integer (-1, 0, 1)
   
   dateString is a date passed as a string in the following
   formats:

   type 1 : 19970529
   type 2 : 970529
   type 3 : 29/05/1997
   type 4 : 29/05/97
   type 5 : 05/29/1997
   type 6 : 05291997
   type 7 : 052997
   
   dateType is a numeric integer from 1 to 7, representing
   the type of dateString passed, as defined above.

   Returns -1 if the date passed is behind todays date
   Returns 0 if the date passed is equal to todays date
   or if dateType is not 1 to 7
   Returns 1 if the date passed is ahead of todays date
   
   Added Y2K checking.  (Works for any century cross over)
*/


    var specialMessage = messageString;
    var dateBackOrder = dateString;
    var dateMessage = '<span class=red>Note:</span> Orders placed today for this item will not ship before ';
    
    var now = new Date();
    var century = parseInt(now.getYear()/100)*100;
        
    if (dateType == 1)
        var date = new Date(dateString.substring(0,4),
                            dateString.substring(4,6)-1,
                            dateString.substring(6,8));
    else if (dateType == 2)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(0,2)))
        {
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        else
        {
            var date = new Date(century-100+parseInt(dateString.substring(0,2)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        
    }
    else if (dateType == 3)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(3,5)-1,
                            dateString.substring(0,2));
    else if (dateType == 4)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(6,8)))
        {
            document.write(century+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        else
        {
            document.write(century-100+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        
    }
    else if (dateType == 5)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(0,2)-1,
                            dateString.substring(3,5));
    else if (dateType == 6)
        var date = new Date(dateString.substring(4,8),
                            dateString.substring(0,2)-1,
                            dateString.substring(2,4));
    else if (dateType == 7)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(4,6)))
        {
            document.write('datestring Century:',century+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        else
        {
            document.write('datestring Century:',century-100+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        
    }
    else
        return false;

    if (date > now)
    {
        if (specialMessage.length == 0) 
	{
        	document.write("<p class=textdarkgray>");
        	document.write(dateMessage);
        	document.write(dateBackOrder,'. ');
        	document.write("</p>");
	}
	else
	{
        	document.write("<p class=textdarkgray>");
        	document.write(specialMessage);
        	document.write("</p>");
	}
        
    }


}

/* TELL A FRIEND */
/* ------------------------------------------------------------------------ */

function tellAFriend () {
	var href = document.location.href;
	var baseRef = href.substring(href.lastIndexOf("/") + 1);
	baseRef = baseRef.substring(0, baseRef.lastIndexOf("."));
	var URL = "reddot-tellafriend.html?item=" + baseRef;
	MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

function askAQuestion () {
	var href = document.location.href;
	var baseRef = href.substring(href.lastIndexOf("/") + 1);
	baseRef = baseRef.substring(0, baseRef.lastIndexOf("."));
	var URL = "ask-a-question.html?item=" + baseRef;
	MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

function tellAFriendPlus () {
	var baseRef = document.location.href.substring(document.location.href.lastIndexOf("=") + 1);
	var URL = "reddot-tellafriend.html?item=" + baseRef;
	MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

function askAQuestionPlus () {
	var baseRef = document.location.href.substring(document.location.href.lastIndexOf("=") + 1);
	var URL = "reddot-askquestion.html?item=" + baseRef;
	MM_openBrWindow(URL,'tellAFriend','scrollbars=no,resizable=yes,width=453,height=447,left=200,top=50');
}

/* POP UPS */
/* ------------------------------------------------------------------------ */

function popVolume(URL) {
	window.open(URL,'','toolbar=no, width=550, height=575, resizable=1, scrollbars=1'); void('');
}

function popUp(URL) {
	window.open(URL,'','toolbar=no, width=500, height=545, resizable=1, scrollbars=1'); void('');
}

function popImage(URL) {
	window.open(URL,'','toolbar=no, width=450, height=520, resizable=0, scrollbars=0'); void('');
}


function MM_openBrWindow(theURL,winName,features) {
  window.name = "main";
  var page = "popup.html";
  smallWin=window.open(theURL,winName,features);
}

function popProduct(URL) {
		window.open('product-zoom.html?' + URL +'','','toolbar=no, width=575, height=600, resizable=1, scrollbars=1'); void('');
	}

function popProductPlus(baseRef,URL) {		
window.open('product-zoom-plus.html?' + URL + '&pageid=' + baseRef,'','toolbar=no, width=575, height=600, resizable=1, scrollbars=1'); void('');
	}

function popMore(URL) {
		window.open('more-zoom.html?' + URL +'','','toolbar=no, width=400, height=400, resizable=1, scrollbars=1'); void('');
	}

function ZoomPopUp(URL) {
		window.open('product-zoom.html?' + URL +'','','toolbar=no, width=575, height=600, resizable=1, scrollbars=1'); void('');
	}


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.0
  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 && document.getElementById) x=document.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];}
}


/* MAKE MENUS WORK IN IE */
/* YES, THERE SHOULD BE TWO SETS! */ 
/* ------------------------------------------------------------------------ */

sfHover = function() {
  var ids = ["nav", "subnav"];
  for (var i in ids) {
    var navEl = document.getElementById(ids[i]);
    if (navEl) {
      var sfEls = navEl.getElementsByTagName("LI");
      for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
          this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
          this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
      }
    }
  }
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

/* */

function popProductPress(URL) {
		window.open('product-zoom.html?' + URL +'','','toolbar=no, width=650, height=600, resizable=1, scrollbars=1'); void('');
	}



function goSite(dropdown) {
	var id = dropdown.options[dropdown.selectedIndex].value;
		if (id) {
		var loc = document.location + '';
		document.location.href = id + '.html';
	 }
}

function goSiteSLI(dropdown) {
	var id = dropdown.options[dropdown.selectedIndex].value;
		if (id) {
		var loc = document.location + '';
		document.location.href = 'http://www.ylighting.com/' + id + '.html';
	 }
}
