 /////////////////
// VARIABLES 
/////////////////
var preloaderBig = "<center><br><br><br><br><br><br>";
	preloaderBig = preloaderBig+"<img src='https://www.blogdistributor.com/img/loading-big.gif'><br><br><h3>Loading...</h3><br></center>";
var debug = false;

var msg_close = " <a href=\"javascript: Hide('error');\" onmouseover=\"this.style.cursor = 'pointer';\" style='padding-left:5px;text-decoration:none;font-size:16px;float:right;margin-top:-2px;font-weight:800;color:#000000;'>[x]</a>";
var success_close = " <a href=\"javascript: Hide('success');\" onmouseover=\"this.style.cursor = 'pointer';\" style='padding-left:5px;text-decoration:none;font-size:16px;float:right;margin-top:-2px;font-weight:800;color:#000000;'>[x]</a>";

var ajax_requests = new Array();


//////////////////////////////////////////////////////////
// resets element's class name to 'class_name'
//////////////////////////////////////////////////////////
function ClassReset(id,class_name) {
	document.getElementById(id).className = class_name;
}  


////////////////////////////////////////////////////////////////////////
// used to refresh images
////////////////////////////////////////////////////////////////////////
function RefreshImage(object_id,name,path)
{
	var full_path = path+name;
	document.getElementById(object_id).src = "https://www.blogdistributor.com/img/loading-big.gif";
	document.getElementById(object_id).src = full_path;
}

////////////////////////////////////////////////////////////////////////
// blinks objects
////////////////////////////////////////////////////////////////////////
function Blink(object_id,interval) {
	
	if (interval == undefined) {
		interval = 1000;
	} else {
		interval = eval(interval);
	}
	

		
	ChangeOpac(object_id, 40);
	
	setTimeout("ChangeOpac('"+object_id+"', 50);",interval  * 0.05);
	setTimeout("ChangeOpac('"+object_id+"', 55);",interval  * 0.1);
	setTimeout("ChangeOpac('"+object_id+"', 60);",interval  * 0.14);
	setTimeout("ChangeOpac('"+object_id+"', 65);",interval  * 0.18);
	setTimeout("ChangeOpac('"+object_id+"', 70);",interval  * 0.21);
	setTimeout("ChangeOpac('"+object_id+"', 75);",interval  * 0.24);
	setTimeout("ChangeOpac('"+object_id+"', 80);",interval  * 0.26);
	setTimeout("ChangeOpac('"+object_id+"', 85);",interval  * 0.28);
	setTimeout("ChangeOpac('"+object_id+"', 90);",interval  * 0.29);
	setTimeout("ChangeOpac('"+object_id+"', 95);",interval  * 0.3);
	setTimeout("ChangeOpac('"+object_id+"', 100);",interval * 0.31);
	setTimeout("ChangeOpac('"+object_id+"', 95);",interval  * 0.69);
	setTimeout("ChangeOpac('"+object_id+"', 90);",interval  * 0.7);
	setTimeout("ChangeOpac('"+object_id+"', 85);",interval  * 0.72);
	setTimeout("ChangeOpac('"+object_id+"', 80);",interval  * 0.74);
	setTimeout("ChangeOpac('"+object_id+"', 75);",interval  * 0.75);
	setTimeout("ChangeOpac('"+object_id+"', 70);",interval  * 0.78);
	setTimeout("ChangeOpac('"+object_id+"', 65);",interval  * 0.82);
	setTimeout("ChangeOpac('"+object_id+"', 60);",interval  * 0.86);
	setTimeout("ChangeOpac('"+object_id+"', 55);",interval  * 0.91);
	setTimeout("ChangeOpac('"+object_id+"', 50);",interval  * 0.96);
	
	setTimeout("Blink('"+object_id+"','"+interval+"');",interval);
}  

/////////////////////////////////////////////////////////////////
// stops blinking
/////////////////////////////////////////////////////////////////
function BlinkStop(object_id) {
	ChangeOpac(object_id,100);
	Hide(object_id+'_noblink');
}

