// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================
function URLEncodeX( )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = document.URLForm.F1.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	document.URLForm.F2.value = encoded;
  document.URLForm.F2.select();
	return false;
};

function URLDecodeX( )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = document.URLForm.F2.value;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   document.URLForm.F1.value = plaintext;
   document.URLForm.F1.select();
   return false;
};


/* Event Functions */

// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

// Get the obj that starts the event
function getElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.currentTarget;
	}
}
// Get the obj that triggers off the event
function getTargetElement(evt){
	if (window.event){
		return window.event.srcElement;
	}else{
		return evt.target;
	}
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
	if (typeof obj.onselectstart != 'undefined'){
		addEvent(obj,"selectstart",function(){ return false;});
	}
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
	if(typeof obj.selectionEnd != "undefined"){
		return obj.selectionEnd;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}

		try{
			Lp.setEndPoint("EndToEnd",M);
		}catch(e){
			return -1;
		}finally{
			var rb=Lp.text.length;
			if(rb>obj.value.length){
				return -1;
			}
			return rb;
		}
		/*
		Lp.setEndPoint("EndToEnd",M);
		var rb=Lp.text.length;
		if(rb>obj.value.length){
			return -1;
		}
		return rb;*/
	}
}
// Get the start position of the caret in the object
function getCaretStart(obj){
	if(typeof obj.selectionStart != "undefined"){
		return obj.selectionStart;
	}else if(document.selection&&document.selection.createRange){
		var M=document.selection.createRange();
		try{
			var Lp = M.duplicate();
			Lp.moveToElementText(obj);
		}catch(e){
			var Lp=obj.createTextRange();
		}

		try{
			Lp.setEndPoint("EndToEnd",M);
		}catch(e){
			return -1;
		}finally{
			var rb=Lp.text.length;
			if(rb>obj.value.length){
				return -1;
			}
			return rb;
		}
	}
}
// sets the caret position to l in the object
function setCaret(obj,l){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(l,l);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',l);
		m.collapse();
		m.select();
	}
}
// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
	obj.focus();
	if (obj.setSelectionRange){
		obj.setSelectionRange(s,e);
	}else if(obj.createTextRange){
		m = obj.createTextRange();		
		m.moveStart('character',s);
		m.moveEnd('character',e);
		m.select();
	}
}

