
function startList(){
	if (document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					if(this.id == "ourFamily" && this.id != current){
						this.style.backgroundPositionX = -77;
					}else if(this.id == "ourPlace" && this.id != current){
						this.style.backgroundPositionX = -73;
					}else if(this.id == "ourWine" && this.id != current){
						this.style.backgroundPositionX = -69;
					}else if(this.id == "yourPlace" && this.id != current){
						this.style.backgroundPositionX = -78;
					}else if(this.id == "epicurean" && this.id != current){
						this.style.backgroundPositionX = -105;
					}else if(this.id == "news" && this.id != current){
						this.style.backgroundPositionX = -97;
		            } else if (this.id == "promotionsclass" && this.id != current) {
						this.style.backgroundPositionX = -86;
					}
					try
					{
						if(this.firstChild.nextSibling.firstChild != undefined && this.id != current){
							this.firstChild.nextSibling.firstChild.style.display = "block";
						}
					}
					catch(e)
					{}
					if(this.id != current && current != ""){
						currentOff();
					}
				}
				node.onmouseout=function() {
					try
					{
						if(this.firstChild.nextSibling.firstChild != undefined && this.id != current){
							this.firstChild.nextSibling.firstChild.style.display = "none";
						}
					}
					catch(e)
					{}
					
					if(this.id != current && current != ""){
						this.style.backgroundPositionX = 0;
						currentOn();
					}else if(current == ""){
						this.style.backgroundPositionX = 0;
					}
				}
			}
		}
	}
}
window.onload = startList;


var current = "";

function initNav(c){
	startList();
	current = c;
	currentOn();
}

function currentOn(){
	var cNav = document.getElementById(current);
	cNav.className = current+"_current";
}

function currentOff(){
	var cNav = document.getElementById(current);
	cNav.className = current;
}




function init(){
    if (document.images){
	
	navArray = ["home","ourFamily","ourPlace","ourWine","yourPlace","epicurean","news",
				"heritage","familyProfiles",
				"milawa","epiCentre","cellarDoor","vineyards","kindergarten",
				"whites","reds","cellarDr","fortifieds","dessert","upcoming","sparkling","patricia","natRelease",
				"cellaring","serving","recipes","wineAndFood","retailer","wizard","retailFind",
				"benefits","application","join","evnts","aboutEpic",
				"newsSub","events","media","reviews","awards","studentInfo","promotions",
				"cart", "ep_welcome", "ep_profile", "ep_browse", "ep_browse_other", "ep_offers", "ep_magazine", "ep_orderhistory", "ep_logout", "ep_become_member", "ep_faq"];
	
	homeFooter = ["hmContact","hmFaq","hmSitemap","hmAirstrip","hmPrivacy","hmTerms","hmTermsOS"];
	globalFooter = ["ftContact","ftFaq","ftAirstrip","ftSitemap","ftPrivacy","ftTerms","ftTermsOS"];
	
		if (document.images) {
			
			for (var n in navArray) {
				
				eval(navArray[n] + "_over = new Image()");
				eval(navArray[n] + "_over.src = '/images/nav/" + navArray[n] + "_1.gif'");
				
				eval(navArray[n] + "_on = new Image()");
				eval(navArray[n] + "_on.src = '/images/nav/" + navArray[n] + "_0.gif'");
				
			}
			
			for (var n in homeFooter) {
				
				eval(homeFooter[n] + "_over = new Image()");
				eval(homeFooter[n] + "_over.src = '/images/home/" + homeFooter[n] + "_1.gif'");
				
				eval(homeFooter[n] + "_on = new Image()");
				eval(homeFooter[n] + "_on.src = '/images/home/" + homeFooter[n] + "_0.gif'");
				
			}
			
			for (var n in globalFooter) {
				
				eval(globalFooter[n] + "_over = new Image()");
				eval(globalFooter[n] + "_over.src = '/images/global/" + globalFooter[n] + "_1.gif'");
				
				eval(globalFooter[n] + "_on = new Image()");
				eval(globalFooter[n] + "_on.src = '/images/global/" + globalFooter[n] + "_0.gif'");
				
			}
			
		}
        
    }
}

