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) {
  	if (document.getElementById(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 (sd2)");
		}
	}
}
function hideDiv2(div_id) {
	if (document.getElementById(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 (hd2)");
		}
	}
}

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

function openInviteWin()  {				
	editwin=window.open(("/grp-new/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
	*/
	console.log(select_object);
	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(document.estiForm.productFamily.value);
		//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) {
		alert('test');
		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 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();
    }
}