/*    Escape function   */
String.prototype.addslashes = function(){
	return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/*String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}*/
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
/* --- Escape --- */

/* Offset position from top of the screen */
function findPos(obj) {
	if (!obj) return ;
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function curTop(obj){
	toreturn = 0;
	while(obj){
		if(obj.scrollTop) toreturn -= obj.scrollTop;
		toreturn += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return toreturn;
}
function curLeft(obj){
	toreturn = 0;
	while(obj){
		if(obj.scrollLeft) toreturn -= obj.scrollLeft;
		toreturn += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	return toreturn;
}

function getPopupTop(active_obj, popup_height){
	var nTop_obj = curTop(active_obj);
	var nTop = nTop_obj + active_obj.offsetHeight;
	//alert(nTop + popup_height);
	//alert(document.body.clientTop + document.body.clientHeight);
	if(nTop + popup_height > document.body.clientTop + document.body.clientHeight){
		nTop = nTop_obj - popup_height - 5 ;
	}
	return nTop + 'px';
}

/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}
function isObject(o) {
  return (typeof(o)=="object");
}
function isArray(obj) {
    return obj.constructor == Array;
} 
function isFunction(o) {
  return (typeof(o)=="function");
}
function isString(o) {
  return (typeof(o)=="string");
}

function CSN(sValue) {
	if(isNumber(sValue)) return sValue;
	sValue = ''+sValue;
	sValue = sValue.replace(/\,/gi,'');
	sValue = sValue.replace(/\$/gi,'');
	value = parseFloat(sValue);
	return (value?value:0);
}

function FormatNumber(fValue, nDecSize) {
	var sValue='';
	nDecSize = (isNumber(nDecSize)?nDecSize:2);
	fValue = CSN(fValue);
	if (fValue){
		sValue = fValue.toFixed(nDecSize);
		return addCommas(sValue);
	}
	return sValue;
}

function HTMLFormatNumber(fValue, nDecSize, zero_caption) {
	var sValue='&nbsp';
	nDecSize = (isNumber(nDecSize)?nDecSize:2);
	fValue = CSN(fValue);
	if (fValue){
		sValue = fValue.toFixed(nDecSize);
		return addCommas(sValue);
	} else {
		if(zero_caption) sValue = zero_caption;
	}
	return sValue;
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


/* Object Functions */

function replaceHTML(obj,text){
	while(el = obj.childNodes[0]){
		obj.removeChild(el);
	};
	obj.appendChild(document.createTextNode(text));
}

function urlencode(str) {
	str = escape(''+str);
	str = str.replace(/\+/g, '%2B');
	//str = str.replace(/\%\2\0/g, '+');
	str = str.replace(/\*/g, '%2A');
	str = str.replace(/\\/g, '%5C');
	//str = str.replace(/\\/g, '%2F');
	str = str.replace(/\//g, '%2F');
	str = str.replace(/\@/g, '%40');
	return str;
}

function HTMLEncode(str) {
	str = ''+str;
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/\n/g, "<br>");
	return str;
} 


function urldecode(str) {
	str = str.replace(/\+/g, ' ');
	str = unescape(str);
	return str;
}

function GetAddress(Street, City, State, Zip, Phone, Fax, URL, Email) {
	var ret = Street;
	var Phone = Phone || '';
	var Fax = Fax || '';
	var URL = URL || '';
	var Email = Email || '';
	
	if((City+State+Zip).length){
		if (ret.length) ret += "\n";
		ret += City+', '+State+' '+Zip;
	}
	if((Phone+Fax).length){
		if (ret.length) ret += "\n";
		ret += (Phone.length? 'TEL: '+Phone: '')+(Phone.length>0 && Fax.length>0? '    ':'')+(Fax.length? 'FAX: '+Fax: '');
	}
	if(URL.length){
		if (ret.length) ret += "\n";
		ret += URL;
	}
	if(Email.length){
		if (ret.length) ret += "\n";
		ret += Email;
	}
	return (ret);
}

function HTMLGetAddress(Street, City, State, Zip, Phone, Fax, URL, Email) {
	return HTMLEncode(GetAddress(Street, City, State, Zip, Phone, Fax, URL, Email));
}

function getCSSRule(name) {
	for(i=0; i<document.styleSheets.length; i++){
		var css_rules = (document.styleSheets[i].cssRules) ? document.styleSheets[i].cssRules: document.styleSheets[i].rules;
		for(j=0; j<css_rules.length; j++){
			if(css_rules[i].selectorText == name) return css_rules[i];
		}
	}
	return null;
}

function addCSSRule(selector, rules){
	AddStyleSheetSet();

	if (rules.length) {
		if(document.styleSheets[0].addRule) {
			document.styleSheets[0].addRule(selector, rules);
		} else {
			document.styleSheets[0].insertRule(selector + '{' + rules + '}', 0);
		}
	}
}

function AddStyleSheetSet(){
	if (document.styleSheets.length==0){
		var cssNode = document.createElement('style');
		cssNode.type = 'text/css';
		cssNode.rel = 'stylesheet';
		cssNode.media = 'screen';
		cssNode.title = 'dynamicSheet';
		document.getElementsByTagName("head")[0].appendChild(cssNode);
	}
}


/* functions of form post. */
function GetCheckedValue(obj_elem){
	for(var i=0; i<obj_elem.length; i++) {
		if (obj_elem[i].checked) return obj_elem[i].value;
	}
	return null;
}

function SetCheckValue(obj_elem, value){
	for(var i=0; i<obj_elem.length; i++) {
		if (obj_elem[i].value==value) {
			obj_elem[i].checked=true;
			break;
		}
	}
}

function GetSelectedValue(obj_elem){
	if(obj_elem.selectedIndex>=0) {
		return parseInt(obj_elem.options[obj_elem.selectedIndex].value);
	}
	return null;
}


/* AJAX functions */
//     if (http_request.overrideMimeType) http_request.overrideMimeType('text/html');
function HttpFormPost(obj_form) {
	var poststr = '', elem, elem_ok, elem_value; 
	
	if (!CheckData(obj_form)) return;

	for(var s=0; s<obj_form.elements.length; s++){   
		elem = obj_form.elements[s]; 
		elem_ok = false;
		switch(elem.type){
			case 'checkbox': case 'radio':
				if (elem.checked) {
					elem_value = elem.value;
					elem_ok = true;
				}
				break;
			case 'text': case 'textarea':  case 'hidden': case 'password':
				elem_value = elem.value; elem_ok=true; break;
			case 'select-one':
				elem_value = elem.options[elem.selectedIndex].value; elem_ok=true; break;
		}
		if(elem_ok){
			if(poststr.length) poststr += '&';   
			poststr += elem.name + "=" + encodeURI(elem_value);   
		}
	}   

	HttpRequest('POST', obj_form.action, poststr);
}

function SetObjValue(sIDandAttr, sValue) {
	var sTag = sIDandAttr.split(".");
	switch(sTag.length) {
		case 0: break;
		case 1: document.getElementById(sTag[0]).value = sValue; alert(sValue); break;
		default: 
			var i = 0;
			var obj = document.getElementById(sTag[i]);
			for(i=1; i<sTag.length-1; i++)
				obj = obj.getAttribute(sTag[i]);
			if(sTag[i]=='value')
				obj.value = sValue;
			else 
				obj.setAttribute(sTag[i], sValue);
	}
}

function HttpRequest(sMethod, sURL, sArgs, eValStr, sync)
{
	var sText;
	var objReq;
	var sync = sync || true;

	try {	
		if (window.XMLHttpRequest)
			objReq = new XMLHttpRequest();
		else if (window.ActiveXObject)
			objReq = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {	
		objReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	objReq.onreadystatechange = function() {
		if (objReq.readyState == 4){	// Received, OK
			if(objReq.status  == 200) {
				sText = objReq.responseText;
			} else {
				sText = objReq.status  + ',Could not connect to server. please try again';
			}
			var iPos = sText.indexOf(',');
			if(iPos) {
				var ret_code = parseInt(sText.substr(0,iPos));
				if(isNaN(ret_code)) {
					ret_code = -2;
					sText = 'Please login again';
				} else {
					sText = sText.substr(iPos+1);
				}
			} else {
				var ret_code = -1;
			}
			if(ret_code){
				if(ret_code!=1) alert(ret_code + ': ' + sText);
			} else {
				//alert(eValStr.replace(/%RETURN_STRING%/gi, sText));
				//sText = sText.replace(/\\/gi, "\\\\");
				//sText = sText.replace(/\'/gi, "\\\'");
				eval(eValStr.replace(/%RETURN_STRING%/gi, addslashes(sText)));
			}
		}	
	};

	if (sMethod.toUpperCase() != "POST")
		objReq.open("GET", sURL, sync);	
	else {	
		objReq.open("POST", sURL, sync);
		objReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objReq.setRequestHeader("Content-length", sArgs.length);
		objReq.setRequestHeader("Connection", "close");
	}
	objReq.send(sArgs);
}

	function checkEmail(email) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return filter.test(email);
	}


//Dependency popupLayer.js

	function show_pop_update(title, width, height, use_close) {
		if(!title) title = 'Save data';
		if(!width) width = 500;
		if(!height) height = 140;
		
		if(use_close){
			popupLayer.load('pop_update', { 'iframe':'', 'title':title, 'width':width, 
					'height':height, 'inner_html':'<br><p>please wait...</p><p><img src="/image/ani_updating.gif"></p>'} );
		} else {
			popupLayer.load('pop_update', { 'iframe':'', 'imgclose':'', 'title':title, 'width':width, 
					'height':height, 'inner_html':'<br><p>please wait...</p><p><img src="/image/ani_updating.gif"></p>'} );
		}
		popupLayer.show('pop_update', true, true);

	}


function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\0/g,'\\0');
	str=str.replace(/\r/g,'\\r');
	str=str.replace(/\n/g,'\\n');
	return str;
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}


function replace_fix_pos(str, stpos, newstr){
	return str.substr(0,stpos)+newstr+str.substr(stpos+newstr.length);
}

function cloneTableRow(or){
	var tbody = or.parentNode;
	if(tbody.rows.length){
		var nr = tbody.insertRow(-1);
		nr.className = or.className;
		for (var i=0; i<or.cells.length; i++) {
			var c = nr.insertCell(-1);
			c.innerHTML = or.cells[i].innerHTML;
		}
		return nr;
	}
	return null;
}


function ShowHideTableColumn(table, cellIndex, bShow){
	var ths = table.getElementsByTagName("th");
	var tds = table.getElementsByTagName("td");
	var bShow = bShow || false;
	var idx = 0;
	for (idx in ths){
		if (ths[idx].cellIndex == cellIndex){
			ths[idx].style.display = (bShow?'':'none');
		}
	}
	for (idx in tds){
		if(tds[idx].parentNode){
			var adjust = 0;
			switch(tds[idx].parentNode.rowIndex){
				case 1: case 2: 
					adjust =-1; break;
			}
			if (tds[idx].cellIndex == cellIndex + adjust){
				tds[idx].style.display = (bShow?'':'none');
			}
		}
	}
}

function FYN(value){
	value = value.trim();
	value = (value=='Y' || value=='y') ?'Y':'';
	return value;
}

function getObjWidth(Elem) {
	var nWidth = 0;
	var elem = (isString(Elem)) ? elem = document.getElementById(Elem): Elem;
	if(elem.clip){
		nWidth = elem.clip.width;
	} else {
		if (elem.style.pixelWidth) {
			nWidth = elem.style.pixelWidth;
		} else {
			nWidth = elem.offsetWidth;
		}
	}
	return nWidth;
}

function get_document_body(){
	return document.body;
}

function set_input_to_spreadsheet(obj_table){
	var obj = isString(obj_table) ? document.getElementById(obj_table): obj_table;
	var elms = obj.getElementsByTagName('INPUT');
	
	for(var i=0;i<elms.length;i++){
		var elm = elms[i];
		addEvent(elm,"keydown",func_input_to_spreadsheet);
	}
}

function func_input_to_spreadsheet(e){
	var keynum = e.which ? e.which: e.keyCode;
	var active_obj = e.srcElement ? e.srcElement: e.target;
	var cell_obj = active_obj.parentNode;
	var row_obj = cell_obj.parentNode;
	var tbl_obj = row_obj.parentNode.parentNode;
	var step_col = 0;
	var step_row = 0;
	var idx = 0;
	var tmp_obj = null;
	var obj_found = null;
	var do_next = true;
	var do_keyaction = true;

	if(tmp_obj =active_obj.controller){
		if(tmp_obj.run_events){
			do_next = tmp_obj.run_events(e);
		}
	}

	if(do_next!=false){
		do_keyaction = false;
		switch(keynum){
			case 37: //left
				step_col = -1;
				break;
			case 38: //up
				step_row = -1;
				break;
			case 39: //right
				step_col = 1;
				break;
			case 40: //down
				step_row = 1;
				break;
			default:
				do_keyaction = true;
		}

		if(step_col){
			idx = cell_obj.cellIndex + step_col;
			while (tmp_obj = tbl_obj.rows[row_obj.rowIndex].cells[idx]){
				if(obj_found = get_first_child_textbox(tmp_obj)) {
					obj_found.select();
					break;
				}
				idx += step_col;
			}
		}

		if(step_row){
			idx = row_obj.rowIndex + step_row;
			while (tmp_obj = tbl_obj.rows[idx]) {
				tmp_obj = tmp_obj.cells[cell_obj.cellIndex];
				if(obj_found = get_first_child_textbox(tmp_obj)) {
					obj_found.select();
					break;
				}
				idx += step_row;
			}
		}

		if (do_keyaction==false) stopEvent(e);
	}

	
	return do_keyaction;
}

function get_first_child_textbox(obj_container){
	if(obj_container){
		var elms = obj_container.getElementsByTagName('INPUT');
		for (var i=0; i<elms.length; i++) {
			if(elms[i].type == 'text'){
				return elms[i];
			}
		}
	}
	return null;
}

function debug_print(str){
	var x = document.getElementById('id_debug');
	if(x) x.value += "\n" + str;
}

function window_open(href, window_name, size_options){
	var window_options = "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1";
	window_options += ","+(size_options ? size_options:"height=800,width=900");
	window.open (href,window_name,window_options);
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+escape(value)+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



/* site default functions */

function submit_filter(obj_form) {
	if(!obj_form) obj_form = document.getElementById('frmFilter');

	if(obj_form){
		var poststr = '';
		for(var s=0; s<obj_form.elements.length; s++){   
			elem = obj_form.elements[s]; 
			elem_ok = false;
			switch(elem.type){
				case 'checkbox': case 'radio':
					if (elem.checked) {
						elem_value = elem.value;
						elem_ok = true;
					}
					break;
				case 'text': case 'textarea':  case 'hidden': case 'password':
					elem_value = elem.value; elem_ok=true; break;
				case 'select-one':
					elem_value = elem.options[elem.selectedIndex].value; elem_ok=true; break;
			}
			if(elem_ok){
				poststr += "\x7f" + elem.name + "\x08" + elem_value;
			}
		}
		poststr = poststr.substr(1);
		update_filter(get_REQUEST('l'), poststr);

		window.location.replace(window.location.href);
	}
}

function get_REQUEST(ji) {
	var hu = window.location.search.substring(1);
	var gy = hu.split("&");
	for (var i=0;i<gy.length;i++) {
		var ft = gy[i].split("=");
		if (ft[0] == ji) return ft[1];
	}
}

function add_filter(name, value, obj_form){
	if(!obj_form) obj_form = document.getElementById('frmFilter');
	if(obj_form){
		update_filter(get_REQUEST('l'), name+"\x08"+value);
		window.location.replace(window.location.href);
	}
}

function remove_filter(name, obj_form){
	if(!obj_form) obj_form = document.getElementById('frmFilter');
	if(obj_form){
		update_filter(get_REQUEST('l'), name+"\x08");
		window.location.replace(window.location.href);
	}
}


function update_filter(page_name, newfilter, clear_all){
	if(clear_all) eraseCookie(page_name);
	
	var qstr = readCookie(page_name);
	if(!qstr) qstr ='';

	if(newfilter.length)  {
		if (qstr.length) qstr = "\x7f" + qstr;
		var filters = newfilter.split("\x7f");
		for (var i=0; i<filters.length; i++){
			var fitem = filters[i].split("\x08");
			var iPos = qstr.indexOf("\x7f"+fitem[0]+"\x08");
			if(iPos>-1){
				var hd = qstr.substr(0,iPos);
				var iPos = qstr.indexOf("\x7f", iPos+1);
				var ft =(iPos>-1)? qstr.substr(iPos):'';
				qstr = hd + "\x7f" + filters[i] + ft;
			} else {
				qstr += "\x7f" + filters[i];
			}
		}
	}

	qstr = qstr.substr(1);
	createCookie(page_name, qstr);

	return qstr;
}

/* Begin : Drop Shadow */

var gradientshadow={}
	gradientshadow.depth=6 //Depth of shadow in pixels
	gradientshadow.containers=[]

	gradientshadow.create=function(){
		var a = document.all ? document.all : document.getElementsByTagName('*')
		for (var i = 0;i < a.length;i++) {
			if (a[i].className == "shadow") {
				for (var x=0; x<gradientshadow.depth; x++){
					var newSd = document.createElement("DIV")
					newSd.className = "shadow_inner"
					newSd.id="shadow"+gradientshadow.containers.length+"_"+x //Each shadow DIV has an id of "shadowL_X" (L=index of target element, X=index of shadow (depth) 
					if (a[i].getAttribute("rel"))
						newSd.style.background = a[i].getAttribute("rel")
					else
						newSd.style.background = "black" //default shadow color if none specified
					document.body.appendChild(newSd)
				}
			gradientshadow.containers[gradientshadow.containers.length]=a[i]
			}
		}

		gradientshadow.position()
			window.onresize=function(){
				gradientshadow.position()
			}
	}

	gradientshadow.position=function(){
		if (gradientshadow.containers.length>0){
			for (var i=0; i<gradientshadow.containers.length; i++){
				for (var x=0; x<gradientshadow.depth; x++){
				var shadowdiv=document.getElementById("shadow"+i+"_"+x)
					shadowdiv.style.width = gradientshadow.containers[i].offsetWidth + "px"
					shadowdiv.style.height = gradientshadow.containers[i].offsetHeight + "px"
					shadowdiv.style.left = gradientshadow.containers[i].offsetLeft + x + "px"
					shadowdiv.style.top = gradientshadow.containers[i].offsetTop + x + "px"
				}
			}
		}
	}

/* End : Drop Shadow */
/* onload run   ///gradientshadow.create///  
   relative object setting  ///class="shadow" rel="green"///
*/


function hidden_update(module, type) {
	var obj_id = 'update_hidden';
	var obj_hidden_prev = document.getElementById(obj_id);
	if(obj_hidden_prev){
		document.body.removeChild(obj_hidden_prev);
	}
	var obj_hidden = document.createElement('div');
	with(obj_hidden){
		id = obj_id;
		style.display = 'none';
		frameborder=0;
		width=0;
		height=0;
		obj_hidden.innerHTML = '<iframe name="'+obj_id+'_iframe" id="'+obj_id+'_iframe" src="" '
			+'onload="hidden_update_loaded(0, \''+module+'\', \''+type+'\');" '
			+'onerror="hidden_update_loaded(1, \''+module+'\', \''+type+'\');"></iframe>';
	}
	document.body.appendChild(obj_hidden);
}

function hidden_update_loaded(code, module, type){
	if(code==1){
		if(action_completed) action_completed(module, type, 0, '');
	}
}

function save_form(form, code){
	hidden_update('apply', 's');

	with(form){
		target="update_hidden_iframe" ;
		a.value="s";
	}
}