﻿function win(url, winname, winwidth, winheight) {
  if(winwidth>screen.width)
    width = screen.width-50;
  if(winheight>screen.height)
    winheight = screen.height-50;
  offset=0;
  if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1) {
    eval(winname+"=window.open('"+url+"','"+winname+"','titlebar=yes,left='+(((parseInt(screen.width)/2)-parseInt(winwidth/2))+offset)+',top='+(((parseInt(screen.height)/2)-parseInt(winheight/2))+offset)+',status=yes,resizable=no,toolbar=no,scrollbars=no,menubar=no,Width='+winwidth+',Height='+winheight);");
  } else {
    eval(winname+"=window.open('"+url+"','"+winname+"','titlebar=yes,screenX='+(((parseInt(screen.width)/2)-parseInt(winwidth/2))+offset)+',screenY='+(((parseInt(screen.height)/2)-parseInt(winheight/2))+offset)+',status=yes,resizable=no,toolbar=no,scrollbars=no,menubar=no,Width='+winwidth+',Height='+winheight);");
  }
  eval(winname+".focus();");
}

function setCSS() {
   fixIE();
}

function fixIE() {
  // fixes IE6 goofyness by forcing a redraw
  if (document.getElementById) {
    if (navigator.userAgent.indexOf("MSIE 6")!=-1 || navigator.userAgent.indexOf("MSIE 5")!=-1) {
      document.body.className="";
    }
  }
}

function setGridLayout() {
  var cols=3;
  var all_found=false;
  var ctr=1;
  while(!all_found) {
    if(document.getElementById("ProdInfoCell_"+ctr)) {
      var curHeight = document.getElementById("ProdInfoCell_"+ctr).offsetHeight;
      //alert("ctr="+ctr+" ctr%3="+ctr%3);
      if(ctr%3==1) {
        var height1 = document.getElementById("ProdInfoCell_"+(ctr+1)).offsetHeight;
        var height2 = document.getElementById("ProdInfoCell_"+(ctr+2)).offsetHeight;
      } else if(ctr%3==2) {
        var height1 = document.getElementById("ProdInfoCell_"+(ctr-1)).offsetHeight;
        var height2 = document.getElementById("ProdInfoCell_"+(ctr+1)).offsetHeight;
      } else if(ctr%3==0) {
        var height1 = document.getElementById("ProdInfoCell_"+(ctr-2)).offsetHeight;
        var height2 = document.getElementById("ProdInfoCell_"+(ctr-1)).offsetHeight;
      }
      if(height1>height2 && height1>curHeight) {
        document.getElementById("ProdInfoCell_"+ctr).style.border="solid 1px white"
        document.getElementById("ProdInfoCell_"+ctr).style.display="block"
        document.getElementById("ProdInfoCell_"+ctr).style.height=height1+"px";
        document.getElementById("ProdButtonCell_"+ctr).style.display="block"
      } else if(height2>height1 && height2>curHeight) {
        document.getElementById("ProdInfoCell_"+ctr).style.border="solid 1px white"
        document.getElementById("ProdInfoCell_"+ctr).style.display="block"
        document.getElementById("ProdInfoCell_"+ctr).style.height=height2+"px";
        document.getElementById("ProdButtonCell_"+ctr).style.display="block"
      } else {
        document.getElementById("ProdInfoCell_"+ctr).style.border="solid 1px white"
        document.getElementById("ProdInfoCell_"+ctr).style.display="block"
        document.getElementById("ProdInfoCell_"+ctr).style.height=curHeight+"px";
        document.getElementById("ProdButtonCell_"+ctr).style.display="block"
      }
      //alert("curHeight="+curHeight+" height1="+height1+" height2="+height2+" setting new height="+document.getElementById("ProdCell_"+ctr).offsetHeight);
    } else {
      all_found=true;
      break;
    }
    ctr++;
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof(window.onload) != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function enableCCValidators() {
  SetCCValidatorsEnabled(true);
}

function disableCCValidators() {
  SetCCValidatorsEnabled(false);
}

function SetCCValidatorsEnabled(enabled) {
  if (typeof(ValidatorEnable) == 'function') {
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_RequiredFieldValidator1'), enabled);
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_RequiredFieldValidator2'), enabled);
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_RequiredFieldValidator3'), enabled);
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_RequiredFieldValidator4'), enabled);
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_RequiredFieldValidator5'), enabled);
    ValidatorEnable(document.getElementById('ctl00_MainContent_CreditCard_CreditCardNumberCheck'), enabled);
  }
}

function doOnLoad() {
  if(typeof(setCSS)=="function") {
    setCSS();
  }
}

if(window.attachEvent){
	window.attachEvent("onload", doOnLoad);
} else {
	if(document.addEventListener){
		document.addEventListener("load", doOnLoad, false);	
	};
	if(window.addEventListener){
		window.addEventListener("load", doOnLoad, false);	
	};
};