/////////////////////////////////////////////////////////////////
//change the opacity for different browsers 
/////////////////////////////////////////////////////////////////
function ChangeOpac(object_id, opacity) {
		var object = document.getElementById(object_id).style;
		 
		if (document.getElementById(object_id+'_noblink')) {
			if (document.getElementById(object_id+'_noblink').style.display == 'none') {
				return;
		 }
		}
		
		
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ");"; 
		
}







//////////////////////////////////////////////////////////////////////
// passes either GET or POST variables to the script and returns response text
//////////////////////////////////////////////////////////////////////
function DataPost(vars,element_id,preloader) {
	DataTrade(vars,element_id,preloader,'POST');
}
function DataTrade(vars,element_id,preloader,mode) {   
		
	var xmlHttp = GetXmlHttpObject();
	
	// determining whether to use GET or POST
	if (mode == undefined) { // if mode is not specified
		if (vars.length > 5000) {  // if request is way long, using post
			var mode = "POST"; 
		} else { // otherwise, using get
			var mode = "GET";
		}  
	} 
	
	if (mode == "POST") {
		var url = vars.substring( 0, vars.indexOf("?"));
		var vars = vars.substring( eval(url.length+1), vars.length);
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", vars.length);
		xmlHttp.setRequestHeader("Connection", "close");
	
	} else {
		var url=vars+"&sid="+Math.random();  
	}
	
	// workaround - in the past, some of those might have been specified as blank
	if (element_id == undefined)  { element_id = ""; }
	if (preloader == undefined)   { preloader = ""; }
	
	ajax_requests[ajax_requests.length] = vars;		
	xmlHttp.onreadystatechange = function () {  
		 
		// when data comes back
		if (xmlHttp.readyState==4)   
		{
			
			ajax_requests.splice(array_index(ajax_requests,vars), 1); // removing request that is done running from array
			
			// if target was innerHTML of DOM id or the return function has been used
			if (element_id != "") { 
				if (element_id.indexOf("(") == -1) { // if no special function was used
					document.getElementById(element_id).innerHTML = xmlHttp.responseText;
				} else {
					eval(element_id+urlencode(xmlHttp.responseText)+"')");
				}
			} else {
			// if only return of the value is needed
				return "";
			}
	
		} else if(preloader != "") { 
		// while waiting for data, will show preloader if needed
			document.getElementById(element_id).innerHTML = preloader; 
		}
	}
	
	if (mode == "POST") {
		xmlHttp.send(vars);
	} else { 
		xmlHttp.open("GET",url,true);   
		xmlHttp.send(null); 
	}
	
}




function DataExec(vars)
{
	var xmlHttp = GetXmlHttpObject();
	var url=vars;
	//+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=function () 
	{   
		// when data comes back
		if (xmlHttp.readyState==4) {
			eval(xmlHttp.responseText);
		} 
	}
	xmlHttp.open("GET",url,true);   
	xmlHttp.send(null);  
}





//////////////////////////////////
// gateway to php
/////////////////////////////////
function TradeData(vars,element_id,preloader)
{
	var xmlHttp = GetXmlHttpObject();
	var url=vars+"&sid="+Math.random();
	xmlHttp.onreadystatechange=function () 
	{   
		if ((xmlHttp.readyState==4)&&(element_id!=""))   
		{ document.getElementById(element_id).innerHTML = xmlHttp.responseText;  delete xmlHttp;}  
		else if(preloader!="") { document.getElementById(element_id).innerHTML = preloader; }
	}
	//alert(url);
	xmlHttp.open("GET",url,true);   xmlHttp.send(null);  
}

			// internal AJAX function
			function GetXmlHttpObject()
			{
			var xmlHttp=null;
			try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
			catch (e)  {  // Internet Explorer
			try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }
			return xmlHttp;
			}

/////////////////////////////////
// replaces characters
/////////////////////////////////
function ReplaceChars(entry,out,add) {
temp = "" + entry;

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
return(temp);
}

