function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showDiv2(div_id) {
  
	var style_sheet = getStyleObject(div_id);
	if (style_sheet) {
		changeObjectVisibilityBetter(div_id, "block");
	}
	  
	else {
		alert("Sorry, this only works in browsers that support Dynamic HTML");
	}
}
function hideDiv2(div_id) {
	var style_sheet = getStyleObject(div_id);
	  
	if (style_sheet) {
		changeObjectVisibilityBetter(div_id, "none");
	}
	  
	else {
		alert("Sorry, this only works in browsers that support Dynamic HTML");
	}
}

function getStyleObject(objectId) {

	// checkW3C DOM, then MSIE 4, then NN 4.
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	
	else if (document.all && document.all(objectId)) {  
		return document.all[objectId].style;
	} 
   
	else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId];
	} 
   
	else {
		return false;
	}
}

function changeObjectVisibilityBetter(objectId, newVisibility) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);
    /* then if we find a stylesheet, set its visibility
       as requested */

    if (styleObject) {
		styleObject.display = newVisibility;
		return true;
    } 
    
    else {
		return false;
    }
}


function openStatus() {
	progresswin = window.open('/grp/jsp/progressAJAX.jsp','ProgressWindow','scrollbars=no,status=no,width=500,height=165');
}

function openInviteWin()  {				
	editwin=window.open(("/grp/jsp/invite.jsp"), "new_win", "width=500,height=300,toolbar=0,location=0,status=0,scrollbars=1,resizable=1");
	loaded=false;				
}

function getFileName(inputFile) {
	filePath = inputFile.value; 
	if (navigator.platform.indexOf("Win") >= 0) {
		f = filePath.substring(filePath.lastIndexOf("\\")+1, filePath.length+1);
	}
	if (navigator.platform.indexOf("Mac") >= 0) {
		f = filePath.substring(filePath.lastIndexOf("\/")+1, filePath.length+1);
	}
	return f;
	 
}

function hasInvalidName(inputFile, fileLabel) {
	
	fileName = getFileName(inputFile);
	
	quote = "\""; // quote character is invalid
	amp = "&"; // & character is invalid
	wild = "*"; // * character is invalid
	question = "?"; // ? is invalid;
	plus = "+"; // + is invalid;
	colon = ":"; // colon invalid
	
	if (fileName.indexOf(quote) > -1) {
		alert("Sorry, quotes are not allowed in filenames. Please rename " + fileLabel + " and try again.\n\n***You will need to rename the file on your local computer and then reselect it for uploading.");
		return true;
	}
	else if (fileName.indexOf(amp) > -1) {
		alert("Sorry, The '&' character is not allowed in filenames. Please rename " + fileLabel + " and try again.\n\n***You will need to rename the file on your local computer and then reselect it for uploading.");
		return true;
	}
	else if (fileName.indexOf(wild) > -1) {
		alert("Sorry, The '*' character is not allowed in filenames. Please rename " + fileLabel + " and try again.\n\n***You will need to rename the file on your local computer and then reselect it for uploading.");
		return true;
	}
	else if (fileName.indexOf(question) > -1) {
		alert("Sorry, The '?' character is not allowed in filenames. Please rename " + fileLabel + " and try again.\n\n***You will need to rename the file on your local computer and then reselect it for uploading.");
		return true;
	}
	else if (fileName.indexOf(plus) > -1) {
		alert("Sorry, The '+' character is not allowed in filenames. Please rename " + fileLabel + " and try again.\n\n***You will need to rename the file on your local computer and then reselect it for uploading.");
		return true;
	}
	else {
		return false;
	}
}


/*
*inspects the select object passed to me, and calls the appropriate swap funtion to show visual aid
*/
function inspect(select_object) {
	/*
	*if the select value is 'no' then refer to the default color select object simce it looks pretty
	*/
	
	/* as of 5/18/06 this function is being shut off.  We're no longer
		showing 4/4, 4/1, and 4/0 example images.*/
	/*if (select_object.options[select_object.selectedIndex].value == "no") {
		select_object = document.estiForm.colors;
	}
	swap(
		document.images['visdesc'], 
		document.images['vislabel'], 
		document.images['visimage'], 
		('visdesc' + select_object.options[select_object.selectedIndex].value), 
		('vislabel' + select_object.options[select_object.selectedIndex].value), 
		('visimage' + select_object.options[select_object.selectedIndex].value)
		);
	*/
}

