
// Function that executes function inside input string when enter is pressed.
function doKey(sFunc) {
	if (document.all) {
		whichASC = event.keyCode;
		if(whichASC==13){
			eval(sFunc);
		}       
	}
}

/*	
	NAME: setClass
	FUNC: Will change the class of provided object. Nice for onMouseOver effects.
*/
function setClass(thisobject, className){
	thisobject.className = className;
}

/* 
	Use getElementsBySelector function to select all classes of a certain name
	and then assign functions to those classes
*/
function assignFunctions(){
	assignthese(document.getElementsBySelector('.main_bigbutton'), 'main_bigbutton_over', 'main_bigbutton');
	assignthese(document.getElementsBySelector('.menu_tab_deselected'), 'menu_tab_over', 'menu_tab_deselected');
	assignthese(document.getElementsBySelector('tr td.row_ascending'), 'row_ascending_over', 'row_ascending');
	assignthese(document.getElementsBySelector('tr td.row_descending'), 'row_descending_over', 'row_descending');
	assignthese(document.getElementsBySelector('tr td.row_ASC'), 'row_ascending_over', 'row_ascending');
	assignthese(document.getElementsBySelector('tr td.row_DESC'), 'row_descending_over', 'row_descending');
	assignthese(document.getElementsBySelector('tr td.row_deselected'), 'row_descending_over', 'row_deselected');
	assignthese(document.getElementsBySelector('div.bt'), 'bt_over', 'bt');
	assignthese(document.getElementsBySelector('div.thumbnail'), 'thumbnail_over', 'thumbnail');
}

/*
	Helper function for assignFunctions - this one does the actual assigning of 
	functions.
*/
function assignthese(a, onMouseOver, onMouseOut) {
	for (i = 0; i != a.length; i++) {
		a[i].onmouseover = function() {this.className = onMouseOver}
		a[i].onmouseout = function() {this.className = onMouseOut}
	}
}

/* new on mouse over function */
function over (obj){
	
	obj.className=obj.className+'_over';
}

/* new on mouse out function */
function out (obj){

	var str=obj.className;
	var pos=str.indexOf("_over")
	obj.className=str.substr(0,pos);
}

/* 
	This onclick event gets triggered when a folder is clicked.
	It is supposed to display that folder contents on the frame named 'hoved'
	numID = id of the clicked folder.
*/
function dispMenu(numID,sMode){
	document.HIDDEN_FIELDS.HIDDEN_MENU_ID.value = numID;
	//document.HIDDEN_FIELDS.JSMENU_OBJECT_ID.value = eval('tree'+document.HIDDEN_FIELDS.LANG.value).getSelected().id;

	/* Only redirect parent.hoved if sMode != '1' */
	if ((sMode == '') || (sMode == '2')){
		parent.hoved.location='browse.asp?id='+numID+'&mode='+sMode+'&lang='+document.HIDDEN_FIELDS.LANGUAGE_ID.value;
	}
}
/* 
	Where to go when the root of the folder menu is clicked 
*/
function goHome(sMode){
	/* If sMode contains anything, select root folder for folder return */
	if (sMode == ''){
		parent.hoved.location='start_frame.asp?view=start';
	}
	document.HIDDEN_FIELDS.HIDDEN_MENU_ID.value='';

}

/*
	When clicking a folder inside the file archive, what do then? 
*/
function dispArch(numID,sMode){
	document.HIDDEN_FIELDS.HIDDEN_MENU_ID.value = numID;
	/* Only redirect parent.hoved if sMode = '' */
	if (sMode == ''){
		parent.hoved.location='object_frame.asp?OBJECT_GROUP_ID='+numID+'&EDITOR='+document.HIDDEN_FIELDS.EDITOR.value+'&FIX='+document.HIDDEN_FIELDS.EDITOR.value;
	}
}
/* 
	Where to go when the root of the filearchive is clicked 
*/
function goArchHome(sMode){
	if (sMode == ''){
		document.HIDDEN_FIELDS.HIDDEN_MENU_ID.value = '';
		parent.hoved.location='start_frame.asp?view=start_filearchive&EDITOR='+document.HIDDEN_FIELDS.EDITOR.value+"&OBJECT_GROUP_ID=-1";
	}
}

/* 
	Action for admin menu
*/
function goAdmin(sFile){
	parent.hoved.location=sFile;
}
function goCalculator(sFile){
	 loc = sFile;
	 myWin1 = window.open(loc, "helpWin","width=240,height=410,resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=no");
	 myWin1.focus();
}

/* search ignitor */
function search(){
	document.FORM1.action='find_advanced.asp';
	document.FORM1.submit();
}

/* Display a help record */
function help_rec(menu,id){
	 loc = "help/help_frame.asp?menu=" + menu + "&id=" + id;
	 myWin1 = window.open(loc, "helpWin","width=750,height=500,resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=no");
	 myWin1.focus();
	
	//loc = "help/help_frame.asp?menu=" + menu + "&id=" + id;
	//vReturnValue = window.showModelessDialog(loc , null, "dialogHeight:40;dialogWidth:43")
}

function help_menu(menuid){
	parent.hoved.location='default.asp?menu='+menuid;
}

/* Add to favorites function */
function add_favorite(s,icon){
	loc = "add_favorite_frame.asp?suggestedname="+s+'&icon='+icon;
	myWin1 = window.open(loc, "addFavWin","width=400,height=300,resizable=no,status=yes,toolbar=no,menubar=no,scrollbars=no");
	myWin1.focus();	
}

/* Load a favorite */
function goFavorite(strMENY_URL,strHOVED_URL){
	window.location=strMENY_URL
	window.location=strHOVED_URL;
}



/* Functions for navigating between main tabs. */

	function content(){
		document.location='menu.asp';
		parent.hoved.location='start_frame.asp?view=start';
	}
	function filearchive(){
		document.location='menu_filearchive.asp';
		parent.hoved.location='start_frame.asp?view=start_filearchive';
	}
	function webshop(){
		document.location='menu_webshop.asp';
		parent.hoved.location='start_frame.asp?view=start_webshop';
	}
	function admin(){
		document.location='menu_admin.asp';
		parent.hoved.location='start_frame.asp?view=start_admin';
	}

/* some helper functions for string manipulation */
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/* two functions for sending sms and email. requires FORM1.SQL.value containing
   SQL string with fields EMAIL and/or MOBILE, FNAME, LNAME.
   SQL must be server.URLEncode */
function open_sms(main_id,category,sub_id_field){
	loc = 'send_sms.asp?SQL='+document.FORM1.SQL.value+'&MAIN_ID='+main_id+'&CATEGORY='+category+'&SUB_ID_FIELD='+sub_id_field;
	myWin = window.open(loc, "displayWindow2","width=600,height=400,resizeable=auto,status=no,toolbar=no,menubar=no,scrollbars=1");
	myWin.focus();
}
function open_email(main_id,category,sub_id_field){
	loc = 'send_mail.asp?SQL='+document.FORM1.SQL.value+'&MAIN_ID='+main_id+'&CATEGORY='+category+'&SUB_ID_FIELD='+sub_id_field;
	myWin = window.open(loc, "displayWindow2","width=600,height=400,resizeable=auto,status=no,toolbar=no,menubar=no,scrollbars=1");
	myWin.focus();
}