/////////////////////////////////
// replaces those characters that can't be passed in the url without parsing
/////////////////////////////////
function SafeInput(entry) {
	// encoding + sign
	entry = ReplaceChars(entry,"+","%2B");
	// encoding & sign
	entry = ReplaceChars(entry,"&","%26");
	// encoding = sign
	entry = ReplaceChars(entry,"=","%3d");
	// encoding ' sign
	entry = ReplaceChars(entry,"'","%27");
	// encoding " sign
	entry = ReplaceChars(entry,'"',"%27");

	
	return(entry);
}


function SafeOutput(entry) {
	// decoding &
	entry = ReplaceChars(entry,"&amp;","&");
	// decoding & sign
	entry = ReplaceChars(entry,"%26","&");
	// decoding = sign
	entry = ReplaceChars(entry,"%3d","=");
	// decoding +
	entry = ReplaceChars(entry,"%2B","+"); 
	// decoding ' sign
	entry = ReplaceChars(entry,"%27","'"); 
	// decoding " sign
	entry = ReplaceChars(entry,"%22",'"'); 

	return(entry);
}

///////////////////////////
// hides object
///////////////////////////
function Hide(id){ 
	
	if ((debug == true) && (document.getElementById(id) == undefined)) {
		alert('id');
	} 
	document.getElementById(id).style.display = "none"; 
}

//////////////////////////
// unhides object as a block
//////////////////////////
function ShowBlock(id) { 

	if ((debug == true) && (document.getElementById(id) == undefined)) {
		alert(id);
	} 
	document.getElementById(id).style.display = "block"; 
}

///////////////////////////
// unhides object as inline
///////////////////////////
function ShowInline(id)
{ document.getElementById(id).style.display = "inline"; }

///////////////////////////
// switches between "block" and "none" values for display property
///////////////////////////
function ToogleBlock(id) {
	var style2 = document.getElementById(id).style;
	if (style2.display == "none") { style2.display = "block"; }
	else { style2.display = "none"; }
}
////////////////////////////////////////////////
// same function tailored for hiding table rows
////////////////////////////////////////////////
function ToogleRow(id) {
	var style2 = document.getElementById(id).style;
	if (style2.display == "none") {style2.visibility = "visible"; style2.display="";}
	else {  style2.display = "none"; }
}
/////////////////////////////
// switches between "inline" and "none" values for display property 
/////////////////////////////
function ToogleInline(id)
{
	var style2 = document.getElementById(id).style;
	if (style2.display == "none") { style2.display = "inline"; }
	else { style2.display = "none"; }
}
/////////////////////////////////////////////
// returns droplist option id
/////////////////////////////////////////////
function DroplistId(o_id) {
	return(document.getElementById(o_id).options[document.getElementById(o_id).selectedIndex].value);
}
////////////////////////////////////
// gets element value
////////////////////////////////////
function Value(id) {
	if (document.getElementById(id)) {
		return(document.getElementById(id).value);
	} else {
		eval("No id for Value(): "+id);
	}
		
}
function ValueSet(id,value_new) {
	if (document.getElementById(id) == undefined) {
		eval("no ValueSet id: "+id);
	} else {
		document.getElementById(id).value = value_new;
	}
}

function ValueAdjust(id,change) {
	document.getElementById(id).value = eval(document.getElementById(id).value) + eval(change);
}


function ValueUse(id,id_source) {
	document.getElementById(id).value = document.getElementById(id_source).value;
}




function ValueSafe(id) {
	return(SafeInput(document.getElementById(id).value));
}

////////////////////////////////////
// gets element innerHTML
////////////////////////////////////
function Content(id) {
  if (document.getElementById(id)) {
	  return(document.getElementById(id).innerHTML);
  } else {
    eval('inner html:'+id);
  }
}
/////////////////////////////////////
// changes inner HTML
/////////////////////////////////////
function ContentSet(id,content_new) {
	if (document.getElementById(id) == undefined) {
		eval("Error - no id for ContentSet(): "+id);
	} else {
		document.getElementById(id).innerHTML = content_new;
	}
}

///////////////////////////////////////////////////////////
// converts HTML content and updates it by 'change' value
///////////////////////////////////////////////////////////
function ContentCrease (id,change) {
	document.getElementById(id).innerHTML = parseInt(document.getElementById(id).innerHTML)+parseInt(change);
}