function bind_inspect(select_object) {
	/*
	*if the select value is 'no' then refer to the default fold select object which is blank
	*/
	if (select_object.options[select_object.selectedIndex].value == "no") {
		swap2(document.images['bind_visimage'],  ('visimageno'));
	}
	if (select_object.name == "pages") { //special case for multi-page image swap
	   swap2(document.images['bind_visimage'], ('visimage' + (eval(select_object.options[select_object.selectedIndex].value) + 4)));
	}
	else { //everything else
	   swap2(document.images['bind_visimage'], ('visimage' + select_object.options[select_object.selectedIndex].value));
	}
}


function folder_inspect() {
	/*
	*if the select value is 'no' then refer to the default fold select object which is blank
	*/
	a = document.estiForm.folderStyle;
	b = document.estiForm.slitSide;
	c = document.estiForm.slitAngle;
	
	folderDependencies(a,b,c);
	
	if (document.estiForm.productFamily.value == "Folder" || document.estiForm.productFamily.value == "3 Panel Folder") {
		//alert(a.value + b.value + c.value);
		//alert((a.selectedIndex + 1) + " " + (b.selectedIndex + 1) + " "  + (c.selectedIndex + 1));
		swap2(document.images['bind_visimage'], ('visimage' + (a.selectedIndex + 1) + (b.selectedIndex + 1) + (c.selectedIndex + 1)));
	}
	if (document.estiForm.productFamily.value  == "Folder 4x9") {
		//alert(a.value + b.value + c.value);
		//alert((a.selectedIndex + 1) + " " + (b.selectedIndex + 1) + " "  + (c.selectedIndex + 2));
		swap2(document.images['bind_visimage'], ('visimage' + (a.selectedIndex + 1) + (b.selectedIndex + 1) + (c.selectedIndex + 2)));
	}
	
}

function w2pFolder_inspect() {
	/*
	*if the select value is 'no' then refer to the default fold select object which is blank
	*/
	a = document.estiForm.folderStyle;
	b = document.estiForm.slitSide;
	c = document.estiForm.slitAngle;
	
	folderDependencies(a,b,c);
	
	if (a.value == "BothPockets") {
	swap2(document.images['bind_visimage'], ('visimage3' + (b.selectedIndex + 1) + (c.selectedIndex + 1)));
	}	
	else if (a.value == "LeftPocket") {
	swap2(document.images['bind_visimage'], ('visimage11' + (c.selectedIndex + 1)));
	}
	else {
	swap2(document.images['bind_visimage'], ('visimage22' + (c.selectedIndex + 1)));
	}

}

function folderDependencies(a,b,c) {
	//folderStyle limits slit side 
	if (document.estiForm.productFamily.value != "3 Panel Folder" && (a.selectedIndex + 1)==1 || (a.value == "LeftPocket")) {
		b.selectedIndex=0;
		b.disabled=true;
		hideDiv2('slitside');
		hideDiv2('slitside2');
	}
	else if (document.estiForm.productFamily.value != "3 Panel Folder" && (a.selectedIndex + 1)==2 || (a.value == "RightPocket")) {
		b.selectedIndex=1;
		b.disabled=true;
		hideDiv2('slitside');
		hideDiv2('slitside2');
	}	
	else if (document.estiForm.productFamily.value != "3 Panel Folder") {		
		showDiv2('slitside');
		showDiv2('slitside2');
		b.disabled=false;
	}
	else if (document.estiForm.productFamily.value == "3 Panel Folder" && (a.selectedIndex + 1)==1) {
		b.selectedIndex=0;
		b.disabled=true;
		hideDiv2('slitside');
		hideDiv2('slitside2');
	}
	else if (document.estiForm.productFamily.value == "3 Panel Folder" && (a.selectedIndex + 1)==2) {
		showDiv2('slitside');
		showDiv2('slitside2');
		b.disabled=false;
	}	
	if (b && b.selectedIndex == 2) {// no slits
		c.selectedIndex = 3;
		c.disabled=true;
		hideDiv2('slitangle');
		hideDiv2('slitangle2');
	}
	else {
		showDiv2('slitangle');
		showDiv2('slitangle2');
		c.disabled=false;

	}
	if (document.estiForm.productFamily.value == "Folder" || document.estiForm.productFamily.value == "3 Panel Folder") {
		if (c && c.selectedIndex == 2) {// no slits
			hideDiv2('slitside');
			hideDiv2('slitside2');
		}
	}
	else if (document.estiForm.productFamily.value == "Folder 4x9") {
		if (c && c.selectedIndex == 1) {// no slits
		hideDiv2('slitside');
		hideDiv2('slitside2');
		}
	}	
}	

