var thisMenu = '';
var closeMe = false;

function showMenu(menuId, styleMenu) {
	menuId = gid(menuId);
	subMenuId = gid(menuId.id+"_sub");
	hideSelectObjects();
	if (thisMenu) thisMenu.style.display = 'none';
	subMenuId.style.display = '';
	closeMe=false;
	if (styleMenu == "h") {
		var menuHeight = getRealObjectTop(menuId) + menuId.offsetHeight;
		var menuLeft = getRealObjectLeft(menuId) + menuId.offsetWidth - subMenuId.offsetWidth;
	} else {
		var menuHeight = getRealObjectTop(menuId);
		var menuLeft = getRealObjectLeft(menuId) - subMenuId.offsetWidth;
		}
	subMenuId.style.top = menuHeight;
	subMenuId.style.left = menuLeft;

	subMenuId.style.display = '';
	thisMenu = gid(subMenuId.id);
	}

function hideMenu() {
	if (closeMe) {
		thisMenu.style.display = "none";
		showSelectObject();
		} else setTimeout("hideMenu();",1000);
	}

function hideAllMenu() {
	for(var i = 0;i<document.getElementsByTagName("DIV").length;i++) {	 
		if (document.getElementsByTagName("DIV").item(i).isMenu == 'true') document.getElementsByTagName("DIV").item(i).style.display = "none";
		}	 

	showSelectObject();
	}

function getRealObjectLeft(el) {
	xPos = el.offsetLeft;
	tempEl = el.offsetParent;
	while (tempEl != null) {
	xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
		}
		return xPos;
	}

function getRealObjectTop(el) {
	yPos = el.offsetTop;
	tempEl = el.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
    		}
    	return yPos;
	}

function hideSelectObjects () {	 
	for(var i = 0;i<document.getElementsByTagName("SELECT").length;i++) {	 
		if (document.getElementsByTagName("SELECT").item(i).id != 'select1cal' && document.getElementsByTagName("SELECT").item(i).id != 'select2cal')
			document.getElementsByTagName("SELECT").item(i).style.visibility = "hidden";	 
		}	 
	}	
 
function showSelectObject () {	 
	for(var i = 0;i<document.getElementsByTagName("SELECT").length;i++) {	 
		if (document.getElementsByTagName("SELECT").item(i).id != 'select1cal' && document.getElementsByTagName("SELECT").item(i).id != 'select2cal')	 
			document.getElementsByTagName("SELECT").item(i).style.visibility = "visible";	 
		}	 
	}
function gid(id) {
	return document.getElementById(id);
	}
function yesORno(text,href) {
	myConfirm=confirm(text);
	if (myConfirm==true) location.href = href;
	}
function checkmail(e) {
	ok ="1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
			}	
		} 
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (-1);
			} 
		}
	}


function select_color(name){
	var id = document.getElementById('dlgHelper');
	var rColor = '';
	var spanID = document.getElementById('the_color_' + name);
	var inputID = document.getElementById(name);
	var sInitColor = spanID.style.backgroundColor;
	if (sInitColor) {
		sInitColor.replace('#', '');
		var sColor = id.ChooseColorDlg(sInitColor);
		} else {
		var sColor = id.ChooseColorDlg();
		}

	sColor = sColor.toString(16);
	if (sColor.length < 6) {
		var sTempString = "000000".substring(0,6-sColor.length);
		sColor = sTempString.concat(sColor);
		}
	rColor = '#' + sColor;

	spanID.style.backgroundColor = rColor;
	inputID.value = rColor;
	

//	return rColor;
	}
function input_color(name, value, extra) {
	var str = '';


	str += '<OBJECT id=dlgHelper CLASSID="clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b" width="0px" height="0px"></OBJECT>';
	str += '<input READONLY type="text" value="'+ value +'" name="'+ name +'" '+ extra +'>&nbsp;<span style="background: '+ value +';" id="the_color_'+ name +'"><img align="absmiddle" onclick="select_color(\''+ name +'\');" src="img/color_backet.gif"></span>';
	document.write(str);
	}




