/* generic functions called by all or most pages on site */

var mydomain = "cspinet.uaqa.com";
//var mydomain = "cspinet.org";

function openPopup(url) {
        var win;
        var winFeatures = 'width=380,height=500,scrollbars=1,resizable=0,status=0,left=1,top=1';
        var pg = url;
        win = open(pg,"windownew",winFeatures);
        win.focus();
} 

function opensmlPopup(url) {
        var win;
        var winFeatures = 'width=370,height=300,scrollbars=0,resizable=0,status=0,left=1,top=1';
        var pg = url;
        win = open(pg,"windownew",winFeatures);
        win.focus();
} 

function openmdPopup(url) {
        var win;
        var winFeatures = 'width=370,height=400,scrollbars=0,resizable=0,status=0,left=1,top=1';
        var pg = url;
        win = open(pg,"windownew",winFeatures);
        win.focus();
} 

function openvrysmlPopup(url) {
        var win;
        var winFeatures = 'width=370,height=200,scrollbars=0,resizable=0,status=0,left=1,top=1';
        var pg = url;
        win = open(pg,"windownew",winFeatures);
        win.focus();
} 

function closePage() {
  if (window.close)
    window.close()
  else
    alert("Sorry, your browser doesn't support this feature.");
}

function WM_preloadImages() {

/*
WM_preloadImages()
Loads images into the browser's cache for later use.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_preloadImages('image 1 URL', 'image 2 URL', 'image 3 URL', ...);
*/

  // Don't bother if there's no document.images
  if (document.images) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    // Loop through all the arguments.
    var argLength = WM_preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      // For each arg, create a new image.
      document.WM.loadedImages[arg] = new Image();
      // Then set the source of that image to the current argument.
      document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}


function WM_imageSwap(daImage, daSrc){
  var objStr,obj;
  /*
    WM_imageSwap()
    Changes the source of an image.

    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Shvatz
    Author Email: shvatz@wired.com

    Usage: WM_imageSwap(originalImage, 'newSourceUrl');

    Requires: WM_preloadImages() (optional, but recommended)
    Thanks to Ken Sundermeyer (ksundermeyer@macromedia.com) for his help
    with variables in ie3 for the mac. 
    */

  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof daImage == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof daImage == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}

function openPopUp300(url,window) {
/* open new window to size 300 X 255 */
     var winFeatures = 'width=300,height=255,scrollbars=no,resizable=no,menubar=no';
     win = open(url,window,winFeatures);
     win.focus();
}

function PopUpTest(url) {
/* test cookie, open popup on second hit */
	var hours = 24; // number of hours the cookie should last
	var triger = 2; // popup survey when hits = triger
	var expires = new Date((new Date()).getTime() + hours*3600000);
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("nahpopup=");
	if (pos == -1){
		document.cookie = "nahpopup=1; path=/; domain=" + mydomain + "; expires=" + expires; 
	}
	else{
		var start = pos + 9;
		var end = allcookies.indexOf(";",start);
		if (end == -1) end = allcookies.length;
		var hits = allcookies.substring(start,end); // hits
		var num = parseInt(hits); // convert to number
		num = num + 1;
		if (num == triger){
			openPopUp300(url,'nahpopup');
			document.cookie = "nahpopup=" + num + "; path=/; domain=" + mydomain + "; expires=" + expires; 
		}
		else if (num < 10){ 
			document.cookie = "nahpopup=" + num + "; path=/; domain=" + mydomain + "; expires=" + expires; 
		}
	}
}

function preloadImages() {
	if (document.images) { var loadedImages = new Array;
		for(arg=0;arg<preloadImages.arguments.length;arg++) {
			loadedImages[arg] = new Image();
			loadedImages[arg].src = preloadImages.arguments[arg]; 
		} 
	} 
}

function img_hotl (imgName) { 
	if (document.images){ 
		document [imgName].src = "/liquidcandy/images/" + imgName + "_on.gif"; 
	} 
}

function img_cooll (imgName) { 
	if (document.images){ 
		document [imgName].src = "/liquidcandy/images/" + imgName + ".gif"; 
	} 
}

function img_hot (imgName) { 
	if (document.images){ 
		document [imgName].src = "images/" + imgName + "_on.gif"; 
	} 
}

function img_cool (imgName) { 
	if (document.images){ 
		document [imgName].src = "images/" + imgName + ".gif"; 
	} 
}

function img_hotNP (imgName) { 
	if (document.images){ 
		document [imgName].src = "/nutritionpolicy/images/" + imgName + "_on.gif"; 
	} 
}

function img_coolNP (imgName) { 
	if (document.images){ 
		document [imgName].src = "/nutritionpolicy/images/" + imgName + ".gif"; 
	} 
}

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.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_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];}
}