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;
	/*@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();}
	/*var now = "&upid=" + new Date().getTime();
	url_param = encodeURIComponent(url_param);
	url_param += (url_param.indexOf("?")+1) ? "&" : "?" + encodeURIComponent(now);
	url_param = decodeURIComponent(url_param);
	//alert(encodeURIComponent(url_param))*/
	/*re = /\.php/i
	if(!re.test(url_param)) url_param = "index.php" + url_param;*/
	xmlhttp.open("GET", url_param, true);
	//xmlhttp.setRequestHeader("Last-Modified", gmdate("D, d M Y H:i:s")+ " GMT");
	xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	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-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)
			}
			if(tmp.elements[i].style.display!='none' && tmp.elements[i].style.visibility!='hidden')
				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);
	//  return false;
	//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.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";
			}
		}
		var imgresizer = document.getElementById('imgresizer');
		if(imgresizer) {
			var tbody = imgresizer;
			while (tbody.nodeName != "TBODY") tbody = tbody.parentNode;
			var imgresizerheight = parseInt(document.getElementById('ridgepole').style.height) - tbody.offsetHeight - 43;
			if(imgresizerheight>0) imgresizer.style.height = imgresizerheight + "px";
		}
		var tipstd = document.getElementById('tipstd2');
		if(tipstd) {
			if(imgresizerheight>0) tipstd.style.height = parseInt(document.getElementById('ridgepole').style.height) - 45 + "px";
		}
	}
	PageSize = getPageSize();
	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="/index.php?ajt=messages&doit="+type+"&param1="+message+"&param2="+param; 
	AJAXRequest(url, 'resultFP', type);
} 

function doVideoBlock(id) {
	var url="/index.php?ajt=messages&doit=videos&param1="+id+"&param2="; 
	AJAXRequest(url, 'resultVideo', 'videos');
}

function resultVideo(param, result) {
	var tmp1 = document.getElementById('system_message');
	var tmp2 = document.getElementById('liover');
	if(tmp1 && tmp2) {
		tmp1.innerHTML = result;
		var arrayPageSize = getPageSize();
		tmp2.style.width = arrayPageSize[0]+"px";
		tmp2.style.height= arrayPageSize[1]+"px";
		tmp2.onclick=cancelSystemMessage;		
		hideMenuarrow()
		hideSelectBoxes();
		hideFlash();

		tmp1.style.display = 'block'
		tmp1.style.top = 160 + 'px'
		tmp1.style.left = Number(Math.round(arrayPageSize[0]/2)-Math.round(tmp1.clientWidth/2)) + 'px';
		/*for(i=0; i<document.getElementsByTagName('TD').length; i++)
			if(document.getElementsByTagName('TD')[i].className=="systemheader") var tl = document.getElementsByTagName('TD')[i];
		if(tl) {
			tl.style.cursor = 'move';
			tl.onclick = new Function("return false");
			tl.onmousedown = new Function("e", "tmpFunc = document.onmousemove; document.onmousemove=mouseMove; sdr = true; e = e || window.event; if(e) { if(navigator.appName.indexOf('Microsoft') != -1) { sysX = e.x; sysY = e.y; } else { sysX = e.pageX; sysY = e.pageY;} DRAG_lastX = sysX; DRAG_lastY = sysY;} var tmp = document.getElementById('system_message'); if (tmp) { prevX = parseInt(tmp.style.marginLeft || '0'); prevY = parseInt(tmp.style.marginTop || '0'); } ");
		}*/
		tmp1.style.display = 'none'
		new Effect.Appear('liover', {duration: 0.0, from: 0.0, to: 0.8});
		new Effect.Appear('system_message', { duration: 0.0, from: 0.0, to: 1});

		{
			// params
			var p_width = 480;
			var p = document.getElementById('p1');
			if(p) p_width = p.value;

			var p_height = 360;
			var p = document.getElementById('p2');
			if(p) p_height = p.value;

			var p_file = '/cms/videos/FC_Home_Video.flv';
			var p = document.getElementById('p3');
			if(p) p_file = p.value;

			var p_autostart = 'true';
			var p = document.getElementById('p4');
			if(p) p_autostart = p.value;
		};
			
		//alert(p_width +" | "+ p_height +" | "+ p_file +" | "+ p_autostart )

		var s1 = new SWFObject("/templates/videos/mediaplayer.swf","playerID", p_width, p_height,"8");
		s1.addVariable("width",p_width);
		s1.addVariable("height",p_height);
		s1.addParam("allowfullscreen","true");
		s1.addParam("allowscriptaccess","always");
		s1.addParam("quality","high");
		s1.addParam("scaleMode","showAll");
		s1.addParam("allowNetworking","all");
		s1.addParam("wmode","transparent");
		s1.addVariable("file", p_file);
		s1.addVariable("id","playerID");
		s1.addVariable("enablejs","true");
		s1.addVariable("javascriptid","playerID");
		s1.addVariable("searchbar","false");
		s1.addVariable("shownavigation","false");
		s1.addVariable("showdigits","false");
		s1.addVariable("usefullscreen","false");
		s1.addVariable("autostart", p_autostart);
		s1.id = 'playerID';
		s1.write("placeholder");

		var tmpV = document.getElementById('playerID');
		if(tmpV) { tmpV.style.visibility = 'visible';	}

		var tmp = document.getElementById("volumer"); 
		if (tmp) {
			tmp.style.marginLeft = Number(16+Math.floor(44*setVolumeIn/100)) + "px";
			tmp.onmousedown=mouseDown2;
			tmpFNC1 = document.onmouseup;
			tmpFNC2 = document.onmousemove;
			document.onmouseup = mouseUp2;
			document.onmousemove=mouseMove2;
		}
	}
}