function picClick(el,txt) {
	opener.document.getElementById(el).value = txt;
	opener.document.getElementById(el).focus();
	opener.document.getElementById(el).blur();
	window.close();
	}

function add_to_list(fromCtrl, toCtrl) {
	var i;
	var j;
	var itemexists;
	var nextitem;

	fromCtrl = gid(fromCtrl);
	toCtrl = gid(toCtrl);

	// step through all items in fromCtrl
	for (i = 0; i < fromCtrl.options.length; i++) {
		if (fromCtrl.options[i].selected) {
			// search toCtrl to see if duplicate
			j = 0;
			itemexists = false;
			while ((j < toCtrl.options.length) && (!(itemexists))) {
				if (toCtrl.options[j].value == fromCtrl.options[i].value) {
					itemexists = true;
					alert(fromCtrl.options[i].value + " found!") ;
				}
				j++;
			}
			if (!(itemexists)) {
				// add the item
				nextitem = toCtrl.options.length;
				toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
				toCtrl.options[nextitem].value = fromCtrl.options[i].value;
			}
		}
	}
}

function remove_from_list(fromCtrl) {
	var i = 0;
	var j;
	var k = 0;

	fromCtrl = gid(fromCtrl);
	while (i < (fromCtrl.options.length - k)) {
		if (fromCtrl.options[i].selected) {
			// remove the item
			for (j = i; j < (fromCtrl.options.length - 1); j++) {
				fromCtrl.options[j].text = fromCtrl.options[j+1].text;
				fromCtrl.options[j].value = fromCtrl.options[j+1].value;
				fromCtrl.options[j].selected = fromCtrl.options[j+1].selected;
			}
			k++;
		} else {
			i++;
		}
	}
	for (i = 0; i < k; i++) {
		fromCtrl.options[fromCtrl.options.length - 1] = null;
	}
}

function array_to_string(Ctrl) {
	var i;
	var j = 0;
	var outlist = "";
	Ctrl = gid(Ctrl);
	for (i = 0; i < Ctrl.length; i++) {
		if (j > 0) {
			outlist = outlist + "|";
		}
		outlist = outlist + Ctrl[i].value;
		j++;
	}
	return outlist;
}
function addfolder(href) {
	var txt = 'הכנס שם לספריה';
	var s = prompt(txt, 'newfolder001');
	if (s != null && s != '') {
		location.href=href + '&mkdir=' + s;
		}
	}

function doi(img, href) {
	var m = window.showModalDialog('explorer.php?popimg=' + img, window , 'dialogWidth:300px;dialogHeight:165px; status:no;');
	 if (m) location.href = href;
	}


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
		window.onload = function() {
			if (oldonload) oldonload();
			func();
			}
		}
	}

// ----------------------------------
function uol() {
	var xmlHttpReq = false;
	xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	xmlHttpReq.open('POST', '/ajax.php?op=uol', true);
	xmlHttpReq.send();

	var t = 1000 * 60 * 5;
	var tuol = setInterval('uol()',t);
	}

function openit(id) {
	id = gid(id);
	if (id.style.display == 'none') id.style.display = '';
		else id.style.display = 'none';
	}
function winopen(url) {
	window.open (url, "mywindow","scrollbars,fullscreen=yes");
	}

function playit(id) {
	window.open ("play.php?id=" + id, "playwindow","width=500,height=400");
	}

function change_lst(el, id) {
	var xmlHttpReq = false;
	xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	xmlHttpReq.open('POST', 'info.php?op=clst&id=' + id, true);

	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4)	{
			gid(el).innerHTML = xmlHttpReq.responseText;
			}
		}
	xmlHttpReq.send();
	}

function count_refersh(id, val, url) {
	id = document.getElementById(id);
	if (val > 0) {
		val = val - 1;
		setTimeout('count_refersh("'+ id.id +'" ,"'+ val +'","'+ url + '")',1000);
		id.innerHTML = val;
		} else {
		location.href = url;
		}
	}