function fetch (idname)
{
  if (typeof idname != 'string')
    return idname;
	else if (document.getElementById)
		return document.getElementById (idname);
	else if (document.all)
		return document.all [idname];
	else if (document.layers)
		return document.layers [idname];
	else
		return null;
}

function fetch_tags (parentobj, tag)
{
	if (typeof parentobj.getElementsByTagName != 'undefined')
		return parentobj.getElementsByTagName (tag);
	else if (parentobj.all && parentobj.all.tags)
		return parentobj.all.tags (tag);
	else
		return null;
}

function SetCookie (name, value, seconds)
{
  var expires = new Date ();
  
  if (value !== false)
  {
    // Set default seconds
    if (typeof seconds == 'undefined')
      var seconds = 365 * 86400;
    
    expires.setTime (expires.getTime () + seconds * 1000);
  }
  else
    expires.setTime (expires.getTime () - 1000 * 86400 * 365);
  
	document.cookie = name + '=' + escape (value) + '; expires=' + expires.toGMTString () + '; path=/';
}

function FetchCookie (name)
{
	var cookie_name = name + '=';
	var cookie_length = document.cookie.length;
	var cookie_begin = 0;
  
	while (cookie_begin < cookie_length)
	{
		var value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring (cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (';', value_begin);
			if (value_end == -1)
				value_end = cookie_length;
      
			return unescape (document.cookie.substring (value_begin, value_end));
		}
    
		cookie_begin = document.cookie.indexOf (' ', cookie_begin) + 1;
		if (cookie_begin == 0)
			break;
	}
  
	return null;
}

function PageInit ()
{
  var count;
  
	// Set 'title' tags for image elements
	var imgs = fetch_tags (document, 'img');
	for (count = 0; count < imgs.length; count++)
		if (!imgs [count].title && imgs [count].alt != '')
			imgs [count].title = imgs [count].alt;
  
  // Capslock detection for password fields
	var inputs = fetch_tags (document, 'input');
	for (count = 0; count < inputs.length; count++)
    if (inputs [count].type == 'password')
      inputs [count].onkeypress = CapslockAlert;
  
	// Collapse buttons
  var id, caption, img, link;
	var spans = fetch_tags (document, 'span');
	for (count = 0; count < spans.length; count++)
  {
		if (spans [count].id.substring (0, 8) == 'collapse')
    {
      id = spans [count].id.substring (9);
      caption = spans [count].innerHTML;
      SetInnerHTML (spans [count], '');
      
      img = document.createElement ('img');
      img.id = 'img_collapse_' + id;
      img.src = 'img/collapse.gif';
//      img.width = img.height = 11;
      img.style.cursor = "pointer";
      img.title = 'לחץ להסתרת/חשיפת מידע';
      eval ("AddEvent (img, 'click', function () { DoCollapse ('" + id + "'); } );");
      spans [count].appendChild (img);
      spans [count].style.styleFloat = 'right';
      
      if (caption != '')
      {
        spans [count].appendChild (document.createTextNode (' '));
        
        link = document.createElement ('a');
        link.innerHTML = caption;
        link.style.cursor = "pointer";
        eval ("AddEvent (link, 'click', function () { DoCollapse ('" + id + "'); } );");
        spans [count].appendChild (link);
      }
      
      if (FetchCookie ('collapse_' + id) == 1)
        DoCollapse (id);
    }
  }
}

function ToggleDisplay ()
{
  var object;
  
  for (var count = 0; count < arguments.length; count++)
  {
    object = fetch (arguments [count]);
    if (object != null)
      object.style.display = object.style.display ? '' : 'none';
  }
}

function DoCollapse (id)
{
  ToggleDisplay (id);
  var collapsed = (fetch (id).style.display == '') ? false : 1;
  fetch ('img_collapse_' + id).src = collapsed ? 'img/expand.gif' : 'img/collapse.gif';
  SetCookie ('collapse_' + id, collapsed);
}

function CollapseAll (collapse, basename)
{
	var spans = fetch_tags (document, 'span');
	for (count = 0; count < spans.length; count++)
  {
		if (spans [count].id.substring (0, 9 + basename.length) == 'collapse_' + basename)
    {
      id = spans [count].id.substring (9);
      if (collapse && IsVisible (id) || !collapse && !IsVisible (id))
        DoCollapse (id);
    }
  }
}

function Hide ()
{
  var object;
  
  for (var count = 0; count < arguments.length; count++)
  {
    object = fetch (arguments [count]);
    
    if (typeof object == 'string')
      object = fetch (object);
    
    if (object != null)
      object.style.display = 'none';
  }
}

function Show ()
{
  var object;
  
  for (var count = 0; count < arguments.length; count++)
  {
    object = fetch (arguments [count]);
    
    if (typeof object == 'string')
      object = fetch (object);
    
    if (object != null)
      object.style.display = '';
  }
}

function IsVisible (object)
{
  if (typeof object == 'string')
    object = fetch (object);
  
  if (object != null)
    return object.style.display != 'none';
}

function SetInnerHTML (objectname, html)
{
  var object = fetch (objectname);
  
  if (object != null)
    object.innerHTML = html;
}

function AddEvent (object, event, callback)
{
  object = fetch (object);
  
  if (object.attachEvent)
    object.attachEvent ('on' + event, callback);
  else if (object.addEventListener)
    object.addEventListener (event, eval (callback), false);
  else
    eval ("object.on" + event + " = callback");
}