var tmpFNC1 = null;
var tmpFNC2 = null;
function mouseDown2(e) {
	this.className='volumer volsel'; 
	if(document.all) DRAG_lastX=window.event.x; 
	else DRAG_lastX=e.pageX; 
	DRAG_dragging=true; 
	return false;
}
function mouseUp2(e) {
	if(DRAG_dragging) { 
		sendEvent('volume',setVolumeIn); 
		DRAG_dragging=false; 
		var tmp=document.getElementById('volumer'); 
		if (tmp) {
			tmp.className='volumer'; 
			tmp.blur(); 
			return false;
		}
	}; 
}
function mouseMove2(e) {
	if(DRAG_dragging) { 
		var tmp = document.getElementById('volumer'); 
		if (tmp) { 
			if(document.all) DRAG_X=window.event.x; 
			else DRAG_X=e.pageX; 
			tp = Number(16+Math.floor(44*currentVolume/100)+(DRAG_X-DRAG_lastX)); 
			if(tp<16) tp = 16; 
			if(tp>61) tp = 61; 
			setVolumeIn=Math.floor((tp-16)/44*100); 
			if(setVolumeIn<0) setVolumeIn = 0; 
			if(setVolumeIn>100) setVolumeIn = 100; 
			tmp.style.marginLeft = tp + 'px'; 
			//report_js_error(tmp.style.marginLeft);
			return false;
		} 
	}
}


