var myself;
var visited = false;

function optionOff(who) {
	if(!visited) {
		var flag = parseInt(who.value);
		if(flag == 0) {
			alert("Turning these options off means that you will not be able to tell when your admins or clients log in.");
			visited = true;
		}
	}
}

/*
function changeTotal(andSubmit) {
	if(document.nix.admins) {
		var total = (parseInt(document.nix.admins.value) + parseInt(document.nix.clients.value));
		if(total < 2 && andSubmit) {
			if(confirm("Turning these options off means that you will not be able to tell when your admins or clients log in. Are you sure you want to disable this feature? Click OK to disable this feature, or Cancel to cancel")) {
				document.nix.submit();
			}
		} else {
			if(andSubmit) {
				document.nix.submit();
			}
		}
	}
}
*/

function setID(what) {
	myself = what;
}

function changeCat() {
	var where = document.gallery.category.value;
	top.location.href = "index.php?cat="+where;
	document.gallery.mainmenu.seletedIndex = 0;
}

function changeEditCat(mainmenu) {
	if(document.edit) {
		var where = document.edit.ecategory.value;
	}else if(document.imageForm) {
		var where = document.imageForm.ecategory.value;
	}else{
		return false;
	}
	//where=v;
	top.location.href = "index.php?cat="+where+'&mainmenu='+mainmenu;
	//document.gallery.mainmenu.seletedIndex = 0;
}

