var coll, styleObj, isNav, isIE, isIE55, b, currWidth, currTop, msnTop, tickersLength, browserVer, commNo, currTime, h, m, s;
// Browser params - Start
isNav = isIE = isIE55 = false;
var timeArray = [];
browser = navigator.appName;
browserVer = navigator.appVersion;
if (browser == "Netscape") isNav = true;
else if (browser == "Microsoft Internet Explorer") isIE = true;
if (isIE)
{
 if (browserVer.indexOf("MSIE 5.5") != -1) isIE55 = true;
 coll = "all.";
	styleObj = ".style";
 document.write("<body>");currWidth = getWidth();document.write("</body>");
}
else
{
 coll = "ids.";
	styleObj = "";
 currWidth = getWidth();
}
// Browser params - End
function titleView(title)
{
if(title != "(*")
{
	document.title = title;
}
}
function pageInit(pID, commNum){
 commNo = commNum;
 if ((pID == 1)||(pID == 69))
 {
   currTime = document.all.isTime.innerText;
   startTime(currTime);
   digiTime();
 }
}
 function pageArch(pID){
 if (pID == 33 ||pID == 37){
   if (document.all)
        document.all.wait.style.visibility="hidden";
   }
 }

// Clock functions Start
function digiTime()//Clock Function
{
 if (!document.layers)
 {
  h = timeArray[0]; m = timeArray[1]; s = timeArray[2];
  if (s < 59) s = parseInt(s) + 1;
  else
  {
   s = 0;
   if (m < 59) m = parseInt(m) + 1;
   else
   {
    m = 0;
    if (h < 24) h = parseInt(h) + 1;
    else h = 1;
   }
  }
  timeArray[0] = h;
  timeArray[1] = m;
  timeArray[2] = s;
 	var strH = strM = strS = "";
  if (h < 10) strH = "0" + h; else strH = h;
  if (m < 10) strM = "0" + m; else strM = m;
  if (s < 10) strS = "0" + s; else strS = s;
  if (strH.length == 3) strH = strH.substring(1, strH.length);
  if (strM.length == 3) strM = strM.substring(1, strM.length);
  if (strS.length == 3) strS = strS.substring(1, strS.length);
 	digclock = strH + ":" + strM;// + ":" + strS;
 
 	document.all.isTime.innerText = digclock;
 			
  setTimeout("digiTime()",1000)
 }
}
function startTime(time)//Insert server's time into array
{
 timeArray[0] = time.substring(0, time.indexOf(" "));
 timeArray[1] = time.substring(time.indexOf(" ")+1, time.length);
 timeArray[2] = 0;
}

var tickerwidth=450;
var tickerheight=28;
var tickerbgcolor="#771C1B";
var tickerCounter = 0;

var msgTexts = new Array();
var msgTimes = new Array();
var msgAgencys = new Array();
var msgLines = new Array();
var cCodeArray = new Array();
var currTWidth = 760;
var currTblWidth = Math.floor(currTWidth/6);

function changeContent(which, what, text){
 if (which == "t12")
  text = "<table border='0' cellspacing='0' cellpadding='0' width='270'><tr><td align='right'><span class='" + which + "'>" + text + "</span></td></tr></table>";
 else if (which == "t11")
  text = "<table border='0' cellspacing='0' cellpadding='0' width='200'><tr><td align='right'><span class='" + which + "'>" + text + "</span></td></tr></table>";
 else
  text = "<span class='" + which + "'>" + text + "</span>";
 what.document.open();
 what.document.write(text);
 what.document.close();
}