var timerID = null
var timerRunning = false
function stopclock(){
   if(timerRunning) clearInterval(timerID)
   timerRunning = false
}
function reloadWin() {
	if(!timerRunning) window.location.reload()
	timerRunning = true
}
function cancelSystemMessage() {
	stopclock();
	var tmp = document.getElementById('RESCHEDULEURL');
	if(tmp) {
		new Effect.Fade('system_message', { duration: 0.0}); 
		stopclock()
		timerID = setInterval("reloadWin();",100);
		//window.location.href = window.location.href+"?12312";
		//window.location.reload();
	} else {
		var tmp1 = document.getElementById('system_message');
		var tmp2 = document.getElementById('liover');
		if(tmp1 && tmp2) {
			tmp1.innerHTML = '&nbsp;';
			tmp2.innerHTML = '&nbsp;';
			//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}); 
		}
		showMenuarrow();
		showSelectBoxes(); 
		showFlash(); 
	}
	if(tmpFNC1!=null) {
		document.onmouseup = tmpFNC1;
		tmpFNC1 = null;
	}
	if(tmpFNC2!=null) {
		document.onmousemove = tmpFNC2;
		tmpFNC2 = null;
	}
}
function resultFP(param, result) {
	var tmp1 = document.getElementById('system_message');
	var tmp2 = document.getElementById('liover');
	if(tmp1 && tmp2) {
		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=cancelSystemMessage;

		hideMenuarrow()
		hideSelectBoxes();
		re = /FC_Save\.swf/i;
		if(re.exec(result)) {
			stopclock()
			timerRunning = true
			timerID = setInterval("cancelSystemMessage();",3000);
		} else {
			hideFlash();
		}
		tmp1.style.display = 'block'
		tss = Number(sysYPosition) - tmp1.clientHeight - 20;
		if(tss < 160) tss = 160;
		tmp1.style.top = tss + 'px'
		tmp1.style.left = Number(Math.round(arrayPageSize[0]/2)-Math.round(tmp1.clientWidth/2)) + 'px';
		for(i=0; i<document.getElementsByTagName('TD').length; i++)
			if(document.getElementsByTagName('TD')[i].className=="systemheader") var tl = document.getElementsByTagName('TD')[i];
		//var tl = document.getElementById('titlespotl');
		if(tl) {
			tl.style.cursor = 'move';
			tl.onclick = new Function("return false");
			tl.onmousedown = new Function("e", "tmpFunc = document.onmousemove; document.onmousemove=mouseMove; sdr = true; e = e || window.event; if(e) { if(navigator.appName.indexOf('Microsoft') != -1) { sysX = e.x; sysY = e.y; } else { sysX = e.pageX; sysY = e.pageY;} DRAG_lastX = sysX; DRAG_lastY = sysY;} var tmp = document.getElementById('system_message'); if (tmp) { prevX = parseInt(tmp.style.marginLeft || '0'); prevY = parseInt(tmp.style.marginTop || '0'); } ");
		}
		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.8});
		new Effect.Appear('system_message', { duration: 0.0, from: 0.0, to: 1});
	}
}


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 sysXPosition = 0;
var sysYPosition = 0;
// drag & drop for LightBox
var sdr = false;
var DRAG_lastX = 0;
var DRAG_lastY = 0;
var prevX = 0;
var prevY = 0;
var PageSize = new Array();
var tmpFunc = null;

function mouseMove(e) {
	e = e || window.event;
	if(e) {
		if(navigator.appName.indexOf("Microsoft") != -1) {
			sysXPosition = e.x
			sysYPosition = e.y
		} else {
			sysXPosition = e.pageX
			sysYPosition = e.pageY
		}
	}
	if(sdr) { 
		var tmp = document.getElementById('system_message');
		if (tmp) {
			tmp.style.marginLeft =  Number(Number(prevX) + Number(sysXPosition)-Number(DRAG_lastX)) + "px";
			tmp.style.marginTop =  Number(Number(prevY) + Number(sysYPosition)-Number(DRAG_lastY)) + "px";
			//tmp1.style.left = Number(Math.round(arrayPageSize[0]/2)-Math.round(tmp1.clientWidth/2)) + 'px';
			//alert(PageSize[0]);
			//alert(tmp.clientWidth)
			if((parseInt(tmp.style.left)+parseInt(tmp.style.marginLeft))<0) tmp.style.marginLeft = "-"+parseInt(tmp.style.left)+"px";
			if((parseInt(tmp.style.left)+parseInt(tmp.style.marginLeft)+parseInt(tmp.clientWidth))>PageSize[0]) tmp.style.marginLeft = Number(parseInt(PageSize[0])-parseInt(tmp.style.left)-parseInt(tmp.clientWidth))+"px";

			if((parseInt(tmp.style.top)+parseInt(tmp.style.marginTop))<0) tmp.style.marginTop = "-"+parseInt(tmp.style.top)+"px";
			if((parseInt(tmp.style.top)+parseInt(tmp.style.marginTop)+parseInt(tmp.clientHeight))>PageSize[1]) tmp.style.marginTop = Number(parseInt(PageSize[1])-parseInt(tmp.style.top)-parseInt(tmp.clientHeight))+"px";
		}
	} 
}
function mouseUp(e) {
	//alert(document.onmousemove);
	sdr = false;
	if (tmpFunc != null) document.onmousemove = tmpFunc;
	//alert(document.onmousemove);
}