/////////////////////////////
// opens up new window
////////////////////////////
function NewWin(id,x,y) {
	if((x*1 == NaN) || (x == "")) x = 800;
	if((y*1 == NaN) || (y == ""))  y = 400;
	window.open("_popup.php?id="+id, "Langas", "resizable=yes,scrollbars=yes,status=no,menubar=yes,titlebar,height="+y+",width="+x+"");
}

/////////////////////////////
// redirects to specified address
/////////////////////////////
function GoTo(loc) { window.location.href = loc; }

////////////////////////////
// confirms action
////////////////////////////
function ConfirmAction(actionDescription,url)
	{  if(window.confirm("Are you sure you want "+actionDescription)){GoTo(""+url+"");}    }
	
//////////////////////////////////////////////////////////////////////////////////
// on confirm executes another ajax action and outputs (if is set) success message
//////////////////////////////////////////////////////////////////////////////////
function ConfirmAjax(text,action,param,success_message)
{  
	conf = confirm(text); 
	if(conf == true) { eval(action+"('"+param+"')"); }
	if (typeof success_message != 'undefined')
	{ 
		document.getElementById('messages').innerHTML = 
			"<div class='success'>"+success_message+"</div>"; 
	}  
}

////////////////////////////
// gets user input via prompt
////////////////////////////
function EnterText(promptTitle,confirmText,url,defaultText)
{
	var answer = prompt (promptTitle,defaultText)
	if (answer != null) {ConfirmAction(confirmText+"\n\n "+answer,url+answer);}
}

/////////////////////////////////////////////
// checks whether email address is properly formated
//////////////////////////////////////////////
function CheckEmail(email)
{
	var testresults
	var str=email
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
	testresults=true
	else{
	testresults=false
	}
	return (testresults)
}



////////////////// for items
function FMW_menu_update(item_id,file_name)
{
	// preparing vars
	var name = SafeInput(document.getElementById('name_'+item_id).value);
	var url = SafeInput(document.getElementById('url_'+item_id).value);
	var preloader = '<img src="https://www.blogdistributor.com/img/loading-small.gif" height="16">';  
	
	// preparing query
	var query = file_name+'?&update='+item_id+'&name='+name+'&url='+url;
	//alert(query);


	// restoring input fields to normal style
	document.getElementById("name_"+item_id).style.border = "1px solid #7B9EBD";
	document.getElementById("name_"+item_id).style.padding = "1px";
	document.getElementById("url_"+item_id).style.border = "1px solid #7B9EBD";
	document.getElementById("url_"+item_id).style.padding = "1px";
	
	// passing via AJAX
	DataTrade(query,'status_'+item_id,preloader);
	
	// different AJAX usage depending item level
	if (document.getElementById("url_"+item_id).style.display == "none") {
		DataTrade(query,'','');
	} else { 
		DataTrade(query,'status_'+item_id,preloader);
	}
}

/////////////////////////////////////////////////////////
// calls AJAX for search by email 
/////////////////////////////////////////////////////////
function FMW_Search(what,input) {
	ShowBlock(what+'_results');
	if (Content(what+'_results') == "") { ContentSet(what+'_results','<center>loading...</center>'); } 
	DataTrade("+search.php?what="+what+"&input="+SafeInput(input),what+"_results","<center>loading...");
}

////////////////////////////////////////////////////
// get's ticket content into span under header  ||| redo checking for wysiwyg and what tailoring
////////////////////////////////////////////////////  
function FMW_actions(what,wysiwyg,params) {
if ( document.getElementById('actions_'+what).style.display == "none") { // if ticket is hidden
	
	if (Content('actions_'+what) == "") { // if ticket data hasn't been loaded yet
	
		DataTrade('+actions.php?action='+what,'actions_'+what,'<center>...loading...');
		if (wysiwyg == true) {
			WaitFor('html','wysiwyghtml',"generate_wysiwyg(|html|); ");
		}
	}
	ShowBlock('actions_'+what);
	
	} else { // if ticket is visible
		Hide('actions_'+what);
	}
}