init();



function imageOn(img){
    if (document.images){
        document [img].src = eval(img + "_over.src");
    }else{
        return;
    }
}

function imageOff(img){
    if (document.images){
        document [img].src = eval(img + "_on.src");
    }else{
        return;
    }
}


function show(id){ 
	var ele = document.getElementById(id);    
	ele.style.display = "block";
	try
	{
		if(id=='pr4')
		{
			ele.style.position= "relative";
		}
	}
	catch(e)
	{
	}
} 
function hide(id){  
	var ele = document.getElementById(id);     
	ele.style.display = "none";        
}

function popUpMenu(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=695,height=600,left = 0,top = 0');");
}

function printPreview(printContent, Title) 
{
	var inf = printContent;
	hWndPreviewWindow = window.open("", 'popup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=695,height=600,left = 0,top = 0');
    hWndPreviewWindow.document.open();
    hWndPreviewWindow.document.writeln('<HTML><HEAD><TITLE>Print Preview Window</TITLE><style type="text/css" media="all">@import url( /css/print.css );</style></HEAD>');
    hWndPreviewWindow.document.writeln('<BODY BGCOLOR="white"><div id="content"><div class="mainCol"><div class="contentBox">');
    hWndPreviewWindow.document.write('<h1>' + Title + "</h1><br>");
	hWndPreviewWindow.document.write(inf);
    hWndPreviewWindow.document.writeln('</div></div></div><br><br><br><A HREF="javascript:window.close()">Close Preview</A>&nbsp;&nbsp;<A HREF="javascript:window.print()">Print</A><BR>');
	hWndPreviewWindow.document.writeln('</BODY></HTML>');
    hWndPreviewWindow.document.close();
}

function makeArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 0
    }
    return this
}

var reSignedInteger = /^\d+$/
var reInteger = /^\d+$/
var defaultEmptyOK = false
var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function isDate(year, month, day) {   // catch invalid years (not 2- or 4-digit) and invalid months and days.

    if (!(isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);
    if (intDay > daysInMonth[intMonth]) return false;
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
    return true;
}

function isYear(s) {
    if (isEmpty(s))
        if (isYear.arguments.length == 1) return defaultEmptyOK;
        else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isMonth(s) {
    if (isEmpty(s))
        if (isMonth.arguments.length == 1) return defaultEmptyOK;
        else return (isMonth.arguments[1] == true);
    return isIntegerInRange(s, 1, 12);
}

function isDay(s) {
    if (isEmpty(s))
        if (isDay.arguments.length == 1) return defaultEmptyOK;
        else return (isDay.arguments[1] == true);
    return isIntegerInRange(s, 1, 31);
}

function daysInFebruary(year) {   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}

function isInteger(s) {
    var i;
    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return defaultEmptyOK;
        else return (isInteger.arguments[1] == true);
    return reInteger.test(s)
}

function isIntegerInRange(s, a, b) {
    if (isEmpty(s))
        if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
        else return (isIntegerInRange.arguments[1] == true);
    if (!isInteger(s, false)) return false;
    var num = parseInt(s);
    return ((num >= a) && (num <= b));
}
function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isNonnegativeInteger(s) {
    var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ((isEmpty(s) && secondArg) || (parseInt(s) >= 0)));
}
function isSignedInteger(s) {
    if (isEmpty(s))
        if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
        else return (isSignedInteger.arguments[1] == true);
    else {
        return reSignedInteger.test(s)
    }
}

function checkForPaste(event) {
    var e = event.element();
    if ((e.previousValue && e.value.length > e.previousValue.length + 1) ||
        (!e.previousValue && e.value.length > 1)) {
        if (e.onpaste) {
            e.onpaste(e)
        } else if (e.readAttribute("onpaste")) {
            eval(e.readAttribute("onpaste"));
        }
    }
    e.previousValue = e.value;
}

function firefoxOnPaste() {
    try {
        $('input').each(function (e) {
            if (e.onpaste || e.readAttribute("onpaste")) {
                Event.observe(e, 'input', checkForPaste);
            }
        });
    }
    catch (e) { }
}