if(document.layers)	document.captureEvents(Event.KEYPRESS);
document.onkeypress = keyPressHandler;

if(document.layers)	document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mouseMove;

if(document.layers) document.captureEvents(Event.MOUSEUP);
document.onmouseup =  mouseUp;


// ------------------------------------------------------------
function refreshRESCHEDULE() {
	var tmp = document.getElementById('RESCHEDULEURL');
	if(tmp) {
		//alert(1)
		window.location.reload();
	}
}
function pageLogin(ret) {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="login" tab="loginpage" ajax="on" return="'+ret+'" ');
}
function pageForgot() {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="forgot" tab="forgotpage" ajax="on" ');
}
function editPackage(id) {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="training-packages" section="add" ajax="on" id="'+id+'"');
}
function editClientPackage(id) {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="training-packages" section="edit-client-package" ajax="on" id="'+id+'"');
}
function editBlackout(id) {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="blackout" section="add" ajax="on" id="'+id+'"');
}
function sendMessageToClient(id) {
	doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="clients" section="message" ajax="on" id="'+id+'"');
}
function sendBilkMail(formId) {
	var tmp = document.getElementById(formId);
	var params = new Array();
	var k = 0;
	var ret = '';
	if(tmp) if(tmp.elements.length>0)  for(i=0; i<tmp.elements.length; i++) 
		if(tmp.elements[i].type=="checkbox" && tmp.elements[i].checked) params[k++] = encodeURIComponent(tmp.elements[i].value);
	
	if(params.length>0) for(i=0; i<params.length; i++) {
		ret += params[i];
		if((i+1)!=params.length) ret += "|";
	}
	if(ret !="") doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="clients" section="bulkmail" ajax="on" id="'+ret+'"');
	else doSystemMessages('systemerror', 'Please select clients for mail');
}
function sendPackageData(formId) {
	var tmp = document.getElementById(formId);
	var params = returnURLParams(formId);
	if (params) AJAXPostRequest(tmp.action, params, 'resultFP', 'systemmodule');
	rs = document.getElementById('RESCHEDULEURL');
	if (rs != null) document.body.removeChild(rs);
	cancelSystemMessage();
}
function editTrainerSession(id, MONTH, DAY, YEAR, time) {
	MONTH = MONTH || '';
	DAY = DAY || '';
	YEAR = YEAR || '';
	time = time || '';
	doSystemMessages('systemmodule', 'name="trainers" view_mode="dashboard" tab="calendar" section="addsession" ajax="on" id="'+id+'" startdate="'+YEAR+"-"+MONTH+"-"+DAY+'-'+time+'" mod="'+whereis+'" ');
}
function cancelClientSession(id) {
	doSystemMessages('systemmodule', 'name="clients" ajax="on" view_mode="dashboard" tab="session_delete" id="'+id+'" ');
}
function cancelClientMessage(id) {
	doSystemMessages('systemmodule', 'name="clients" ajax="on" view_mode="dashboard" tab="message_delete" id="'+id+'" ');
}
function buyPackage(id) {
	doSystemMessages('systemmodule', 'name="clients" ajax="on" view_mode="dashboard" tab="buypackage" trid="'+id+'" ');
}
function readReSuspport(id) {
	doSystemMessages('systemmodule', 'name="techsupport" ajax="on" view_mode="read" id="'+id+'" ');
}
function buyPackageFromTrainerPanel(id, clid) {
	clid = clid || '';
	doSystemMessages('systemmodule', 'name="clients" ajax="on" view_mode="dashboard" tab="buypackage" trid="'+id+'" clid="'+clid+'" ');
}
function changeCCData(){
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="ccdata" ');
}
function changeURL(){
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="fakeurl" ');
}
function confirmReschedule(id) {
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="confirmreschedule" id="'+id+'" mod="'+whereis+'" ');
}
function addDayTimeOff(ondate, subid, owner_id) {
	var subid = subid || 0;
	var owner_id = owner_id || 0;
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="daytimeoff" ondate="'+ondate+'" sub_id="'+subid +'" mod="'+whereis+'" id="'+owner_id+'" ');
}
function removeDayTimeOff(ondate, subid, owner_id) {
	var subid = subid || 0;
	var owner_id = owner_id || 0;
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="daytimeoff" mode="remove" ondate="'+ondate+'" sub_id="'+subid +'" mod="'+whereis+'" id="'+owner_id+'" ');
}
function confirmCancellation(id) {
	doSystemMessages('systemmodule', 'name="trainers" ajax="on" view_mode="dashboard" tab="confirmcancell" id="'+id+'" mod="'+whereis+'" ');
}

