/**
* common library of javascript functions
*/

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
		obj.addEventListener(evType, fn, true);
		return true;
    } else if (obj.attachEvent)  {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

/*
* fix alpha pngs on a page (turn on transparency for IE)
*/

//Commenting this out. Use the custom tag for applying IE transparency filter.
/*
function fixAlphaPng() {
    var src     = '';
    var ua      = '';
    var width   = '';
    var height  = '';
    var rpng    = new RegExp('\.(png|jpg)$');
    var rmsie   = new RegExp('msie');
    var rmac    = new RegExp('mac');

    for (var i = 0; i < document.getElementsByTagName('IMG').length; i++) {
        src     = document.getElementsByTagName('IMG')[i].getAttribute('src');
        ua      = navigator.userAgent.toLowerCase();
        width   = document.getElementsByTagName('IMG')[i].getAttribute('width');
        height  = document.getElementsByTagName('IMG')[i].getAttribute('height');

        if (src.match(rpng) && ua.match(rmsie) && !ua.match(rmac)) {
        	document.getElementsByTagName('IMG')[i].setAttribute('src', '/images/spacer.png');
            document.getElementsByTagName('IMG')[i].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=scale)';
           	document.getElementsByTagName('IMG')[i].style.width = width + 'px';
            document.getElementsByTagName('IMG')[i].style.height = height + 'px';            
        }
    }
}
addEvent(window, 'load', fixAlphaPng);
*/


/*
Nav Fix for IE hover
*/
navArray = Array('nav1');
startList = function() {
	if (document.all&&document.getElementById) {
		//Top Navs
		for (m=0; m<navArray.length; m++) {
			if (document.getElementById(navArray[m])) {
				topNavRoot = document.getElementById(navArray[m]);
				for (i=0; i<topNavRoot.childNodes.length; i++) {
					node = topNavRoot.childNodes[i];
					//alert(node.nodeName);
					if (node.nodeName=="LI") {
						//Sub UL
						for (j=0; j<node.childNodes.length; j++) {
							subTopNavRoot = node.childNodes[j];
							if (subTopNavRoot.nodeName=="UL") {
								for (k=0; k<subTopNavRoot.childNodes.length; k++) {
									subnode = subTopNavRoot.childNodes[k];
									if (subnode.nodeName=="LI") {
										subnode.onmouseover=function() {
											this.className="over "+this.className;
										}
										subnode.onmouseout=function() {
											this.className=this.className.replace("over ", "");
										}
									}
								}
							}
						}
						node.onmouseover=function() {
							//alert(" m = "+m+"\n i = "+i+"\n j = "+j+"\n k = "+k);
							this.className="over "+this.className;
						}
						node.onmouseout=function() {
							this.className=this.className.replace("over ", "");
						}
					}
				}
			}
		}
	}
}
addEvent(window, 'load', startList);



/*
Redirect to no cookies page
*/
function noCookies(redirect) {
	var tmpcookie = new Date();
	chkcookie = (tmpcookie.getTime() + '');
	document.cookie = "chkcookie=" + chkcookie + "; path=/";
	if (document.cookie.indexOf(chkcookie,0) < 0) {
		window.location = redirect;
	} else {
		return("true");
	}
}

/*
Clear default value of text input
*/
function clearField(thefield) {
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
}


/*
pop up new scrollable, resizable window
*/
function popup(url,w,h) {
	if (!w) {w='270';}
	if (!h) {h='270';}
	newPopup = window.open (url, 'wexnerpop', 'resizable,scrollbars,width='+w+',height='+h);
	newPopup.focus();
}

/*
pop up new non-scrollable, non-resizable window
*/
function kiosk(url,w,h) {
	//resize Mood River popup
	if (url.indexOf('/ex/2002/moodriver/') != -1) {
		w = 720;
	}
	newKiosk = window.open (url, 'wexnerkiosk', 'width='+w+',height='+h);
	newKiosk.focus();
}

/*
pop up new resizable, non-scrollable window with menu and toolbars 
(for navigatbale & printable pages.)
*/
function formpop(url,w,h) {
	newFormpop = window.open (url, 'wexnerform', 'resizable,menubar,toolbar,width='+w+',height='+h);
	newFormpop.focus();
}

/*
Check Postal Code for baln/defaul and country
*/
function checkPostalCode(theform) {
	if (theform.postalCode.value==theform.postalCode.defaultValue || theform.postalCode.value=="") {
		window.location="http://web.sa.mapquest.com/wendys/?tempset="+theform.tempset.value;
	} else {
		(/([a-z]|[A-Z])/.test(theform.postalCode.value))?theform.country.value='CA':theform.country.value='US';
		theform.submit();
	}
}

