var lastMenu = "";
var menuStatus = false;


var xmlHttp;

function afterSendMessage()
{
        if (xmlHttp.readyState==4) 
		{
        
			if (xmlHttp.status == 200)
			{
				try
				{
					response = xmlHttp.responseText;
					alert(response);
				}
				catch(e)
				{
					alert("Error reading of answer: " + e.toString());
				}	
			}
			else
			{
	//			alert("Problems with getting!!!:\n" + xmlHttp.statusText);
			}				
        }
}

var xmlHttp2;

function afterSendMessage2()
{alert('status='+xmlHttp2.status);
        if (xmlHttp2.readyState==4) 
		{
        
			if (xmlHttp2.status == 200)
			{
				try
				{
					response = xmlHttp2.responseText;
					alert(response);
				}
				catch(e)
				{
					alert("Error reading of answer: " + e.toString());
				}	
			}
			else
			{
				alert("Problems with getting!!!:\n" + xmlHttp.statusText);
			}				
        }
}



function sendPost(url, date)
{

	
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
		{
		  try 
		  { 
			// try to create XMLHttpRequest object
			xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
		  } 
		  catch (e) {}
		}
	}
	
	if (!xmlHttp)
		alert("Error with creating of object XMLHttpRequest");
	else
	{//alert(url+'?'+date);
	
        xmlHttp.open('POST',url+'?'+date,true);
	//alert(url+'?'+date);
       // xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlHttp.onreadystatechange=afterSendMessage;
        xmlHttp.send(null);

	}
}



function sendPost2(url, date)
{

	
	
	try
	{
		xmlHttp2 = new XMLHttpRequest();
	}
	catch(e)
	{
    // assume IE6 or older
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    // try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp2; i++) 
		{
		  try 
		  { 
			// try to create XMLHttpRequest object
			xmlHttp2 = new ActiveXObject(XmlHttpVersions[i]);
		  } 
		  catch (e) {}
		}
	}
	
	if (!xmlHttp2)
		alert("Error with creating of object XMLHttpRequest");
	else
	{alert(url+'?'+date);
	
        xmlHttp2.open('POST',url+'?'+date,true);
	alert(url+'?'+date);
       // xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xmlHttp2.onreadystatechange=afterSendMessage2;
        xmlHttp2.send(null);

	}
}



function gid (id) {
	return document.getElementById(id);
	}
	
function ajax(url,target) {
	var xmlHttp;
	try {  // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();  }
		catch (e) {  // Internet Explorer 
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
				}
			}
		}

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState == 4) gid(target).innerHTML = xmlHttp.responseText;
		}
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null); 
	}


function selectFromList2(selectId,id,lang) 
{ 
	var val =  document.getElementById(selectId).name;
	//alert(val);
	var obj = document.getElementById('valList2');
	obj.innerHTML = val;
	if (lang=="HEB")
		gid('valList3').innerHTML ='בחר הרצאה';
	else
		gid('valList3').innerHTML ='Choose a topic';
		
	
	gid('parSearch').innerHTML = '<input type="hidden" name="sID" value="'+id+'">';
	
	gid('expandedList3').innerHTML = ajax('martzim.php?op=chgSubject&id='+id,'expandedList3');
	
}		


function selectFromList3(selectId,id) 
{ 
	var val =  document.getElementById(selectId).name;
	 if (val.length > 20)
		val = val.substr(0,20)+'...';
//	alert(val);
	var obj = document.getElementById('valList3');
	obj.innerHTML = val;
	gid('parSearch').innerHTML = '<input type="hidden" name="sID" value="'+id+'">';
}			

	
function displayMenu (parent,menuStyle) {
	menuStatus = true;
	if (lastMenu) lastMenu.style.display = "none";

	gid(parent+'_child').style.display = "block";
/*	if ( menuStyle=="he" ) {
		gid(parent+'_child').style.left = getRealLeft(gid(parent));
		gid(parent+'_child').style.top = getRealTop(gid(parent)) + gid(parent).offsetHeight;
		} else if ( menuStyle=="hh" ) {
		gid(parent+'_child').style.left = getRealLeft(gid(parent)) + gid(parent).offsetWidth - gid(parent+'_child').offsetWidth;
		gid(parent+'_child').style.top = getRealTop(gid(parent)) + gid(parent).offsetHeight;
		} else if ( menuStyle=="ve" ) {
		gid(parent+'_child').style.left = getRealLeft(gid(parent)) + gid(parent).offsetWidth;
		gid(parent+'_child').style.top = getRealTop(gid(parent));
		} else if ( menuStyle=="vh" ) {
		gid(parent+'_child').style.left = getRealLeft(gid(parent)) - gid(parent+'_child').offsetWidth;
		gid(parent+'_child').style.top = getRealTop(gid(parent));
		}*/
	lastMenu = gid(parent+'_child');
	setTimeout("hideme();",1000);
	}