/*
*this does the neccsary image swapping for the visual aid area based on output of inspect()
*/
function swap(id1,id2,id3,name1,name2,name3)  {
	if (id1 != null) {
		id1.src=eval(name1+".src");
	}
	if (id2 != null) {
		id2.src=eval(name2+".src");
	}
	if (id3 != null) {
		id3.src=eval(name3+".src");
	}
}

function swap2(id1,name1)  {
	if (id1 != null) {
		id1.src=eval(name1+".src");
	}
}

function echeck(str) {
		var myAlert = "Please enter a valid email address";
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert(myAlert);
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(myAlert);
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   alert(myAlert);
		   return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
		   alert(myAlert);
		   return false;
		}
		
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   alert(myAlert);
		   return false;
		}
		
		if (str.indexOf(dot,(lat+2))==-1){
		   alert(myAlert);
		   return false;
		}
		
		if (str.indexOf(" ")!=-1){
		   alert(myAlert);
		   return false;
		}
		
		return true;					
	}

	function ValidateEmail(inputFormElement){
		var emailID=inputFormElement;
		
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please enter an email address");
			emailID.focus();
			return false;
		}
		
		var isValidEmail = echeck(emailID.value);
		if (!isValidEmail) {
			emailID.focus();
			return false;
		}
		
		return true;
	 }
		 
	function stopRKey(evt) { 
		var evt = (evt) ? evt : ((event) ? event : null); 
		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
		//alert(node.type);
		if ((evt.keyCode == 13) && (node.type=="text" || node.type=="select-one" || node.type=="radio" || node.type=="checkbox" || node.type=="password"))  {return false;} 
	} 

	
function clearEmptyBusCardNames() { 
	if (document.getElementById('bc_name_two') && document.getElementById('bc_name_two').style.display == 'none') {
		//alert("clearing name 2");
		document.estiForm.cardName2.value = "";		
		document.estiForm.cardQuant2.value = "";
	}
	if (document.getElementById('bc_name_three') && document.getElementById('bc_name_three').style.display == 'none') {
		//alert("clearing name 3");		
		document.estiForm.cardName3.value = "";		
		document.estiForm.cardQuant3.value = "";
	}
	if (document.getElementById('bc_name_four') && document.getElementById('bc_name_four').style.display == 'none') {
		document.estiForm.cardQuant4.value = "";
		document.estiForm.cardName4.value = "";
	}
	if (document.getElementById('bc_name_five') && document.getElementById('bc_name_five').style.display == 'none') {
		document.estiForm.cardQuant5.value = "";
		document.estiForm.cardName5.value = "";
	}
	if (document.getElementById('bc_name_six') && document.getElementById('bc_name_six').style.display == 'none') {
		document.estiForm.cardQuant6.value = "";
		document.estiForm.cardName6.value = "";
	}
	if (document.getElementById('bc_name_seven') && document.getElementById('bc_name_seven').style.display == 'none') {
		document.estiForm.cardQuant7.value = "";
		document.estiForm.cardName7.value = "";
	}
	if (document.getElementById('bc_name_eight') && document.getElementById('bc_name_eight').style.display == 'none') {
		document.estiForm.cardQuant8.value = "";
		document.estiForm.cardName8.value = "";
	}
}