function mainMenuSelect(what, isadmin) {
	isadmin = parseInt(isadmin);
	var which = eval("document.gallery."+what);
	var where = which.value;
	switch(where) {
		case "email":
		top.location.href="logout.php?block=true&heimdall=";
		break;
		case "password":
		top.location.href="password.php";
		break;
		case "upload":
		top.location.href="selectimage.php";
		break;
		case "dellogo":
		top.location.href="dellogo.php";
		break;
		case "forum":
		top.location.href="messageboard.php";
		break;
		case "sequence":
		top.location.href="sequence.php";
		break;
		case "editallpass":
		top.location.href="editallpass.php";
		break;
		case "music":
		top.location.href="music.php";
		break;
		case "gofish":
		top.location.href="fishclient.php";
		break;
		case "notesvis":
		top.location.href="notesvis.php";
		case "notifs":
		top.location.href="notifs.php";
		break;
		/*
		case "newcat":
		var moniker = window.prompt("Enter the name of the new category you wish to create, then choose the OK button,  if your not sure, choose the cancel button to cancel","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			var max = 30;
			if(moniker.length > max) {
				alert("The category name you have typed is too long. It must not exceed "+max+" characters, including spaces.");
			} else {
				top.location.href="addcat.php?addthis="+moniker;
			}
		}
		break;
		*/
		case "newcom":
		var moniker = window.prompt("Enter the name of the new company, then choose the OK button, if your not sure, choose the cancel button to cancel","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			top.location.href="addcom.php?addthis="+moniker;
		}
		break;
		case "logosize":
		var moniker = window.prompt("Enter a pixel width for the logo","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			top.location.href="logosize.php?newsize="+parseInt(moniker);
		}
		break;
		case "logout":
		if(isadmin > 0) {
			sendAMessage();
		} else {
			top.location.href="logout.php";
		}
		break;
		case "slideshow":
		openSlideshow();
		break;

		case "addpage":
		top.location.href="contmansys/index.php";
		break;
		case "appradmin":
		top.location.href="apradmin.html";
		break;


		case "editmetas":
		top.location.href="editmetas.php";
		break;
		case "advancedsearch":
		top.location.href="advancedsearch.php";
		break;
		/*
		case "xtrainfo":
		top.location.href="xtrainfo.php";
		break;
		*/
		case "uploader":
		top.location.href="imuploader.php";
		break;
		case "suploader":
		top.location.href="uploadfilei.php";
		break;
		case "gadmin":
		top.location.href="gadmin.php";
		break;
		case "promo":
		top.location.href="site_promo.php";
		break;
		case "bugs":
		top.location.href="bugreport.php";
		break;
		/*
		case "batch":
		top.location.href="batch.php";
		break;
		*/
		case "changeadmin":
		top.location.href="changeadmin.php";
		break;
		//case "delpage":
		//top.location.href="contmansys/index.php?mode=delete";
		break;
		case "dellogo":
		top.location.href="dellogo.php";
		break;
		case "deldocket":
		top.location.href="displaydockets.php?delete=true";
		break;
		case "editpage":
		top.location.href="contmansys/index.php?mode=edit";
		break;
		case "supplies":
		top.location.href="addproducts.php";
		break;
		case "visitors":
		top.location.href="visitors.php";
		break;
		case "support":
		top.location.href="supporttypes.php";
		break;
		case "quote":
		top.location.href="invoice.php";
		break;
		case "sendinvoice":
		top.location.href="invoice.php?rightaway=true";
		break;
		case "dockets":
		top.location.href="displaydockets.php";
		break;
		case "editwm":
		top.location.href="editwm.php";
		break;
		case "headerlogo":
		top.location.href="uploadwm.php?headerlogo=true";
		break;
		case "changeheader":
		top.location.href="changeheader.php";
		break;
		case "borderedge":
		top.location.href="borderedge.php";
		break;
		case "converter":
		openConverter();
		break;
		case "calculator":
		openCalculator();
		break;
		case "dof":
		openDOF();
		break;
		case "newclient":
		top.location.href="writeclient.php";
		break;
		case "delflash":
		top.location.href="delflash.php";
		break;
		case "addevent":
		top.location.href="addevent.php";
		break;
		case "calandar":
		top.location.href="events.php";
		break;
		case "editnuclient":
		top.location.href="editnuclient.php";
		break;
		case "email_login":
		top.location.href="email_login.php";
		break;
		case "download":
		top.location.href="ftpentries.php";
		break;
		case "showcal":
		top.location.href="showcalandar.php";
		break;
		case "help":
		switch(isadmin) {
			case 0:
			top.location.href="clienthelp.php";
			break;
			case 1:
			top.location.href="assist_help.php";
			break;
			default:
			top.location.href="help.php";
		}
		break;
		default:
		document.gallery.submit();
	}
}
function closeDC() {
	if(document.all) {
		delcat.style.visibility = "hidden";
	} else {
		if(document.layers) {
			document.delcat.visibility = "hide";
		} else {
			document.getElementById("delcat").style.visibility = "hidden";
		}
	}
	document.gallery.mainmenu.seletedIndex = 0;
}
function closeDCli() {
	if(document.all) {
		delclient.style.visibility = "hidden";
	} else {
		if(document.layers) {
			document.delclient.visibility = "hide";
		} else {
			document.getElementById("delclient").style.visibility = "hidden";
		}
	}
	document.gallery.mainmenu.seletedIndex = 0;
}
function areYouSure(question, who) {
	if(confirm(question)) {
		var theOtherThing = String(who);
		var that = eval("document."+theOtherThing);
		that.submit();
	}else{
		return false;
	}
}
function deleteItOrNot(who, where) {
	if(confirm("Click OK to delete this message, or Cancel to cancel")) {
		top.location.href = "scripts/deletepost.php?post="+who+"&thread="+where;
	}
}
function sendAMessage() {
	if(confirm("Would you like to send out promotional pieces to your clients before signing out? Click the Cancel button to send promotional pieces or choose the OK button to log out")) {
		top.location.href="logout.php";
	} else {
		top.location.href="logout.php?heimdall=";
	}
}
function thankYouForTrying(what, who) {
	alert("Thank you for choosing "+what+", "+who+". Your business is very important.");
	top.location.href = "logout.php";
}
function promptForNewLabel() {
	var label = window.prompt("Enter the new name of the client project, and choose the OK button, if your not sure, choose the cancel button to cancel","");
	if(label != "") {
		document.nix.label.value = label;
		//document.nix.submit();
	} else {
		alert("You did not fill out a client project name");
	}
}
function promptForLabel() {
	var label = window.prompt("Enter the new name of the client project, and choose the OK button, if your not sure, choose the cancel button to cancel","");
	if(label != "" && label != null && label != "undefined") {
		document.nix.label.value = label;
		document.nix.submit();
	} else {
		alert("Opps You forgot to fill out a client project name");
	}
}
function realign(what,how) {
	var theOtherThing = String(what);
	var that = eval("document."+theOtherThing);
	that.action = how;
	that.submit();
}
function realignWithQuestion(question,what,how) {
	if(confirm(question)) {
		var theOtherThing = String(what);
		var that = eval("document."+theOtherThing);
		that.action = how;
		that.submit();
	}
}
function printThat() {
	window.print();
}
function openImgBox(who, tall, wide) {
	window.open("printimg.php?focus="+who,"bebox","top=30,left=30,width="+wide+",height="+tall+",resizable=yes,scrollbars=yes");
}
function openBEBox() {
	window.open("borderedge.php","bebox","top=30,left=30,width=400,height=150,resizable=yes,scrollbars=yes");
}
function openConverter() {
	window.open("exchange.php","bebox","top=30,left=30,width=600,height=800,resizable=yes,scrollbars=yes");
}
function openCalculator() {
	window.open("calculator.html","bebox","top=30,left=30,width=330,height=400,resizable=yes,scrollbars=yes");
}
function openDOF() {
	window.open("dof.html","bebox","top=60,left=60,width=820,height=420,resizable=yes,scrollbars=yes");
}
function openSlideshow() {
	top.location.href="slideshow.php";
	//window.open("images/slideshow/slideshow.php","commentbox","top=50,left=30,width=520,height=520,resizable=yes,scrollbars=yes");
}
function openClientBox() {
	window.open("printclients.php","commentbox","top=50,left=30,width=600,height=300,resizable=yes,scrollbars=yes");
}
function openCommentBox(how) {
	window.open("comments.php?focus="+how+"&list=","commentbox","top=30,left=30,width=600,height=200,resizable=yes,scrollbars=yes");
}
function openUploadHelp() {
	window.open("uploadhelp.php","commentbox","top=30,left=30,width=400,height=400,resizable=yes,scrollbars=yes");
}
function openArchBox(date) {
	window.open("printarchives.php?date="+date,"commentbox","top=100,left=350,width=400,height=500,resizable=yes,scrollbars=yes");
}
function openWMBox(how, mode) {
	if(!mode) {
		window.open("uploadwm.php?mark="+how,"wmbox","top=30,left=30,width=530,height=120,resizable=yes,scrollbars=no");
	} else {
		window.open("uploadwm.php?mark="+how+"&headerlogo="+mode,"wmbox","top=30,left=30,width=530,height=120,resizable=yes,scrollbars=no");
	}
}
function selectAllMessages() {
	for (var i = 0; i < document.nix.elements.length; i++) {
		if(document.nix.elements[i].type == 'checkbox') {
			document.nix.elements[i].checked = !(document.nix.elements[i].checked);
		}
	}
}
function selectAllImages(ofThatForm) {
	var thatForm = eval("document."+ofThatForm);
	for (var i = 0; i < thatForm.elements.length; i++) {
		if(thatForm.elements[i].type == 'checkbox' && thatForm.elements[i].name != 'flash' && thatForm.elements[i].name != 'forsale') {
			thatForm.elements[i].checked = !(thatForm.elements[i].checked);
		}
	}
}