function hideme () 
{
	if (menuStatus) 
		setTimeout("hideme();",1000);
	else 
	{
		lastMenu.style.display = "none";
	}
}

function hideSelects () {	 
	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 showSelects () {	 
	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 getRealLeft(el) {
	xPos = el.offsetLeft;
	tempEl = el.offsetParent;
	while (tempEl != null) {
	xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
		}
		return xPos;
	}

function getRealTop(el) {
	yPos = el.offsetTop;
	tempEl = el.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
    		}
    	return yPos;
	}

function enlargePic(mypic) {
	windowPic = window.open('showpic.php?s='+mypic,'','resizable=0,status=0,scrollbars=0');
	}


function cngStyle (theClass,attr,prop) {  
	var allPageTags=document.getElementsByTagName("*");
	for (i=0; i<allPageTags.length; i++) { 
		if (allPageTags[i].className==theClass) { 
			allPageTags[i].style.setAttribute(attr,prop);
			}  
		} 
	} 



function getFilter (filtername) {
	filtername = filtername.toLowerCase();
	if (filtername=="fade") filtername 	= "progid:DXImageTransform.Microsoft.Fade(Overlap=1.00)";
	if (filtername=="zigzag") filtername 	= "progid:DXImageTransform.Microsoft.Zigzag(GridSizeX=8,GridSizeY=8)";
	return filtername;
	}

function sDisplay (id) {

	if (document.getElementById(id).style.display=="none") document.getElementById(id).style.display = "";
		else document.getElementById(id).style.display = "none";

	}

function opnclac (vars,fvar) {
	window.open('calendar.php?'+vars+'&re='+fvar,'','resizable=0,status=0,scrollbars=0')
	}

function numbersOnly () {
	if (event.keyCode<48||event.keyCode>57) if (event.keyCode!=45) if (event.keyCode!=46) return false
	}

function safeString (mystar) {
	var parsed = true;
	var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@-._אבגדהוזחטיכךלמםנןסעפףצץקרשת";
	for (var i=0; i < mystar.length; i++) {
		var letter = mystar.charAt(i).toLowerCase();
		if (validchars.indexOf(letter) == -1) parsed = false;
		}
	return parsed;
	}

function swapChk(strchk) {
	for(var i = 0;i<document.getElementsByTagName('INPUT').length;i++) {	
		if (document.getElementsByTagName('INPUT').item(i).name.indexOf(strchk) != -1) {
			if (document.getElementsByTagName('INPUT').item(i).checked) document.getElementsByTagName('INPUT').item(i).checked = 0;	
				else document.getElementsByTagName('INPUT').item(i).checked = 1;
			}
		}
	}

function confirmNsubmit(text,form) {
	myConfirm=confirm(text);
	if (myConfirm==true) form.submit();
	return (myConfirm);
	}

function confirmNhref(text,href) {
	myConfirm=confirm(text);
	if (myConfirm==true) location.href = href;
	return (myConfirm);
	}

function switchLang (cookie,lng) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
	setCookie(cookie, lng, expdate);
	location.reload();
	}

function check_email(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);
			} 
		}
	}

// -------------------------------------------------------------------------   
//                    Cookie Function's
// -------------------------------------------------------------------------   

	function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

	function setCookie(name, value, expires, path, domain, secure) {
		document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	}

	function getCookie(name) {
		var dc = document.cookie;
		var prefix = name + "=";
		var begin = dc.indexOf("; " + prefix);
		if (begin == -1) {
			begin = dc.indexOf(prefix);
			if (begin != 0) return null;
			} else {
			begin += 2;
			}
		var end = document.cookie.indexOf(";", begin);
		if (end == -1) end = dc.length;
		return unescape(dc.substring(begin + prefix.length, end));
	}

// -------------------------------------------------------------------------   
//                    END Cookie Function's
// -------------------------------------------------------------------------   

var enlargePopup = window.createPopup();
function enlargeCustom(s,w,h) {
	var enlargePopBody = enlargePopup.document.body;
	enlargePopBody.style.backgroundColor = 'black';
	enlargePopBody.style.border = 'solid black 1px';
	enlargePopBody.onmousedown = enlargePopup.hide;
	enlargePopBody.onclick = enlargePopup.hide;
	enlargePopBody.oncontextmenu = enlargePopup.hide;
	enlargePopBody.innerHTML = "<img src="+s+" width="+w+" height="+h+">";
	if (s) enlargePopup.show(event.clientX-w, event.clientY, w, h, document.body);
	}

	
	
function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("ajax_search.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
function fill(thisValue,thisId,flag,flag2) {
		$('#inputString').val(thisValue);
		$('#inputStringHidd').val(thisId);
		$('#butSearchMartze').attr(flag, '');
		$('#butSearchMartze').attr('src', flag2);
		//$('#butSearchMartze').css( "display", flag2);
		$('#butSearchMartze').focus(); 		

		setTimeout("$('#suggestions').hide();", 200);
}