function initTickers(){
	var tmpTime, tmpText;
	tickersLength = document.all.tickerText.length;
  	for (var i=0;i<tickersLength;i++){
 	   tmpText = eval("document." + coll + "tickerText[i].innerText");
      msgTexts[i] = setTicker(tmpText, i);
		tmpTime = eval("document." + coll + "tickerTime(i).innerText");
		msgTimes[i] = tmpTime;
		msgAgencys[i] = eval("document." + coll + "tickerAgency(i).innerText");
	}
 insertTicker(tickerCounter);
}
function setTicker(strTicker, counter){
   var tmp = /\n/;
   if (strTicker.length > 130) // width of ticker text
   {
		msgLines[counter] = Math.ceil(strTicker.length/63); // test how many rows 
      var tmpStr = strTicker.substring(0, strTicker.search(tmp));
      strTicker = strTicker.substring(strTicker.search(tmp)+1, strTicker.length);
      if (strTicker.search(tmp) != -1)
      strTicker = tmpStr + "... " + strTicker.substring(0, strTicker.search(tmp));
	}
	else
	{
      var tmpStr = strTicker.substring(strTicker.search(tmp), strTicker.length);
		if (tmpStr.length > 80)
			msgLines[counter] = 2;
		else
		 msgLines[counter] = 1;
	}
 return strTicker;
}
function insertTicker(tCounter){
	document.all.tickerDateTd.innerHTML = "<span class='t11r1'>" + msgTimes[tCounter] + "</span>";
	document.all.tickerAgencyTD.innerHTML = "<span class='t11r1'>" + msgAgencys[tCounter] + "</span>";
   document.all.tickerTxtTd.innerText = msgTexts[tCounter];
}
function nextTicker(){
   if (tickerCounter < (tickersLength - 1))
		tickerCounter++;
	else
		tickerCounter = 0;
 
   if (isIE)
 	   insertTicker(tickerCounter);
}
function prevTicker(){
	if (tickerCounter > 0)
		tickerCounter--;
	else
		tickerCounter = tickersLength - 1;
   if (isIE)
 	   insertTicker(tickerCounter);
}
function showT(expose){
 var tmpText = msgTexts[tickerCounter]
 if (tmpText.length > 96){
  var textL = eval(document.layers['tickerTxtTd']);
  if (expose)
   changeContent("t12", textL, tmpText);
  else{
   tmpText = setNavTicker(tmpText);
   changeContent("t12", textL, tmpText);
  }
 }
}
function showTicker(expose){
	if (msgLines[tickerCounter] > 1){
		if (expose){
			if (isIE)
				document.all.tickerTxtTd.innerText = document.all.tickerText(tickerCounter).innerText;
   	}else{
			if (isIE)
				document.all.tickerTxtTd.innerText = msgTexts[tickerCounter];
		}
	}
}
function getWidth()
{
	if (isIE)
		return document.body.clientWidth;
	else
		return window.innerWidth;
}
function DD(on, id)
{
 if (document.layers)
 {
  if (on)
   navShowSub(on, id);
  else 
   setTimeout("navShowSub(false, "+id+")", 4000);
 }
 else
  ieShowSub(on, id)
}

function navShowSub(on, id)
{
 var offSet = 8;
 var currSubMenu = cCodeArray[id];
 var cWidth = Math.floor(currTWidth/6)
 var tmpCurrSubMenu;
 
 if (currWidth > currTWidth)
 {
 	switch(id)
 	{
 		case 0: currLeft = currWidth/2 - (3 * cWidth + 11);	break;
 		case 1: currLeft = currWidth/2 - (2 * cWidth + 14); break;
	 	case 2: currLeft = currWidth/2 - (cWidth + 17); break;
		 case 3: currLeft = currWidth/2 - 20 ; break;
 		case 4: currLeft = currWidth/2 + (cWidth - 23); break;
	 	case 5: currLeft = currWidth/2 + (2 * cWidth - 25); break;
 	}
 }
 else
 {
 	switch(id)
 	{
 		case 0: currLeft = offSet;break;
 		case 1: currLeft = offSet+cWidth-3;break;
 		case 2: currLeft = offSet+cWidth*2-6;break;
 		case 3: currLeft = offSet+cWidth*3-9;break;
 		case 4: currLeft = offSet+cWidth*4-12;break;
 		case 5: currLeft = offSet+cWidth*5-14;break;
 	}
 }
 if (on)
 {
  document.layers[currSubMenu].top = parseInt(currTop);
  document.layers[currSubMenu].left = parseInt(currLeft);
  for (j=0;j<cCodeArray.length;j++)
  {
   if (j != 5)
   {
    tmpCurrSubMenu = cCodeArray[j];
    if (j == id)
    {
     document.layers[tmpCurrSubMenu].visibility = "show";
    }
    else
    {
     document.layers[tmpCurrSubMenu].visibility = "hide";
    }
   }
  }
 }
 else
 {
  document.layers[currSubMenu].visibility = "hide";
 }
}

function ieShowSub(on, id)
{
 var offSet = 8;

 if (isIE55)
  offSet = 1;
// else
//  offSet = 8;
 var currSubMenu = cCodeArray[id];
 var cWidth = Math.floor(currTWidth/6)
 if (currWidth > currTWidth)
 {
 	switch(id)
 	{
 		case 0: currLeft = currWidth/2 - (3 * cWidth + 2) - offSet;break;
 		case 1: currLeft = currWidth/2 - (2 * cWidth + 5) - offSet;break;
 		case 2: currLeft = currWidth/2 - (cWidth + 8) - offSet;break;
 		case 3: currLeft = currWidth/2 - 11 - offSet ;break;
 		case 4: currLeft = currWidth/2 + (cWidth - 14) - offSet;break;
 		case 5: currLeft = currWidth/2 + (2 * cWidth - 17) - offSet;break;
 	}
 }
 else
 {
  offSet += 10;
 	switch(id)
 	{
 		case 0: currLeft = offSet;break;
 		case 1: currLeft = offSet+cWidth-3;break;
 		case 2: currLeft = offSet+cWidth*2-6;break;
 		case 3: currLeft = offSet+cWidth*3-9;break;
 		case 4: currLeft = offSet+cWidth*4-12;break;
 		case 5: currLeft = offSet+cWidth*5-14;break;
 	}
 }
// alert (currLeft);
 if (on)
 {
  document.all[currSubMenu].style.top = parseInt(currTop);
  document.all[currSubMenu].style.left = parseInt(currLeft);
  document.all[currSubMenu].style.display = "inline";
 }
 else
 {
  document.all[currSubMenu].style.display = "none";
 }
}

