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 getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start = c_start + c_name.length + 1; 
			c_end   = document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}


function showsubmenu(hrf) {
	if(hrf.className == 'act') {
		hrf.id = 'act';
	}
	hrf.timerID = null;
	hrf.stopclock = function() {
		if(this.timerID) {
			clearInterval(this.timerID);
			this.timerID = null 
		}
	}
	hrf.className = 'hov';
	var ex = true
	var nod = hrf.parentNode.firstChild;
	var cnt = 0;
	do
	{
		if(!nod) ex=false
		else if (nod.nodeName == 'DIV') {
			var submenu = nod;
			ex=false
		} else {
			nod = nod.nextSibling;
		}
		cnt ++ ; if(cnt > 5) ex=false
	}
	while (ex);
	if(submenu) {
		submenu.style.display = 'block';
		submenu.onmousemove = function() {
			hrf.className = 'hov';
		}
		submenu.onmouseover = function() {
			hrf.stopclock()
		}
		hrf.onmouseout = submenu.onmouseout = function() {
			hrf.stopclock()
			hrf.timerID = setInterval( function() {
					if(hrf.timerID) {
						if(hrf.id == 'act') hrf.className = 'act';
						else hrf.className = '';
						submenu.style.display = 'none';
						hrf.stopclock()
					}
				}, 300);
		}
	}
}


function Chg(ImNm, Vsbl){
	if (document.images) {document.images[ImNm].src = "img/" + ImNm + (Vsbl ? "_" : "") + ".gif";}
}
function report_js_error(msg, url, linenumber) {
  stuff=" URL: "+url+" - "+msg+"; line: "+linenumber;
  tmp = new Image();
  tmp.src = "/write_error.php?error="+stuff;
  return true;
}
function getCookie(Name) {   
	var search = Name + "="   
	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search)       
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1) end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))     
		}
	}
}
function setCookie(name, value) { 
	var expire = "0, 01-01-2020 00:00:00 GMT"
	document.cookie = name + "=" + escape(value) + "; expires=" + expire + "; path=/";
}
function Win2Escape(AStr){
	var Result='';
	for(var i=0;i<AStr.length;i++)
		if(AStr.charAt(i)>='À' && AStr.charAt(i)<='ÿ')	Result+=Letters[AStr.charCodeAt(i)-0x0410];
		else if(AStr.charAt(i)=='¨') Result+=Letters[64];
		else if(AStr.charAt(i)=='¸') Result+=Letters[65];
		else if(AStr.charAt(i)=='=') Result+='%3D';
		else if(AStr.charAt(i)=='&') Result+='%26';
		else Result+=AStr.charAt(i);
	return Result;
}
// -------------------------------------------------------------
function URLencode(sStr) {
	return (Win2Escape(sStr)).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}
