function CopySelectObjectText(From_SelectObj, To_Object) {
	SelectObj_Len = From_SelectObj.options.length;
	for (var i=0; i<SelectObj_Len ; i++) {
		if (From_SelectObj.options[i].selected==true) {
			SelectObj_Text = From_SelectObj.options[i].text;
			To_Object.value = SelectObj_Text;
			break;
		}
	}		
}

function toggle(id, pic1, pic2) {
//	window.alert(pic1);
	toggle_pic = document.getElementById("toggleInfoPic"+id);
	target = document.getElementById("toggleInfo"+id);
	if (target.style.display == "none"){
		target.style.display="";
		toggle_pic.src=pic2;
	} else {
		target.style.display="none";
		toggle_pic.src=pic1;
	}
}

function toggleRecord(objectId) {
//	window.alert(document.location);
	target = document.getElementById(objectId);
	if (target.style.display == "none"){
		target.style.display="";
	} else {
		target.style.display="none";
		document.getElementById("checkbox_viewall").checked=false;
	}
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function expandAll(isTrue, expandPic, collapsePic) {
//	window.alert("COOKIES: " + document.cookie);
	var divElem = document.getElementsByTagName("DIV");
	setCookie("expandSet", "1", null);
	setCookie("expandAll", (isTrue ? "1" : "0"), 30);
	for(i=0; i<divElem.length; i++){
		idStr = divElem[i].id;
		if (idStr.match("toggleInfo")!=null) {
			recordId = idStr.substr(10);
			target = document.getElementById("toggleInfoPic"+recordId);
			if (isTrue){ // do Expand
				divElem[i].style.display = "";
				target.src=collapsePic;
			} else { // do Collapse
				divElem[i].style.display = "none";
				target.src=expandPic;
			}
		}
	}
//	window.alert("COOKIES: " + document.cookie);
}

/* This is for action=showLL
 * 
 */
function expandAll2(id) {
	var divElem = document.getElementsByTagName("DIV");
	setCookie("expandSet2", "1", null);
//	window.alert(id.checked);
	for(i=0; i<divElem.length; i++){
		idStr = divElem[i].id;
		if (idStr.match("view")!=null) {
			recordId = idStr.substr(4);
			target = document.getElementById("checkbox"+recordId);
//			window.alert(target.checked);
			if (id.checked==true){ // do Expand
				divElem[i].style.display = "";
				target.checked=true;
			} else { // do Collapse
				divElem[i].style.display = "none";
				target.checked=false;
			}
		}
	}
}

function orderLabelSheet(strUrl){
//	window.alert(strUrl);
	var divElem = document.getElementsByTagName("DIV");
	var view="";
	for(i=0; i<divElem.length; i++){
		idStr = divElem[i].id;
		if (idStr.match("view")!=null) {
			recordId = idStr.substr(4);
			record = document.getElementById("checkbox"+recordId);
			if (record.checked==true){ // do Expand
				view += recordId + ",";
			} 
		}
	}
	window.top.location= strUrl + "&view=" + view;
}

function move_selected_objects(Form, From_SelectObj, To_SelectObj) {
//	From_Name = From_SelectObj.name;
//	window.alert("FROM_name="+From_Name);
//	window.alert("FROM_Length="+From_SelectObj.options.length);
	
//	To_Name = To_SelectObj.name;
//	window.alert("TO_NAME="+To_Name);
//	window.alert("LEN="+To_SelectObj.options.length);
	
	From_LEN = From_SelectObj.options.length;
	for (var i=0; i<From_LEN ; i++) {
		if (From_SelectObj.options[i].selected==true) {
			// E.g: Text = Wild Pitch
			Text = From_SelectObj.options[i].text;

			// E.g: Value is LL_id = 27
			Value = From_SelectObj.options[i].value;

			// Insert new option in TO list
			To_NextIndex = To_SelectObj.options.length;
			To_SelectObj.options[To_NextIndex] = new Option(Text, Value, false, false);

			// Remove option in FROM list
			From_SelectObj.options[i] = null;

			// Create new hidden object
	//		document.all.LL_update.innerHTML = document.LL_update.innerHTML + "<input type=hidden name=Alex value='any Value'>";
			var To_NewHidden = document.createElement('INPUT');
			To_NewHidden.setAttribute('type', 'hidden');
			To_HiddenName = To_SelectObj.name+"_array["+Value+"]";
			To_NewHidden.setAttribute('name', To_HiddenName);
			To_NewHidden.setAttribute('value', Text);

			// Append new hidden object in TO list
			document.LL_update.appendChild(To_NewHidden);
			//document.LL_update.removeChild(To_NewHidden);
			
			
			// Delete hidden object attribute "NAME" in FROM list
			From_HiddenName = From_SelectObj.name+"_array["+Value+"]";
			NodeList=document.LL_update.getElementsByTagName("INPUT");
			for (var index2=0; i<NodeList.length ; index2++) {
				Node = NodeList.item(index2);
				if (Node.getAttribute("name")==From_HiddenName) {
					Node.removeAttribute("name");
					break;
				}
			}

			// Recalulate length
			From_LEN = From_SelectObj.options.length;
			i--;
		}
	}
}



function set_selected_action(SelectObject) {
	//window.alert("HEJ");
	//window.alert(SelectObject);
	Index = SelectObject.selectedIndex;
	//window.alert("Index="+Index);
	New_URL = SelectObject.options[Index].value;
	//Form.action = New_Action;
	//window.alert("New Action="+New_Action+"\nForm Action="+Form.action);
	//top.frames[1].location.href = New_URL;
	top.location = New_URL;
	SelectObject.selectedIndex = 0;
	//window.location.href = New_Action;
	//Form.submit();
}

function copy_text_input(Text_Obj1, Text_Obj2) {
//	window.alert("Conf Value="+Text_Obj1.value);
//	window.alert("Conf Value="+Text_Obj2.value);
	Text_Obj2.value = Text_Obj1.value;
}

function set_page(SelectObject) {
	Selected_Index = SelectObject.selectedIndex;
//	window.alert("Selected_Index = " + Selected_Index);
	Main_URL = SelectObject.options[Selected_Index].value;
//	window.alert(New URL = " + SelectObject.options[Selected_Index].text);
	top.location.href = Main_URL;
}


function submit_new_param(Form, www_url, obj, param) {
//	window.alert("www="+www_url);
	NewAction = www_url+"&"+param+"="+obj.value;
//	window.alert("NewAction="+NewAction);
	Form.action = NewAction;
	Form.submit();
}


function submit_search(Form, www_url, objSearchText, objSelectFields) {
//	window.alert(www_url);
	s_txt = new String(objSearchText.value); // Search text submitted by user
	s_txt3 = unescape(s_txt);
	pattern = /\s/; // \s=space
	s_List = s_txt.split(pattern);
	if (s_txt == "" || s_List.length==0) {
		window.alert("You must enter a valid search value before pressing the \"Search\" button");
		return false;
	} else {
		s_txt2 = new String("");
		replace = new String("%2B");
		for (ndx=0 ; ndx < s_List.length-1 ; ndx++) {
			s_txt2 += s_List[ndx].replace("+", replace) + "%20";
//			window.alert("s_List[" + ndx + "]=" + s_List[ndx]);
		}
		s_txt2 = s_txt2 + s_List[s_List.length-1].replace("+", replace);
		s_fields = "&s_fields="+objSelectFields.value
		Form.action = www_url + s_fields + "&s_txt=" + s_txt2;
//		window.alert("action="+Form.action);
		Form.submit();
	}
}

function window_alert(TEXT_STRING){
	window.alert(TEXT_STRING);
}

function preview_record(form, url) {
	//window.alert("FORM TARGET = [" + form.target + "]");
	//window.name=
	window.open(url, "Preview", 'width=665, height=800, status=no, directories=no, toolbar=no, location=yes, menubar=no, scrollbars=yes, resizable=yes');
	OldTarget = form.target;
	OldAction = form.action;
	form.target = "Preview";
	//window.alert("form.target " + form.target);
	form.action = url;
	form.submit();
	form.target = OldTarget;
	form.action = OldAction;
	return false;
}


function SubmitAddRemoveLine(Form, NewAction, FormObject, RecordSide) {
	//window.alert("FORM = " + Form.name);	
	//Form.action = NewAction;
	FormObject.value = RecordSide;
}


function popup_confirm(msg) {
	return window.confirm(msg);
}

function change_site() {
   var site = document.monform.monpopup.selectedIndex;
   window.location.href = document.monform.monpopup.options[site].value;
}

function sort_submit(form, name) {
	NewAction = name.value;
	form.action = NewAction;
	//window.alert("new site = " + form.action);
	form.submit();
}

function form_submit(form) {
	//window.alert("Hej");
	//window.alert("FORM = " + form.name);
	//form.action = top.location.href;
	//window.alert("cBox35 = " + form.cBox35.value );
	//window.alert("Form1 Elements = " + form.elements[1]);
	form.submit();
}

function submit_writeN_form(form, SelectObject) {
	//window.alert("Form="+form.name+"\n Obj.name="+SelectObject.name+"\n Obj.Val="+SelectObject.value+"\n "+SelectObject);
	Selected_Index = SelectObject.selectedIndex;
	form.action = SelectObject.options[Selected_Index].value;
	form.submit();
}

function submit_new_action(form, newAction) {
	//window.alert("OLD ACTION = " + form.action);
	form.action = newAction;
	//window.alert("NEW ACTION = " + form.action);
	form.submit();
	return false;
}

function submit_Nrecords(Form, obj, www_url) {
	//window.alert("Form.action = "+Form.action);
	//window.alert("www_url = "+www_url);
	//window.alert("N_RECORDS_OBJECT = "+"N");
	Form.action = www_url + "&n="+obj.value; // add "N" param to url
	//window.alert("Form.action = "+Form.action);
	Form.submit();
//	setTimeout('top.frames[1].location.href = Main_URL',1400);
}



function submit_new_action2(form, newAction) {
	//window.alert("ONEW ACTION = " + newAction);
	//window.alert("URL=" + top.frames[1].location.href);
	form.action = newAction;
	//form.action = top.frames[1].location.href;
	//window.alert("NEW ACTION = " + form.action);
	form.submit();
//	window.location.href = newAction;
	//return false;
}


function submit_event_trigger_form(form, Check_Box) {
	window.alert("action"+form.action);
	window.alert("top location"+top.location);
	form.action = top.location;
	form.event_trigger.value = Check_Box.name;
	form.submit();
}

function submit_LL_sheet(form, view_str) {
//	window.alert("view= "+view_str);
	form.action = form.action+"&view="+view_str;
//	window.alert("action= "+form.action);
	form.submit();
}



function quick_navigate(Current_URL, Select_Object) {
	//window.alert("HEJ!");
	//window.alert(Select_Object);
	TAG = Select_Object.value;
	//window.alert("TAG = " + TAG);
	//window.alert("Current URL="+window.location);
	//Current_URL = top.frames[3].location;
	New_URL = Current_URL + "#" + TAG;
	//Old_URL = top.frames[3].location;
	//window.alert("OLD = "+window.location+ "\nNEW = " + New_URL);
	//top.frames[3].location = New_URL;
  	window.location.href = New_URL;
}