/////////////////////////////////////////////////////////////////////
// waits for the specified element to be available and then executes specified action
///////////////////////////////////////////////////////////////////////////////////////
function WaitFor(what,limit,action) {
	// if the object, that is created by executing the action that we are waiting for exists..
	if (document.getElementById(limit)) { return; }

	if (document.getElementById(what)){
		action = ReplaceChars(action,"|","'");
		eval(action);
	} else {
		setTimeout("WaitFor('"+what+"','"+limit+"','"+action+"')","200");
	}
}


/////////////////////////////////////////////////////////////////////////
// main function, gets HTML from php script using predifined variables
/////////////////////////////////////////////////////////////////////////
function ajax_table_refresh(arguments)
{  
	var target_div = "results";
	TradeData(file_name+"&"+arguments,target_div,preloaderBig);
	
	//document.getElementById("messages").innerHTML = "";
}

/////////////////////////////////////////////////////////////////////////
// only if the page is realoaded, messages div will not be cleaned
/////////////////////////////////////////////////////////////////////////
function ajax_table_initialize()
{  
	var target_div = "results";
	TradeData(file_name,target_div,preloaderBig);  
}

////////////////////////////////////////// LEGACY

function ShowObject(id) {
	ShowBlock(id);
}


////////////////////////////////////////////////////////////////////////////////////////////////
// used for ajax table inlays
////////////////////////////////////////////////////////////////////////////////////////////////
function FMW_inlay(row_id,gateway,wysiwyg,wysiwyg_width) {
																															 
	ToogleRow('view_'+row_id); // this function can be used for both expanding and collapsing the row
	
	if (document.getElementById('view_'+row_id).style.display != "none") { // if row has been expanded..
		DataTrade(gateway+row_id,'edit_'+row_id,'...loading...'); // ...getting data
		if(wysiwyg != undefined) { // and if wysiyg is enabled
			if (wysiwyg_width != undefined) { // .. and if it's paramaters are set
				WaitFor(wysiwyg+row_id,"wysiwyg"+wysiwyg+row_id,"generate_wysiwyg(|"+wysiwyg+row_id+"|,|"+wysiwyg_width+"|);"); 
			}  else {
				WaitFor(wysiwyg+row_id,"wysiwyg"+wysiwyg+row_id,"generate_wysiwyg(|"+wysiwyg+row_id+"|,||);"); // generating it..
			}      
		}
	} else { // if row is collapsed
		ContentSet('edit_'+row_id,""); // unsetting content 
	}
}


/////////////////////////////////////////////////////////////////////
// waits for the specified element to be available and then executes specified action
///////////////////////////////////////////////////////////////////////////////////////
function WaitFor(what,limit,action) {
	// if the object, that is created by executing the action that we are waiting for already exists..
	if (limit != undefined)  {
		if (document.getElementById(limit)) { return; }
	}

	if (document.getElementById(what)){
		action = ReplaceChars(action,"|","'");
		eval(action);
	} else {
		setTimeout("WaitFor('"+what+"','"+limit+"','"+action+"')","200");
	}
}



function urlencode( str ) {
		// http://kevin.vanzonneveld.net
		// +   original by: Philip Peterson
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +      input by: AJ
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
		// *     example 1: urlencode('Kevin van Zonneveld!');
		// *     returns 1: 'Kevin+van+Zonneveld%21'
		// *     example 2: urlencode('http://kevin.vanzonneveld.net/');
		// *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
		// *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
		// *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
																		 
		var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
		var ret = str.toString();
		
		var replacer = function(search, replace, str) {
				var tmp_arr = [];
				tmp_arr = str.split(search);
				return tmp_arr.join(replace);
		};
		
		// The histogram is identical to the one in urldecode.
		histogram['!']   = '%21';
		histogram['%20'] = '+';
		
		// Begin with encodeURIComponent, which most resembles PHP's encoding functions
		ret = encodeURIComponent(ret);
		
		for (search in histogram) {
				replace = histogram[search];
				ret = replacer(search, replace, ret) // Custom replace. No regexing
		}
		
		// Uppercase for full PHP compatibility
		return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
				return "%"+m2.toUpperCase();
		});
		
		return ret;
}