function readPolicy() {
	doSystemMessages('systemmodule', 'name="clients" ajax="on" view_mode="dashboard" tab="readPolicy" ');
}

function setTimeZone() {
	var d = new Date();
	var message = 'name="trainers" ajax="on" view_mode="dashboard" tab="setTimeZone" offset="'+d.getTimezoneOffset()+'" ';
	var url="/index.php?ajt=messages&doit=systemmodule&param1="+message+"&param2="; 
	AJAXRequest(url, 'resultCL', '');
}

function resultCL(param, result) {
	//alert(result);
}

var checkedTimeId;
var checkedTimeClass;
function doChecked(obj) {
	var tmp = document.getElementById('checkedTimeId');
	if(tmp && tmp.value!='') {checkedTimeId=tmp.value; tmp.value=''; }
	var tmp = document.getElementById('checkedTimeClass');
	if(tmp && tmp.value!='') {checkedTimeClass=tmp.value;  tmp.value=''; }

	var fcs = document.getElementById('focuselm');
	if(obj) {
		re = / available/i;
		if(re.exec(obj.className)) {
			var tmp = document.getElementById(checkedTimeId);
			if(tmp && checkedTimeClass!='') {
				tmp.className = checkedTimeClass;
			}
			checkedTimeId = obj.id;
			checkedTimeClass = obj.className;
			obj.className += " clicked";
			if(fcs) fcs.value = obj.id;
		}
	}
	if(fcs) fcs.focus();
}
function setRepetitiveParams(vl) {
	if(vl!="") {
		var by_date = document.getElementById('by_date');
		if(by_date) by_date.style.display = 'none';
		var by_weekday = document.getElementById('by_weekday');
		if(by_weekday) by_weekday.style.display = 'none';
		var by_daynumber = document.getElementById('by_daynumber');
		if(by_daynumber) by_daynumber.style.display = 'none';
		var title_day_off = document.getElementById('title_day_off');
		if(title_day_off) if (vl == 'Every Day') title_day_off.style.display = 'none'; else title_day_off.style.display = 'block';
		switch(vl) {
			case "No repeat": 
				by_date.style.display = 'block';
			break;
			case "Every Day": 
				// hide all
			break;
			case "Every Week": 
				by_weekday.style.display = 'block';
			break;
			case "Every Month": 
				by_daynumber.style.display = 'block';
			break;
		}
	}
}
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;
}
//var timeoffindex = 0;
function timeOffChange(val, ind) {
	var tmp = document.getElementById('TIME_OF_TO_SELECT_'+ind); 
	var tmpTo = document.getElementById('TIME_OF_TO_'+ind); 
	if(tmp) {
		if(val == "allday") {
			//timeoffindex = tmp.selectedIndex;
			tmp.style.visibility = 'hidden';
			if(tmpTo) tmpTo.style.visibility = 'hidden';
		} else {
			//stmp.selectedIndex=timeoffindex ;
			tmp.style.visibility = 'visible';
			if(tmpTo) tmpTo.style.visibility = 'visible';
		}
	}
}
var TimeOffAdditCounter = 1;
function addTimeOff(obj) {
	var nod = obj.parentNode;
	if(nod && nod.nodeName=='TD') {
		var nod = nod.parentNode;
		if(nod && nod.nodeName=='TR') {
			var objTR = document.createElement("tr");
			if(objTR) {
				objTR.setAttribute('id','nodeTR_'+TimeOffAdditCounter);

				var objTD = document.createElement("td");
				objTD.setAttribute('nowrap','nowrap');
				objTD.setAttribute('align','left');
				objTD.innerHTML = 'CHOOSE A DAY:';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('align','left');
				objTD.innerHTML = '<select name="DAY_OFF_'+TimeOffAdditCounter+'"><option value="everyday">Everyday<option value="0">Sunday<option value="1">Monday<option value="2">Tuesday<option value="3">Wednesday<option value="4">Thursday<option value="5">Friday<option value="6">Saturday</select>';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.innerHTML = ' ';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('nowrap','nowrap');
				objTD.setAttribute('align','left');
				objTD.innerHTML = 'CHOOSE A TIME:';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('align','left');
				objTD.innerHTML = '<select name="TIME_OF_FROM_'+TimeOffAdditCounter+'" onchange="timeOffChange(this.value, '+TimeOffAdditCounter+');"><option value="allday">All Day</option><option selected>12 AM</option><option>1 AM</option><option>2 AM</option><option>3 AM</option><option>4 AM</option><option>5 AM</option><option>6 AM</option><option>7 AM</option><option>8 AM</option><option>9 AM</option><option>10 AM</option><option>11 AM</option><option>12 PM</option><option>1 PM</option><option>2 PM</option><option>3 PM</option><option>4 PM</option><option>5 PM</option><option>6 PM</option><option>7 PM</option><option>8 PM</option><option>9 PM</option><option>10 PM</option><option>11 PM</option></select>';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('id','TIME_OF_TO_'+TimeOffAdditCounter);
				objTD.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;TO:&nbsp;&nbsp;&nbsp;&nbsp;';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('nowrap','nowrap');
				objTD.setAttribute('align','left');
				objTD.innerHTML = '<select name="TIME_OF_TO_'+TimeOffAdditCounter+'" id="TIME_OF_TO_SELECT_'+TimeOffAdditCounter+'"><option>12 AM</option><option selected>1 AM</option><option>2 AM</option><option>3 AM</option><option>4 AM</option><option>5 AM</option><option>6 AM</option><option>7 AM</option><option>8 AM</option><option>9 AM</option><option>10 AM</option><option>11 AM</option><option>12 PM</option><option>1 PM</option><option>2 PM</option><option>3 PM</option><option>4 PM</option><option>5 PM</option><option>6 PM</option><option>7 PM</option><option>8 PM</option><option>9 PM</option><option>10 PM</option><option>11 PM</option></select>';
				objTR.appendChild(objTD);

				var objTD = document.createElement("td");
				objTD.setAttribute('nowrap','nowrap');
				objTD.setAttribute('align','left');
				objTD.innerHTML = '<a href="#" onClick="removeDOMObj(\'nodeTR_'+TimeOffAdditCounter+'\'); return false;" class="cLilac">Remove</a>';
				objTR.appendChild(objTD);

				var nodT = nod.parentNode;
				nodT.insertBefore(objTR, nod);
				TimeOffAdditCounter++;
			}
		}
	}
}