// -------------------------------------------------------------
function startFlashing(block_id) {
	layer = document.getElementById(block_id);
	if (flashing==1) {
		layer.style.borderWidth='1px';
		layer.style.borderColor='#000000';
		if (layer.style.borderStyle.indexOf('none') == -1) {
			//alert(layer.style.borderStyle);
			layer.style.borderStyle='none';
		} else {
			layer.style.borderStyle='dotted';
		}
		window.setTimeout("startFlashing('"+block_id+"');", 100);
	} else {
		layer.style.borderStyle='none';
		layer.style.borderWidth='0px';
	}
}
// -------------------------------------------------------------
function AJAXRequest(url_param, ready_function, first_param, proc_function) {
	proc_function = proc_function || '';
	first_param = first_param || '';
	var xmlhttp=false;
	//alert(1)
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {xmlhttp = new XMLHttpRequest();}
	xmlhttp.open("GET", url_param, true);
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=windows-1251");
	xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	xmlhttp.setRequestHeader("Pragma", "no-cache");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {eval(ready_function+'(\''+first_param+'\', xmlhttp.responseText);');}
	}
	if (proc_function) {
		eval(proc_function+'();');
	}
	xmlhttp.send(null);
	return false;
}
// -------------------------------------------------------------
function create_http_handle(TYPE){
	var http_handle = false;
	if (window.XMLHttpRequest){
		http_handle = new XMLHttpRequest();
		if (http_handle.overrideMimeType){
			if (TYPE == "XML"){
				http_handle.overrideMimeType('text/xml');
			} else {
				http_handle.overrideMimeType('text/html');
			}
		}
	} else if (window.ActiveXObject){
		try {
			http_handle = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_handle = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_handle){
		alert("We are sorry but you are using an outdated browser.  To view this site you must update your browser.");
		return false;
	} else {
		return http_handle;
	}
}
// -------------------------------------------------------------
function AJAXPostRequest(url, params, ready_function, first_param, proc_function) {
	proc_function = proc_function || '';
	first_param = first_param || '';
	xmlhttp = create_http_handle();
	var now = "&upid=" + new Date().getTime();
	url += (url.indexOf("?")+1) ? "&" : "?";
	url += now;
	//params += now;
	//xmlhttp.open("POST",url+params,true);
	xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-URLencoded");
	xmlhttp.setRequestHeader("Content-Type", "text/html; charset=windows-1251");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {eval(ready_function+'(\''+first_param+'\', xmlhttp.responseText);');}
	}
	if (proc_function) { eval(proc_function+'(\''+first_param+'\');');	}
	xmlhttp.send(params);
	return false;
}
// -------------------------------------------------------------
function returnURLParams(formId){
	var params='';
	var tmp = document.getElementById(formId);
	if(tmp) {
		if(tmp.elements.length>0)  for(i=0; i<tmp.elements.length; i++) {
			if(tmp.elements[i].name == 'param3') {
				//alert(document.getElementById(formId).elements[i].value);
				//alert(tmp.elements[i].value)
			}
			switch(tmp.elements[i].type) {
				case "radio": case "checkbox": 
					if(tmp.elements[i].checked) {
						if(tmp.elements[i].value=='') params += "&" + tmp.elements[i].name + "=1";
						else params += "&" + tmp.elements[i].name + "=" + encodeURIComponent(tmp.elements[i].value);
					}
				break;
				case "select-multiple": 
					if(tmp.elements[i].options.length>0) for(y=0; y<tmp.elements[i].options.length; y++) {
						if(tmp.elements[i].options[y].selected) {
							params += "&" + tmp.elements[i].name + encodeURIComponent("[") + y + encodeURIComponent("]") + "=" + encodeURIComponent(tmp.elements[i].options[y].value);
						}
					}
				break;
				default: params += "&" + tmp.elements[i].name + "=" + encodeURIComponent(tmp.elements[i].value);
			}
		}
	}
	return params;
}
// -------------------------------------------------------------
function getBlockDataForm(block_id, form) {
	params='';
	for(i=0;i<form.elements.length;i++) {
		if (form.elements[i].type!='radio' || form.elements[i].checked) {
			params+='&'+form.elements[i].name+'='+URLencode(form.elements[i].value);
		}
	}
	//alert(params);
	url=form.action;
	layer = document.getElementById(block_id);
	old_data=layer.innerHTML;
	flashing=1;
	startFlashing(block_id);
	// layer.innerHTML='<b>Loading please wait...</b>';
	var xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			flashing=0;
			layer.innerHTML=xmlhttp.responseText;
			layer.style.borderStyle='none';
		}
	}
	if (form.method=='post') {
		xmlhttp.open("POST", url, true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(params+'&filterblock='+block_id);
	} else {
		xmlhttp.open("GET", url+params+'&filterblock='+block_id,true);
		xmlhttp.send(null);
	}
	return false;
}
// ------------------------------------------------------------
function getBlockData(block_id, url) {
	layer = document.getElementById(block_id);
	old_data=layer.innerHTML;
	flashing=1;
	startFlashing(block_id);
	var xmlhttp=false;
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", url+'&filterblock='+block_id,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			flashing=0;
			layer.style.borderStyle='none';
			layer.innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
	return false;
}
// ------------------------------------------------------------
var resizing = true;
function resizeHeight() {
	if(resizing) {
		tmp = document.getElementById('ridgepole');
		tmp2 = document.getElementById('ridgepoler');
		bbd = document.getElementById('meter');
		bm = document.getElementById('bottommeter');
		tm = document.getElementById('topmeter');
		if(tmp && bbd && bm && tm) {
			var startH = Number(bbd.clientHeight - bm.clientHeight - tm.clientHeight);
			if(tmp2 && getBrowserType()=='ie') {
				var nod = tmp2.parentNode;
				if(nod && nod.nodeName=='TD') {
					var nod = nod.parentNode;
					if(nod && nod.nodeName=='TR') {
						var he = 0;
						ex = true
						nodUNDER = nod
						do
						{
							var nodUNDER = nodUNDER.nextSibling;
							if(!nodUNDER) ex=false
							else he+=nodUNDER.clientHeight;
						}
						while (ex);
						ex = true
						nodABOVE = nod
						do
						{
							var nodABOVE = nodABOVE.previousSibling;
							if(!nodABOVE) ex=false
							else he+=nodABOVE.clientHeight;
						}
						while (ex);
					}
					if(he>0) {
						bbd.firstChild.style.height = "1%";
						tmp2.style.height = "1%";
						tmp.style.height = "1%";
						
						tmp2.style.height = Number(startH - he)  + "px";
						bbd.firstChild.style.height = "100%";
					}
				}
			} else {
				tmp.style.height = (startH-1) + "px";
			}
		}
	}
	resizing = false;
}
function getBrowserType()	 {
	var myUserAgent;
	var myMajor;
	myUserAgent = navigator.userAgent.toLowerCase();
	myMajor = parseInt(navigator.appVersion);
	re = /safari/i;
	if(re.exec(myUserAgent))								{	return "safari";	 }
	if( (myUserAgent.indexOf('mozilla') != -1) && (myUserAgent.indexOf('spoofer') == -1) && (myUserAgent.indexOf('compatible') == -1) && (myUserAgent.indexOf('opera') == -1) && (myUserAgent.indexOf('webtv') == -1)    )	{	return "nav";	}
	if (myUserAgent.indexOf("msie") != -1)				{	return "ie";		}
																		return "other";
}
// ------------------------------------------------------------
function doSystemMessages(type, message, param) {
	var url="?ajt=messages&doit="+type+"&param1="+message+"&param2="+param; 
	AJAXRequest(url, 'resultFP', type);
} 
function cancelSystemMessage() {
	var tmp1 = document.getElementById('system_message');
	var tmp2 = document.getElementById('liover');
	if(tmp1 && tmp2) {
		//new Effect.Fade('system_message', { duration: 0.1}); 
		//new Effect.Fade('liover', { duration: 0.4}); 
		new Effect.Fade('system_message', { duration: 0.0}); 
		new Effect.Fade('liover', { duration: 0.0}); 
	}
	
	showSelectBoxes(); 
	showFlash(); 
}
function resultFP(param, result) {
	var tmp1 = document.getElementById('system_message');
	var tmp2 = document.getElementById('liover');
	if(tmp1 && tmp2) {
		hideSelectBoxes();
		hideFlash();
		tmp1.innerHTML = result;
		// redirect here
		var tmpRH = document.getElementById('refreshurl');
		if(tmpRH)  { 
			cancelSystemMessage();
			re = /\.html(.*)/
			window.location.href= tmpRH.value + (re.exec(tmpRH.value)[1] == '' ? "?" : "&") + (new Date()).getTime();
			return false;
		}
		// System Message
		var tmpR = document.getElementById('returntrue');
		if(tmpR)  { 
			doSystemMessages('systeminformation', tmpR.value);	
			return false;
		}
		var tmpA = document.getElementById('scroll_to');
		if (tmpA) {
			window.location.hash = tmpA.value;
		}
		// just show result
		var arrayPageSize = getPageSize();
		tmp2.style.width = arrayPageSize[0]+"px";
		tmp2.style.height= arrayPageSize[1]+"px";
		tmp2.onclick=function() {
			var tmp1 = document.getElementById('system_message');
			var tmp2 = document.getElementById('liover');
			if(tmp1 && tmp2) {
				//new Effect.Fade('system_message', { duration: 0.1}); 
				//new Effect.Fade('liover', { duration: 0.4}); 
				new Effect.Fade('system_message', { duration: 0.0}); 
				new Effect.Fade('liover', { duration: 0.0}); 
			}
			
			showSelectBoxes(); 
			showFlash(); 
		};
		
		tmp1.style.display = 'block'
		tss = Number(sysYPosition) - tmp1.clientHeight - 20;
		if(tss < 160) tss = 160;
		tmp1.style.top = tss + 'px'
		tmp1.style.display = 'none'

		//new Effect.Appear('liover', {duration: 0.1, from: 0.0, to: 0.8});
		//new Effect.Appear('system_message', { duration: 0.2, from: 0.0, to: 1.0});
		new Effect.Appear('liover', {duration: 0.0, from: 0.0, to: 0.5});
		new Effect.Appear('system_message', { duration: 0.0, from: 0.0, to: 1.0});
	}
}


