/*Popup Window Functions*/
var popUpWin;
var popDefWidth = 570;
var popDefHeight = 400;
var lastWidth;
var lastHeight;
var popZIndex = 500;
 
//Open URL in new window with fixed dimensions
function openWin(url, pixWidth, pixHeight, canScroll){
 var winFeatures = "width=" + pixWidth + ",height=" + pixHeight + "," + getCentered(pixWidth,pixHeight) + ",resizable=no,scrollbars=";
 if (canScroll){
  winFeatures += "yes";
 } else {
  winFeatures += "no";
 }
 if (popUpWin != null){
  if (popUpWin.closed){
   popUpWin = window.open(url, "popwin", winFeatures);
   popUpWin.focus();
  } else if ((lastWidth == pixWidth) && (lastHeight == pixHeight)){
   popUpWin.location.href = url;
   popUpWin.focus();
  } else {
   popUpWin.close();
   var timeDelay = 0;
   if (navigator.userAgent.indexOf("Safari") != -1){
    timeDelay = 1000;
   }
   var winWait = window.setTimeout('popUpWin = window.open("' + url + '", "popwin", "' + winFeatures + '");popUpWin.focus();', timeDelay);
  } 
 } else {
  popUpWin = window.open(url, "popwin", winFeatures);
  popUpWin.focus();
 }
 lastWidth = pixWidth;
 lastHeight = pixHeight;
}
 
//Get coordinates for centering window
function getCentered(popupWidth, popupHeight){
 var indentNetscapeWidth = 'screenX=' + getIndent(popupWidth, false);
 var indentNetscapeHeight = 'screenY=' + getIndent(popupHeight, true);
 var indentMSIEWidth = 'left=' + getIndent(popupWidth, false);
 var indentMSIEHeight = 'top=' + getIndent(popupHeight, true);
 var centerCoordinates = indentNetscapeWidth + ',' + indentNetscapeHeight + ',' + indentMSIEWidth + ',' + indentMSIEHeight;
 return centerCoordinates;
}
 
//Determine top and left margins for window
function getIndent (popupDimension, isHeight){
 if (isHeight){
  return ((screen.availHeight - popupDimension) / 2);
 } else {
  return ((screen.availWidth - popupDimension) / 2);
 }
}
 
function popImage(imgURL, imgWidth, imgHeight){
 var imgURL = "/popimage.aspx?img=" + imgURL + "&w=" + imgWidth + "&h=" + imgHeight;
 openWin(imgURL, imgWidth, imgHeight);
}

//Determine top and left margins for window
function getDPopIndent (popupDimension, isHeight){
	if (isHeight){
		if (window.innerHeight)
			return ((window.innerHeight - popupDimension) / 2);
		else if (window.document.documentElement && window.document.documentElement.clientHeight)
			return ((window.document.documentElement.clientHeight - popupDimension) /2 );
		else if (window.document.body.clientHeight)
			return ((window.document.body.clientHeight - popupDimension) / 2);
	} else {
		if (window.innerWidth)
			return ((window.innerWidth - popupDimension) / 2);
		else if (window.document.documentElement && window.document.documentElement.clientWidth)
			return ((window.document.documentElement.clientWidth - popupDimension) / 2);
		else if (window.document.body.clientWidth)
			return ((window.document.body.clientWidth - popupDimension) / 2);
	}
}

//Get coordinates for centering DHTML Popup
function getDPopCoords(popupWidth, popupHeight){
	var centerCoordinates = getDPopIndent(popupWidth, false) + ',' + getDPopIndent(popupHeight, true);
	return centerCoordinates;
}

function centerDPop(popID){
	var divPop = getobject(popID);
	var anchorDIV = getobject("content");
	var coords = new String();
	coords = getDPopCoords(parseInt(divPop.style.width), parseInt(divPop.style.height)).toString().split(",");
	divPop.style.left = Math.round(parseInt(coords[0]) - (anchorDIV.offsetLeft)) + "px";
	divPop.style.top = Math.round((parseInt(coords[1]) - anchorDIV.offsetTop) + document.documentElement.scrollTop) + "px";
alert(divPop.style.left + " " + divPop.style.top);
}

function getobject(objectID){
	if (document.all!=null){
		return document.all[objectID];
	} else if (document.getElementById){
		return document.getElementById(objectID);
	}
}

function showTAF(){
	overlay(getobject("staf1"), "subcontent2");
}

function showDPop(popID, isCentered){
	if (macSafari){
		showDIVv("safarifix");
		hideDIVv("flashcontent");
	}
	for (var i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type == "select-one"){
			document.forms[0].elements[i].style.visibility = "hidden";
		}
	}
	if (isCentered || isCentered == null){
	alert("test");
		centerDPop(popID);
	}
	showDIV(popID);
}

function hideDPop(popID){
	if (macSafari){
		showDIVv("flashcontent");
		hideDIVv("safarifix");
	}
	for (var i = 0; i < document.forms[0].elements.length; i++){
		if (document.forms[0].elements[i].type == "select-one"){
			document.forms[0].elements[i].style.visibility = "visible";
		}
	}
	hideDIV(popID);
}

function gotoLeft(field) {
    if (field.value == "(___)___-____") {
        setCaretPosition(field, 1);
    }
}

function popQuestions(){
	openWin("http://f0122a2k9rd.realdialogdirect.com/AskHellmanns/", 960, 650, true);
}

function popQuestionsBF() {
    openWin("http://f0122a2k9rd.realdialogdirect.com/AskBestFoods/", 960, 650, true);
}

function popRules(){
	openWin("/promotions/therealfoodproject/rules.aspx", 670, 520, false);
}

function popRulesTT(){
	openWin("/tastetest/rules.aspx", 500, 500, false);
}

function clearOtherCheckBoxes(chkBox){
    var theForm = document.forms[0];  

	if (chkBox.checked){
		switch(chkBox){
			case theForm.ctl00$ContentPlaceHolder1$chkUnilever:
				theForm.ctl00$ContentPlaceHolder1$chkBrandOnly.checked = false;
				break;
			case theForm.ctl00$ContentPlaceHolder1$chkBrandOnly:
				theForm.ctl00$ContentPlaceHolder1$chkUnilever.checked = false;
				break;
		}
	}
}

function hideDIV(divID) {
    var divPop = getObjectByID(divID);
    if (divPop != null) {
        divPop.style.display = "none";
    }
}

/*
function showDIV(divID, z){
	var divPop = getObjectByID(divID);
	if (divPop != null){
		divPop.style.zIndex = z;
		divPop.style.display = "block";
	}
}

function hideDIV(divID){
	var divPop = getObjectByID(divID);
	if (divPop != null){
		divPop.style.display = "none";
	}
}

function showDIVv(divID){
	var divPop = getObjectByID(divID);
	if (divPop != null){
		divPop.style.visibility = "visible";
	}
}

function hideDIVv(divID){
	var divPop = getObjectByID(divID);
	if (divPop != null){
		divPop.style.visibility = "hidden";
	}
}
*/