function removeDOMObj(id) {
	var obj = document.getElementById(id); 
	if(obj) {
		var nodT = obj.parentNode;
		nodT.removeChild(obj);
	}
}

function menuarrowclick(ev) {
	if (ev==undefined) ev = window.event; 
	//alert(ev)
	if (me.menu != null) me.menu.popup(ev, 'd_cal_cell_[#COL#]_0');
}
function hideMenuarrow() {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		for(i=0; i<document.getElementsByTagName('div').length; i++) 
			if (document.getElementsByTagName('div')[i].className=='menuarrow') document.getElementsByTagName('div')[i].style.display = 'none';
	} else {
		var tmp3 = document.getElementsByName('menuarrow');
		if(tmp3.length>0) for(k=0; k<tmp3.length; k++) tmp3[k].style.display = 'none';
	}
}
function showMenuarrow() {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		for(i=0; i<document.getElementsByTagName('div').length; i++) 
			if (document.getElementsByTagName('div')[i].className=='menuarrow') document.getElementsByTagName('div')[i].style.display = 'block';
	} else {
		var tmp3 = document.getElementsByName('menuarrow');
		if(tmp3.length>0) for(k=0; k<tmp3.length; k++) tmp3[k].style.display = 'block';
	}
}

function tellAFriendForm(mode){
	if (typeof mode == "undefined") mode = "";
	if (mode == "send"){
		var emails = 'emails="' + escape(document.getElementById("inv_emails").value) + '"';
	} else var emails = '';
	doSystemMessages('systemmodule', 'name="feedback" view_mode="tell_a_friend" ajax="on" mode="'+mode+'"'+emails);
}

