/**
 * File: popawindow.js
 * By: TL Smoot(tlsmoot@ematic.com)
 *     Brian French(bfrench@ematic.com)
 *     Cliff Lang(cliffl@ematic.com)
 *
 *
 */

var ie4 = (document.all&&navigator.userAgent.indexOf("Opera")==-1)? true:false
var ns6 = (document.getElementById&&!document.all)? true:false
var ns4 = (document.layers)? true:false


document.onload = window.focus();


// Window Opener Function
//self.name = "myWindow";

/* this is the old one

function openWindow(url, name, specs) {
   popupWin = window.open(url, name, specs);
      if (!popupWin.opener) {
         popupWin.opener = self;
      }
}
*/
// to save space, and have more control, i created popupWindow. to prevent bugs i rewrote openWindow
function openWindow(url, name) {
   switch (name){
      case "order" :
         popupWin = window.open(url, name, 'height=450,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
      case "item" :
         popupWin = window.open(url, name, 'height=232,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
      case "itemEdit" :
         popupWin = window.open(url, name, 'height=600,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
      case "Message" :
         popupWin = window.open(url, name, 'height=450,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
      case "aboutpage" :
         popupWin = window.open(url, name, 'height=600,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
      case "banners" :
         popupWin = window.open(url, name, 'height=600,width=650,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
	  default :
         popupWin = window.open(url, name, 'height=400,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
         break;
   }
   if (!popupWin.opener) {
     popupWin.opener = self;
   }
   
}

function resizeWindow(url, h, w) {
   if (h || w){
      window.resizeTo(w,h);
   }
   if (url)
      location.href = url;
}

function helpWindow(url) {
   popupWin = window.open('/cgi-bin/ematic/users/procgi.pl/code/help.p?page=' + url, 'helpWindow', 'height=350,width=500,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=1,toolbar=0');
      if (!popupWin.opener) {
         popupWin.opener = self;
      }
}

function docWindow(url) {
   popupWin = window.open('mforms.p?page=' + url, 'docWindow', 'height=600,width=700,fullscreen=0,location=0,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=0');
      if (!popupWin.opener) {
         popupWin.opener = self;
      }
}

// SSL Cert Display Function
function OpenCertDetails() {
	thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USINFO141-1', 'certDetails', config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}

// Login Form Function
function doLogin(theForm) {
	user = theForm.user.value;
	pass = theForm.pass.value;

	host = document.location.host;
	protocol = document.location.protocol;
	str = protocol + "//" + user + ":" + pass + '@' + host;
	str = str + "/" + user + "/admin/NewLogin";
	
	theForm.action = str;
	theForm.submit();
	self.status = 'Logging you in!';
}

// Loggout Function
var logoutType;

function doLogout(logoutType) {	
	// Switch To A Different User - Send To "Login Again Page"
	if (logoutType == 'switchUser') { 
		var URL = '/Logout/switch_user.html';
		location.replace(URL);
		self.status = 'Logging you out!';
	}
	// Log Off Completely - Send To "Home Page"
	if (logoutType == 'logoutNow') {
		var URL = '/Logout/logging_out.html';
		location.replace(URL);
		self.status = 'Logging you out!';
	}
}

// Date Function
function writeTheDate() {
	thisMonth = new Date();
	document.write("<font face=\"Arial, Helvetica, sans-serif\" size=\"-1\"><b>");
	document.write((thisMonth.getMonth()+1) + "-" + thisMonth.getDate() + "-" + thisMonth.getFullYear());
	document.write("</b></font>");
}

function chkDelete(type) { 
	var ans = "Are you sure you want to delete the " + type; 
	return confirm(ans);
} 


/*
* Used to expand and contract the menus in the site
*/


function expandDiv(tahw) {
  table_contract = new Image(1,1);
  table_contract.src = "/images/nav/menuArrow2.gif";
  table_expand = new Image(1,1);
  table_expand.src = "/images/nav/menuArrow.gif";
  what  = tahw + "_menu"
  where = tahw + "_table"
  gotox  = tahw + "_link"
  if (document.getElementById(what).style.display == "none") {
    document.getElementById(what).style.display = "";
    gotox.href = "#"
  } else {
    document.getElementById(what).style.display = "none";
    gotox.href = "#"
  }
}

function expandDiv2(tahw) {

// has no images
  table_contract = new Image(1,1);
  table_contract.src = "/images/nav/menuArrow2.gif";
  table_expand = new Image(1,1);
  table_expand.src = "/images/nav/menuArrow.gif";
  what  = tahw + "_menu"
  where = tahw + "_table"
  gotox  = tahw + "_link"
  if (document.getElementById(what).style.display == "none") {
    document.getElementById(what).style.display = "";
    gotox.href = "#"
  } else {
    document.getElementById(what).style.display = "none";
    gotox.href = "#"
  }
}

/*
function expandDiv(id) {
	what = id + "_menu"
	where = id + "_table"
	table_contract = new Image(1,1);
	table_contract.src = "/images/nav/menuArrow2.gif";
	table_expand = new Image(1,1);
	table_expand.src = "/images/nav/menuArrow.gif";
	if (ns4){
		if (document.layers[what].visibility == "hide"){
			document.layers[what].visibility = "show"
		}
		else {
			document.layers[what].visibility = "hide"
		}
	}
	else if (ie4){
		if(document.all[what].style.visibility == "hidden"){
			document.all[what].style.visibility = "visible"
		}
		else {
			document.all[what].style.visibility = "hidden"
		}
	}
}

  		if (document.getElementById(what).style.display == "none") {
			document.getElementById(what).style.display = "";
    		where.src = table_expand.src;
    		gotox.href = "#"
  		} else {
    		document.getElementById(what).style.display = "none";
    		where.src = table_contract.src;
    		gotox.href = "#"
  		}



 Written by: Joshua Miller (josh.miller@eagletgi.com)
 Makes the width of forms' textfields in IE look like the width in netscape
 Place this after all form elements on a webpage:
 <script language="JavaScript">
<!-- Begin
jm_fixForms('25');
//  End -->
</script>
*/
function jm_fixForms(decNum){
  if(navigator.appName != 'Netscape'){
    var incrVal="."+decNum;
    for(i=0;i<document.forms.length;i++){
      for(j=0;j<document.forms[i].elements.length;j++){
        var formObj=document.forms[i].elements[j];
        if(formObj.type.toLowerCase() == "text" || formObj.type.toLowerCase() == "password" || formObj.type.toLowerCase() == "file"){
          formincr=formObj.size*eval(incrVal);
          formObj.size=formObj.size+formincr;
        }else if(document.forms[i].elements[j].type.toLowerCase() == "textarea"){
          formincr=formObj.cols*eval(incrVal/5);
          formObj.cols=formObj.cols+formincr;
        }
      }
    }
  }
}

// Makes sure the form only gets submitted once
numberoftimes = 0;
function onlyonce() {
   numberoftimes += 1;
   if (numberoftimes > 1) {
      var themessage = "Please be patient. You have already submitted this form. You will receive a response momentarily.";
      if (numberoftimes == 3) {
         themessage = "Please do not press the submit button multiple times.";
      }
      alert(themessage);
      return false;
   }
   else
   {
      return true;
   }
}
