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 picClick(el,txt) {
	opener.document.getElementById(el).value = txt;
	opener.document.getElementById(el).focus();
	opener.document.getElementById(el).blur();
	window.close();
	}

function winOpen(url, winname, w, h) {
	if (!w) w = 700;
	if (!h) h = 500;
	if (!winname) winname = null;
	window.open(url,winname,'width=' + w + ',height=' + h + ',resizable=0,status=no,scrollbars=2,menubar=no,toolbar=no');
	}


function wopen(url, name, w, h) {
	if (!w) w = 700;
	if (!h) h = 500;

	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no');
	win.resizeTo(w, h);
	win.moveTo(wleft, wtop);
	win.focus();
	}

function active_upload() {
	var str = ''
	var c_w = document.body.clientWidth + document.body.scrollLeft;
	var c_h = document.body.clientHeight + document.body.scrollTop;

	var c_h_2 = c_h / 2;

	str += '<div style="filter:Alpha(opacity=85); position:absolute; right:0px; top:0px; width:'+ c_w +'px; height:'+ c_h +'px; background-color:white;"></div>';
	str += '<div style="text-align:center; right:0px; top:'+ c_h_2 +'px; width:100%; position:absolute;">';
	str += '<embed wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="126" height="44" name="upload_flash" src="main/img/upload.swf" bgcolor="#FFFFFF" quality="best" menu="false"></embed>';
	str += '</div>';
	document.body.innerHTML += str;
	}


function addfolder(href) {
	var s = prompt('הכנס שם לספריה', '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 autoComplete (field, select, property, forcematch) {
	var found = false;
	for (var i = 0; i < select.options.length; i++)  if (!select.options[i]['act']) {
	if (select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
		found=true; break;
		}
	}
	if (found) { select.selectedIndex = i; }
	else { select.selectedIndex = -1; }
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
			}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				}
			}
		}
	}

function ref_mem() {
	gid('login_table').style.display = '';
	gid('login_table_2').style.display = '';
	gid('member_label').style.display = 'none'; 
	}
function check_members() {
	var req = false;
	req = new ActiveXObject("Microsoft.XMLHTTP");
	if (req) {
		gid('login_table').style.display = 'none';
		gid('login_table_2').style.display = 'none';
		gid('member_label').style.display = ''; 
		gid('member_label').innerHTML = '<br><img width=35 src="img/ajax.gif"><br>';

		req.open('POST', 'members.php?op=ajaxuserLoginCheck&username=' + gid("uname").value + '&userpass=' + gid("upass").value, false);
		req.send(null);
		if (req.responseText == 1) {
			location.href='index.php';
			} else {
			gid('member_label').innerHTML = '<br>שגיאה בהתחברות, נסה שנית';
			gid('member_label').innerHTML += '<br><center><a class=siteLink href="javascript:ref_mem();">חזור אחורה</a></center>';
			}
		} else {
		return false;
		}
	}