function showClientSelect(cid, allclients) {
	var cid = cid || 0;
	var allclients = allclients || [];
	if(allclients.length > 0 ) {
		for(i=0; i<allclients.length; i++) {
			var tmp  = document.getElementById('select_client_'+allclients[i]);
			if(tmp)  {
				if(cid == allclients[i]) {
					tmp.style.display = 'block';
				} else {
					tmp.style.display = 'none';
				}
			}
		}
	}
}

/*media player*/
var DRAG_lastX=900, DRAG_dragging = false;
var currentPosition=0;
var currentRemaining=100;
var currentVolume;
var setVolumeIn=80;
var setPlayedIn=0;
var currentItem;
var currentState;
var currentLoad;
var currentXsize;
var currentYsize;

function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1)	return window[movieName];
	else return document[movieName];
};
function sendEvent(typ,prm) { 
	var typ = typ || 'playpause';
	var prm = prm || '';
	thisMovie("playerID").sendEvent(typ,prm); 
	if(typ=='playpause') {thisMovie("playerID").sendEvent('volume',setVolumeIn);}
};
function loadFile(obj) { thisMovie("playerID").loadFile(obj); };
function addItem(obj,idx) { thisMovie("playerID").addItem(obj,idx); };
function removeItem(idx) { thisMovie("playerID").removeItem(idx); };
function getLength(swf) { return(thisMovie(swf).getLength()); };
function getItemData(idx) { var obj = thisMovie("playerID").itemData(idx); };
function getUpdate(typ,pr1,pr2,swf) { 
	var pr1 = pr1 || undefined;
	var pr2 = pr2 || undefined;
	var swf = swf || "";
	if(typ == "time") { currentPosition = pr1; pr2 == undefined ? null: currentRemaining = Math.ceil(pr2); }
	else if(typ == "state") { currentState = pr1; }
	else if(typ == "volume") { currentVolume = pr1; } 
	/*else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100);}
	else if(typ == "load") { currentLoad = pr1; }
	else if(typ == "size") { currentXsize = "X=" + pr1; pr2 == undefined ? null: currentYsize = "Y=" + Math.round(pr2); } */
	var tmp = document.getElementById("currtime"); if (tmp) { 
		min = (Math.floor(currentPosition/60));
		sec = currentPosition-min*60;
		if(min<=9) min = '0'+min;
		if(sec<=9) sec = '0'+sec;
		if(isNaN(min)) min = '00'
		if(isNaN(sec)) sec = '00'
		tmp.innerHTML = min +":"+sec; 
	}
	var tmp = document.getElementById("stateButt"); if (tmp) { 
		if(currentState == 0) tmp.className = 'playButton';
		if(currentState == 1) tmp.className = 'playButton';
		if(currentState == 2) tmp.className = 'playButton sel';
		if(currentState == 3) tmp.className = 'playButton';
	} 
	var tmp = document.getElementById("volumer"); if (tmp && !DRAG_dragging) { 
		tmp.style.display = "block";
		if(isNaN(currentVolume)) currentVolume = 0;
		tmp.style.marginLeft = Number(16+Math.ceil(45*currentVolume/100)) + "px";
	} 
};


function changeNum(prefix, act) {
	var curr = document.getElementById(prefix+'current_num');
	var maxVal = document.getElementById(prefix+'maxVal');
	var minVal = document.getElementById(prefix+'minVal');
	var NUMBERS = document.getElementById(prefix+'NUMBERS');
	if(curr && maxVal && minVal) {
		var val = parseInt(curr.innerHTML);
		var maxVal = parseInt(maxVal.value);
		var minVal = parseInt(minVal.value);
		if(act == '+') {
			val ++;
			if(val > maxVal) val = maxVal;
			curr.innerHTML = val.toString();
		}
		if(act == '-') {
			val --;
			if(val < minVal) val = minVal;
			if(val < 0) val = 0;
			curr.innerHTML = val.toString();
		}
		NUMBERS.value =  val;
	}
	return false;
}