function charslimit(v, num){
	if(v.value.length+1>num){
		v.value=v.value.substring(0,num);
		event.returnValue=false;
		return false;
	}
	return true;
}

function mainMenuSelectX(whatx, isadmin,where) {
	isadmin = parseInt(isadmin);
	//var where = whatx.alt;
	var x=document.getElementById('mainmenu');
	x.value=where;
	if(document.getElementById('clientlist')){
		document.getElementById('clientlist').value=where;
	}
	switch(where) {
		case "email":
		top.location.href="logout.php?block=true&heimdall=";
		break;
		case "password":
		top.location.href="password.php";
		break;
		case "upload":
		top.location.href="selectimage.php";
		break;
		case "dellogo":
		top.location.href="dellogo.php";
		break;
		case "forum":
		top.location.href="messageboard.php";
		break;
		case "sequence":
		top.location.href="sequence.php";
		break;
		case "editallpass":
		top.location.href="editallpass.php";
		break;
		case "music":
		top.location.href="music.php";
		break;
		case "gofish":
		top.location.href="fishclient.php";
		break;
		case "notesvis":
		top.location.href="notesvis.php";
		break;
		case "notifs":
		top.location.href="notifs.php";
		break;
		case "mngcats":
		top.location.href="mngcats.php";
		break;
		/*
		case "newcat":
		var moniker = window.prompt("Enter the name of the new category you wish to create, then choose the OK button,  if your not sure, choose the cancel button to cancel","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			var max = 30;
			if(moniker.length > max) {
				alert("The category name you have typed is too long. It must not exceed "+max+" characters, including spaces.");
				top.location.href='';
			} else {
				top.location.href="addcat.php?addthis="+moniker;
			}
		}else{
			top.location.href='';
		}
		break;
		*/
		case "newcom":
		var moniker = window.prompt("Enter the name of the new company, then choose the OK button, if you not sure, choose the cancel button to cancel","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			top.location.href="addcom.php?addthis="+moniker;
		}else{
			top.location.href='';
		}
		break;
		case "logosize":
		var moniker = window.prompt("Enter a pixel width for the logo","");
		if(moniker != "" && moniker != null && moniker != "undefined") {
			top.location.href="logosize.php?newsize="+parseInt(moniker);
		}else{
			top.location.href='';
		}
		break;
		case "logout":
		if(isadmin > 0) {
			sendAMessage();
		} else {
			top.location.href="logout.php";
		}
		break;
		case "slideshow":
		openSlideshow();
		break;

		//case "addpage":
		//top.location.href="contmansys/index.php";
		//break;
		case "appradmin":
		top.location.href="apradmin.html";
		break;


		case "editmetas":
		top.location.href="editmetas.php";
		break;
		case "advancedsearch":
		top.location.href="advancedsearch.php";
		break;
		case "xtrainfo":
		top.location.href="xtrainfo.php";
		break;
		case "uploader":
		top.location.href="imuploader.php";
		break;
		case "suploader":
		top.location.href="uploadfilei.php";
		break;
		case "gadmin":
		top.location.href="gadmin.php";
		break;
		case "promo":
		top.location.href="site_promo.php";
		break;
		case "bugs":
		top.location.href="bugreport.php";
		break;
		case "batch":
		top.location.href="batch.php";
		break;
		case "changeadmin":
		top.location.href="changeadmin.php";
		break;
		//case "delpage":
		//top.location.href="contmansys/index.php?mode=delete";
		//break;
		case "dellogo":
		top.location.href="dellogo.php";
		break;
		case "deldocket":
		top.location.href="displaydockets.php?delete=true";
		break;
		//case "editpage":
		//top.location.href="contmansys/index.php?mode=edit";
		//break;
		case "supplies":
		top.location.href="addproducts.php";
		break;
		case "visitors":
		top.location.href="visitors.php";
		break;
		case "support":
		top.location.href="supporttypes.php";
		break;
		case "quote":
		top.location.href="invoice.php";
		break;
		case "sendinvoice":
		top.location.href="invoice.php?rightaway=true";
		break;
		case "dockets":
		top.location.href="displaydockets.php";
		break;
		case "editwm":
		top.location.href="editwm.php";
		break;
		case "headerlogo":
		top.location.href="uploadwm.php?headerlogo=true";
		break;
		case "changeheader":
		top.location.href="changeheader.php";
		break;
		case "borderedge":
		top.location.href="borderedge.php";
		break;
		case "layouts":
		top.location.href="changelayouts.php";
		break;
		case "converter":
		openConverter();
		break;
		case "calculator":
		openCalculator();
		break;
		case "dof":
		openDOF();
		break;
		case "newclient":
		top.location.href="writeclient.php";
		break;
		case "delflash":
		top.location.href="delflash.php";
		break;
		case "addevent":
		top.location.href="addevent.php";
		break;
		case "calandar":
		top.location.href="events.php";
		break;
		case "editnuclient":
		top.location.href="editnuclient.php";
		break;
		case "email_login":
		top.location.href="email_login.php";
		break;
		case "download":
		top.location.href="ftpentries.php";
		break;
		case "showcal":
		top.location.href="showcalandar.php";
		break;
		case "systemsetting":
		top.location.href="systemsetting.php";
		break;
		case "orders":
		top.location.href="orders.php";
		break;
		case "pricelist":
		top.location.href="price_list.php";
		break;

		case "smarttransfer":
		top.location.href="uploadfile.php";
		break;
		case "transfer":
		top.location.href="uploadfile.php";
		break;
		case "assignfiles":
		top.location.href="assignfile.php";
		break;
		case "downloadassign":
		top.location.href="listassigns.php";
		break;

		case "help":
		switch(isadmin) {
			case 0:
			top.location.href="clienthelp.php";
			break;
			case 1:
			top.location.href="assist_help.php";
			break;
			default:
			top.location.href="help.php";
		}
		break;
		default:
		document.gallery.submit();
	}
	return false;
}

function submitimg(id,idf,table,field,img){

	document.getElementById('chid').value=id;
	document.getElementById('chidf').value=idf;
	document.getElementById('chtable').value=table;
	document.getElementById('chfield').value=field;
	document.getElementById('chimage').value=img;
	document.getElementById('fupload').submit();

}


function selectallcheckbox(classname){
	var cks=document.getElementsByClassName(classname);
	var full=true;
	for(var i=0;i<cks.length;i++){
		if(!cks[i].checked){
			full=false;
			break;
		}
	}
	full=!full;
	for(var i=0;i<cks.length;i++){
		cks[i].checked=full;
	}

}


function selectalloptions(sel){

	var s=document.getElementById(sel);
	var c=s.options.length;

	var t=true;		// if all selected
	for(var i=0;i<c;i++){
		if(s.options.item(i).selected==true){

		}else{
			t=false;	// found unselected item, break;
			break;
		}
	}

	var to=true;	// if all selected, unselect all
	if(t){
		to=false;
	}

	for(var i=0;i<c;i++){
		s.options.item(i).selected=to;	// select / unselect all
	}

}