function urldecode( str ) {
		// http://kevin.vanzonneveld.net
		// +   original by: Philip Peterson
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// +      input by: AJ
		// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
		// %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
		// *     example 1: urldecode('Kevin+van+Zonneveld%21');
		// *     returns 1: 'Kevin van Zonneveld!'
		// *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
		// *     returns 2: 'http://kevin.vanzonneveld.net/'
		// *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
		// *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
		
		var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
		var ret = str.toString();
		
		var replacer = function(search, replace, str) {
				var tmp_arr = [];
				tmp_arr = str.split(search);
				return tmp_arr.join(replace);
		};
		
		// The histogram is identical to the one in urlencode.
		histogram['!']   = '%21';
		histogram['%20'] = '+';
		
		for (replace in histogram) {
				search = histogram[replace]; // Switch order when decoding
				ret = replacer(search, replace, ret) // Custom replace. No regexing   
		}
		
		// End with decodeURIComponent, which most resembles PHP's encoding functions
		ret = decodeURIComponent(ret);
 
		return ret;
}



////////////////////////////////////////////////////////////////
// counts words in the text block. works well with line breaks
////////////////////////////////////////////////////////////////
function CountWords(input) {
	
	var fullStr = input + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	if (fullStr.length <2) {
		word_count = 0;
	}
	return(word_count);
}

////////////////////////////////////////////////////////////////////////////////
// scroll document by a number of pixels from it's current position
// change: negative numbers will scroll up/left, positive - right and down
// direction: 'x' or 'y', 'x' is used by default 
////////////////////////////////////////////////////////////////////////////////
function WindowScroll(change,direction) {
	var vscroll = (document.all ? document.scrollTop : window.pageYOffset);
	var hscroll = (document.all ? document.scrollLeft : window.pageXOffset);
	if (direction == undefined) {
		var direction = 'x';
	}
	if (direction == 'x') {
		vscroll = eval(vscroll + change);
	} else {
		hscroll = eval(hscroll + change);
	}
	
	window.scroll(hscroll,vscroll);
}

///- DATE& TIME

function dt_now(param) {
	var format = "dt";  if (param != undefined) { format = param;  }
	var dt = new Date(); 
	var o = "";
	
	var year = dt.getFullYear();
	var month = dt.getMonth()+1;
	if (month < 10) {
		month = "0"+month;
	}
	var day = dt.getDay()+1;
	if (day < 10) {
		day = "0"+day;
	}
	
	if (format == "d") {
		o = year+"-"+month+"-"+day;
	}
	
	return(o);
		
}

function dt_es(dt) {
	var o = "";
	var year = dt.substring(6,10);
	var month = dt.substring(0,2);
	var day = dt.substring(3,5);
	
	o = year+"-"+month+"-"+day;
	
	return(o);
}


//////////////////////////////////////////////////////////
// delays action untill ajax requests are done running
//////////////////////////////////////////////////////////
function ActionDelayed(action,button_id) {
	if (ajax_requests.length == 0) {
		eval(action);
		//ValueSet(button_id,"Submit");
		if (button_id != "none") {
			document.getElementById(button_id).disabled = false;
		}
	} else {
		if (button_id != "none") {
			//ValueSet(button_id,"...wait...");
			document.getElementById(button_id).disabled = true;
		}
		setTimeout("ActionDelayed('"+action+"','"+button_id+"')",500);
	}
}


//////////////////////////////////////////////
// since IE6 does not support a.indexOf()
//////////////////////////////////////////////
function array_index(array_name,value) {
	var za = 0;
	for (x in array_name)
	{
		if (array_name[x] == value) {
			return za;
		}
		za++;
	}
	return(-1);
}

//////////////////////////////////////////////////////////////////////////////
// selects droplist option with specified value
/////////////////////////////////////////////////////////////////////////////
function DroplistSelect(id,value) {
  var options = document.getElementById(id).options;
  var row_id = "";
  for (x in options) { // foreach 
    if (options[x].value == value) {
      row_id = x;
    }
  }
  
  if (row_id != "") {
    document.getElementById(id).selectedIndex = row_id;
  }
}


	