function DetectCapslock (e)
{
  e = (e ? e : window.event);
  
  var keycode = (e.which ? e.which : (e.keyCode ? e.keyCode : (e.charCode ? e.charCode : 0)));
  var shifted = (e.shiftKey || (e.modifiers && (e.modifiers & 4)));
  var ctrled = (e.ctrlKey || (e.modifiers && (e.modifiers & 2)));
  
  // if characters are uppercase without shift, or lowercase with shift, caps-lock is on.
  return (keycode >= 65 && keycode <= 90 && !shifted && !ctrled) ||
         (keycode >= 97 && keycode <= 122 && shifted) ||
         (keycode >= 1488 && keycode <= 1514 && shifted);
}

var CapslockAlertShown = false;
function CapslockAlert (e)
{
  if (DetectCapslock (e) && !CapslockAlertShown)
  {
    alert ('!שלך פעיל Caps Lock-שים לב: מקש ה\n\n.במצב זה הסיסמא עלולה לא להתקבל\n\n.כדי לבטלו Caps Lock-מומלץ כי תלחץ על מקש ה');
    CapslockAlertShown = true;
  }
}

function ConfirmRemoveEntry ()
{
  return confirm ('!פעולה זו תמחק את הרשומה, והינה בלתי הפיכה\n\n?האם אתה בטוח שברצונך להמשיך');
}

function CloneField (fieldname)
{
  var count, elements;
  
  // Clone original field
  var prototype = fetch ("prototype_" + fieldname);
  var clone = prototype.cloneNode (true);
  
  // Set cloned field properties
	elements = fetch_tags (clone, 'input');
	for (count = 0; count < elements.length; count++)
    elements [count].value = '';
  
  // Remove manual clone link from prototype
	elements = fetch_tags (prototype, 'div');
	for (count = 0; count < elements.length; count++)
		if (elements [count].id.substring (0, 10) == 'clonelink_')
      Hide (elements [count]);
  
  // New prototype in town!
  prototype.id = '';
  
  // Add cloned field
  fetch ("more_" + fieldname).appendChild (clone);
}

function AJAX (Parameters, HandlerFunc)
{
  if (typeof HandlerFunc == 'undefined')
    var HandlerFunc = ProcessXML;
  
  return new Ajax.Request ('ajax.php', {method: 'post', parameters: Parameters, onComplete: HandlerFunc});
}

function ProcessXML (AJAXHandler)
{
  var fields = fetch_tags (AJAXHandler.responseXML, 'field');
  var variables = fetch_tags (AJAXHandler.responseXML, 'variable');
  var executes = fetch_tags (AJAXHandler.responseXML, 'execute');
  var count, code, fieldname, fieldvalue, escapedvalue, ifchanged;
  
  for (count = 0 ; count < fields.length ; count++)
  {
    fieldname = fields [count].getAttribute ("id");
    fieldvalue = (fields [count].firstChild != null) ? fields [count].firstChild.nodeValue : '';
    SetInnerHTML (fieldname, fieldvalue);
  }
  
  for (count = 0 ; count < variables.length ; count++)
  {
    fieldname = variables [count].getAttribute ("name");
    fieldvalue = (variables [count].firstChild != null) ? variables [count].firstChild.nodeValue : '';
    escapedvalue = fieldvalue.replace (/'/g, "\\'");
    ifchanged = variables [count].getAttribute ("ifchanged");

    code  = 'if (typeof ' + fieldname + ' != \'undefined\' && ' + fieldname + ' != \'' + escapedvalue + '\')';
    code += '{';
    code += fieldname + ' = \'' + escapedvalue + '\';';
    if (ifchanged != null)
      code += ifchanged + ';';
    code += '}';
    eval (code);
  }
  
  for (count = 0 ; count < executes.length ; count++)
    if (executes [count].firstChild != null)
      eval (executes [count].firstChild.nodeValue);
}

function SetActiveTab (index)
{
  var tabid;
  
  var divs = fetch_tags (document, 'div');
  for (var count = 0 ; count < divs.length ; count++)
    if (divs [count].id.substring (0, 12) == 'tab_content_')
    {
      tabid = divs [count].id.substring (12);
      if (index == tabid)
      {
        Show ('tab_content_' + tabid);
        fetch ('tab_button_' + tabid).className = 'active';
      }
      else
      {
        Hide ('tab_content_' + tabid);
        fetch ('tab_button_' + tabid).className = '';
      }
    }
}

 function hover(oElement) {
    oElement.className = (oElement.className == "normal") ? "hover" : "normal" ;
}



        function hide(n) {
            n = n.replace('^', '@');
            n = n.replace('~', 'mailto:');
            n = n.replace('`', '.');
            document.location.href = n;
        }

        function Output(n) {
            n = n.replace('^', '@');
            n = n.replace('`', '.');
            return n;
        }

		
		// Ad close script
function closeBox(toClose) {
    document.getElementById(toClose).style.display = "none";
    setCookie(toClose, "closed", 365);

}
function setCookie(cName, value, expiredays) {
    var expDate = new Date();
    expDate.setDate(expDate.getDate()+expiredays);
    document.cookie=cName + "=" + escape(value) +
    ";expires=" + expDate.toGMTString();
}
function loadMsg(msgClass) {
    msg = document.getElementsByTagName("div");
    for (i=0; i<msg.length; i++) {
        if(msg[i].className == msgClass) {
            if(document.cookie.indexOf(msg[i].id) == -1) {
                msg[i].style.display = "block";
            } 
        }
    }
}
 // add bookmark
function bookmark(){
    var title="טלוויזיה באינטרנט - ישראמדיה"
    var url="http://www.isramedia.net"

    if (window.sidebar) window.sidebar.addPanel(title, url,"");

    else if( window.opera && window.print )
    {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
    }

    else if( document.all ) window.external.AddFavorite( url, title);

}