function listAlert() {
	alert("IMPORTANT, PLEASE READ: Lists can only be purchased for use with GreenerPrinter orders. Final list purchase will be conducted at checkout. If you choose to cancel your order after checkout, you will still be held liable for the cost of the list.")
}
function trim(strText) { 
	// get rid of leading spaces / tabs / returns 
	while (strText.substring(0,1) == ' ' || strText.substring(0,1) == '\n' || strText.substring(0,1) == '\t') 
		strText = strText.substring(1, strText.length);
	// get rid of trailing spaces 
	//while (strText.substring(strText.length-1,strText.length) == ' ')
	//	strText = strText.substring(0, strText.length-1);
	return strText;
}
function keyEnterToLogin(field, e) {
	var charCode;
    
    if (e && e.which){
        charCode = e.which;
    } else if (window.event) {
        e = window.event;
        charCode = e.keyCode;
    }

    if (charCode == 13) {
        $(field).closest("form").submit();
    }
}

function setAbsoluteVisibilityAndPosition(objectId, x, y) {
	if (document.all) {  // IE4+
		//document.all[objectId].style.posLeft = window.event.x + document.body.scrollLeft + x;
        //document.all[objectId].style.posTop = window.event.y + document.body.scrollTop + y;
        document.all[objectId].style.posLeft = x;
        document.all[objectId].style.posTop = y;      
        document.all[objectId].style.visibility = 'visible';
		return;
		
	} 
   
	else if (document.layers) {  // NN 4+ or W3C DOM		
		document.layers[object].left = x;
        document.layers[object].top = y;
        document.layers[object].visibility = 'visible';
		return;
		
	}
	
	else if (document.getElementById && document.getElementById(objectId)) { //Mozilla, Netscape 6 + 7
		document.getElementById(objectId).style.left = x;
        document.getElementById(objectId).style.top = y;       
		document.getElementById(objectId).style.visibility = 'visible';
		return;
		
	}
	
	else {
		alert("Sorry, this only works in browsers that support Dynamic HTML");
	}
}

var leftCoord = null;
var topCoord = null;

function setVisibilityAndPosition(objectId, x, y) {
	if (document.all) {  // IE4+
		//document.all[objectId].style.posLeft = window.event.x + document.body.scrollLeft + x;
        //document.all[objectId].style.posTop = window.event.y + document.body.scrollTop + y;
        document.all[objectId].style.posLeft = leftCoord + x;  
        document.all[objectId].style.posTop = topCoord + y;        
        document.all[objectId].style.visibility = 'visible';
		
	} 
   
	else if (document.layers) {  // NN 4+ or W3C DOM		
		document.layers[object].left = leftCoord + x + 'px';  
        document.layers[object].top = topCoord + y + 'px';  
        document.layers[object].visibility = 'visible';
		//return document.layers[objectId];
		//return document.all(objectId).style;
	}
	
	else if (document.getElementById) { //Mozilla, Netscape 6 + 7		
		document.getElementById(objectId).style.left = leftCoord + x + 'px';
        document.getElementById(objectId).style.top = topCoord + y + 'px';     
		document.getElementById(objectId).style.visibility = 'visible';
	}
	
	else {
		alert("Sorry, this only works in browsers that support Dynamic HTML");
	}
}

function setMouseCoordinate(e) {
	if (document.layers) { // NN 4+
		leftCoord = e.pageX; 
		topCoord = e.pageY;
	}
	
	else if (document.all) { // IE 4+
		leftCoord = document.body.scrollLeft + event.clientX;
		topCoord = document.body.scrollTop + event.clientY;
	}
	
	else if (document.getElementById) { // NN 6+
		leftCoord = e.pageX; 
		topCoord = e.pageY;
	}
	
	//window.status = "left=" + left + ", top=" + top;	
}

function hideLayer(objectId) {
    if (document.layers && document.layers[objectId]) {
        document.layers[objectId].visibility = 'hidden';
    }
    
    else if (document.all) {
        document.all[objectId].style.visibility = 'hidden';
    }
    
    else if (document.getElementById) {
    	document.getElementById(objectId).style.visibility = 'hidden';
    }
    
}

function hideAll()  {
	changeObjectVisibility("bind_show","hidden");
	changeObjectVisibility("bind_hide","hidden");
}

function hideAllBetter()  {
	changeObjectVisibilityBetter("bind_show","none");
	changeObjectVisibilityBetter("bind_hide","none");
}