function keyPressHandler(e) {
  var kC  = (window.event) ? event.keyCode : e.keyCode;
  var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
  if(kC==Esc) {
	  cancelSystemMessage();
	  var tmp = document.getElementById("d_cal_menu");
	  if(tmp) { tmp.style.display = 'none'; selectedmenuarrow = ''; }
  }
}
var sysYPosition = 0;
function mouseMove(e) {
	e = e || window.event;
	if(e.pageY) {
		sysYPosition = e.pageY
		return 0;
	}
}
if(document.layers)	document.captureEvents(Event.KEYPRESS);
document.onkeypress = keyPressHandler;

if(document.layers)	document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mouseMove;


// ------------------------------------------------------------
function showVideo(id) {
	doSystemMessages('systemmodule', 'name="videos" view_mode="view_videos" ajax="on" id="'+id+'"');
}
function sendPackageData(formId) {
	var tmp = document.getElementById(formId);
	var params = returnURLParams(formId);
	if(params) AJAXPostRequest(tmp.action, params, 'resultFP', 'systemmodule');
	cancelSystemMessage(); 
}
function ckeckboxs(name) {
	var tmp = document.getElementsByName(name);
	if(tmp) if(tmp.length>0) for(i=0; i<tmp.length; i++) if(tmp[i].type=="checkbox") if(tmp[i].checked) tmp[i].checked = false; else tmp[i].checked = true;
}

function leaveBid(type) {
	var type = type || "";
    var wdth=510;
    var hgth=520;
    var LeftPosition=(screen.width)?(screen.width-wdth)/2:100;
    var TopPosition=(screen.height)?(screen.height-hgth)/2:100;
    var settings='width='+ wdth + ',height='+ hgth + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
    window.open("/popup.html?ptype="+type, "ord", settings);
    return false;
}
