/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */

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" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */

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));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */

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 MM_reloadPage(init)
{  //reloads the window if Nav4 resized
		  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
		  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function show_hide_layer(l,s) 
{ 
	eval('document.getElementById("' + l + '").style.visibility="' + s + '"'); 
}	

function show_hide_block(block) 
{ 
	if(document.getElementById(block))
	{
		if (document.getElementById(block).style.display == "none") 
			document.getElementById(block).style.display = "block";
		else
			document.getElementById(block).style.display = "none"; 
	}
}	

function show_hide_block2(block,flag) 
{ 
	if (flag==0)
	{
		if (document.getElementById(block).style.display == "none") 
			document.getElementById(block).style.display = "block";
		else
			document.getElementById(block).style.display = "none"; 
	}
}	

function openWin(url,title,attrib) 
{
	wref=window.open(url,title,attrib);
}

function openInnewWindow(url,width,height,toolbar) 
{
	if(toolbar==1) {
		openWin(url,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+width+',height='+height)
	 }
	 else {
		openWin(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,movable=yes,resizable=no,top=100,left=100,width='+width+',height='+height)
	}
}
function openInnewWindowResizable(url,width,height,toolbar) 
{
	if(toolbar==1) {
		openWin(url,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,top=100,left=100,width='+width+',height='+height)
	 }
	 else {
		openWin(url,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,movable=yes,resizable=yes,top=100,left=100,width='+width+',height='+height)
	}
}

function doPrint()
{
	window.print();
}

function getIndexDetails(ind){
	doAjaxAction('/_inc/inmanage/ajax/index.counter.php','ind='+ind,getIndexDetails_Done);
}

function getIndexDetails_Done(result){
	document.getElementById('indexDetailsHolder').style.backgroundColor = '';
	document.getElementById('indexDetailsHolder').style.padding = '';
	document.getElementById('indexDetailsHolder').style.width = '';
	document.getElementById('indexDetailsHolder').style.lineHeight = '20px';
	if(result=='<dup/>' || result=='<err/>'){
		document.getElementById('indexDetailsHolder').innerHTML = '<br /><font color="gray">פעולה נכשלה. נסה שוב מאוחר יותר</font>';
	}else{
		document.getElementById('indexDetailsHolder').innerHTML = result;
	}
}

// AJAX
var xmlhttp;
function doAjaxAction(target,vars,func){
	if (window.XMLHttpRequest){ try { xmlhttp = new XMLHttpRequest(); }catch(e){ xmlhttp = false; }
	} else if(window.ActiveXObject){ try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp = false; } } }
	if (xmlhttp) xmlhttp.open('POST', target, true);
	else{ alert("error init"); return false; }
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200){
				if(func) func(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(vars);
}
// ^ AJAX

	