/*if (isNav)
{
	window.captureEvents(Event.RESIZE)
	window.onresize = handeleResize
}
else
{
	window.onresize = handeleResize
}

function handeleResize()
{
	location.reload()
	return false
}
*/
function setCCodeArray(id, code)
{
 id = parseInt(id);
 cCodeArray[id] = code;
}

function formHandler(formName, selectName)
{
 if (document.forms[formName][selectName].selectedIndex != 0)
 {
  var URL = document.forms[formName][selectName].options[document.forms[formName][selectName].selectedIndex].value;
  if (isNaN(URL))
  {
   if (URL.indexOf("-") == 4)
   {
    URL = "/hasite/pages/LiArtSR.jhtml?itemNo=" + URL.substring(0,URL.indexOf("-")) + "&specialReportLines=" + URL.substring(URL.indexOf("-")+1, URL.length);
    window.location.href = URL;
   }
   else
    window.open(URL);
  }
  else
  {
   URL = "/hasite/pages/ShArt.jhtml?itemNo=" + URL;
   window.location.href = URL;
  }
 }
}

function checkForm(formName)
{
 if (document.forms[formName].searchWord.value == "")
 {
  alert("לא הוכנס ערך לחיפוש");
  document.forms[formName].searchWord.focus();
  return false;
 }
}

function PopUpWin(mypage, myname, w, h, scroll)
{
<!-- Original:  Eric King (eric_andrew_king@hotmail.com) -->
 var posTop = (screen.width)
 var winl = (screen.width)* 235/1000 ;
  if (posTop > 500)
   var wint =(screen.height) * 22/100;
 else
   var wint =(screen.height) * 40/100;
 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
 win = window.open(mypage, myname, winprops)
 if (parseInt(navigator.appVersion) >= 4)
  {
   win.window.focus();
  }
}

function chkSearch(word)
{
 if (word == "")
  return false;
 else
  return true;
}

function banner(noPosition,lay1, lay2, lay3, time)
{
 var site = "haaretz";
// var size = new Array("","WIDTH=143 HEIGHT=204");
var size = new Array("","WIDTH=468 HEIGHT=60","WIDTH=468 HEIGHT=60","WIDTH=109 HEIGHT=65","WIDTH=109 HEIGHT=65","WIDTH=124 HEIGHT=31","WIDTH=124 HEIGHT=31","WIDTH=124 HEIGHT=150","WIDTH=124 HEIGHT=150","WIDTH=80 HEIGHT=31","WIDTH=124 HEIGHT=150","WIDTH=109 HEIGHT=100","WIDTH=420 HEIGHT=108","WIDTH=420 HEIGHT=108","WIDTH=124 HEIGHT=450","","WIDTH=124 HEIGHT=31","WIDTH=124 HEIGHT=180","WIDTH=210 HEIGHT=210");

var posSrcs = new Array(" ","adsize=468x60","adsize=468x60","adsize=109x65","adsize=109x65","adsize=124x31","adsize=124x31","adsize=124x150","adsize=124x150","adsize=80x31","adsize=124x150","adsize=109x100","adsize=420x108","adsize=420x108","adsize=124x450","","adsize=124x31","adsize=124x180","adsize=210x210");

// var posSrcs = new Array(" ","adsize=143X204");
 var now = new Date();
 var RND = now.getSeconds();
 //alert("noPosition-"+noPosition+"-l1-"+lay1+"-l2-"+lay2+"-l3-"+lay3);
 document.write('<IFRAME ' + size[noPosition] + ' MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no BORDERCOLOR=000000 SRC="http://dclk.themarker.com/html.ng/site=' + site + '&' + posSrcs[noPosition] + '&' + (lay1=="none"?'':'hlayer1='+lay1+'&') + (lay2=="none"?'':'hlayer2='+lay2+'&')+ (lay3=="none"?'':'hlayer3='+lay3+'&')+'hposition=' + noPosition + '&Rnd=' + RND +'"></IFRAME>');
}
