﻿
var domain = 'http://edition.presstv.ir/';

function $(element) { return document.getElementById(element); };
function $S(element) { return document.getElementById(element).style; };

var dd = new Date();
var ddd = dd.getDate() + '' + dd.getHours() + '' + dd.getMinutes() + '' + dd.getSeconds();

function setCookie(c_name, value, expiredays) {var exdate = new Date();exdate.setDate(exdate.getDate() + expiredays);document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());}

var i2 = new Image(1, 1);var r = document.referrer.replace(/html/g, 'htm');i2.src = domain + 'stat/?ddd=' + ddd + '&r=' ;i2.onload = function () { return; };

var cb_tab_list = new Array('', 'divMediaTab', 'divLatestTab', 'divMediaTab', '', '', 'divLatestTab', 'divMediaTab');
var cb_list = new Array('divMainBody', 'divMediaContent', 'divLatestCont', 'divMediaCont', 'divSectionLatest', 'divSectionLatest', 'divLatestCont', 'divMediaContent');
var store = new Array;
for (i = 0; i < cb_list.length; i++) store[i] = new Array(5);
var mainCurr = 0;
function a0(no) {var divMainHeadlines = $('divMainHeadlines');var divs = divMainHeadlines.getElementsByTagName('li');for (i = 0; i < divs.length; i++)divs[i].className = '';divs[no].className = 'sel';$('divMainBody').innerHTML = main[no];mainCurr = no;}
function a(p, no, s) {var divTab = $(cb_tab_list[p]);if (divTab != null) {var lis = divTab.getElementsByTagName('li');if (no < lis.length) {for (i = 0; i < lis.length; i++)lis[i].className = '';lis[no].className = 'sel';}}setTimeout('getD(' + p + ', ' + no + ', ' + s + ')', 500);}
function querySt(loc, ji) {hu = loc.search.substring(1);gy = hu.split("&");for (i = 0; i < gy.length; i++) {ft = gy[i].split("=");if (ft[0] == ji) {return ft[1];}}}

_w = window;_d = document;_de = _d.documentElement;_ie = !!_w.ActiveXObject;_i6 = _ie && !_w.XMLHttpRequest;
function _gx() { return _i6 ? new ActiveXObject("MSXML2.XMLHTTP") : new XMLHttpRequest }
function populateW(p, no, t) {var tt = t;if (store[p][no] == null)store[p][no] = t;else tt = store[p][no];tt = tt.replace(/href='/g, "href='" + $('root').value);if(tt.length > 20)$(cb_list[p]).innerHTML = tt;}
function getD(p, no, s) { if (store[p][no] != null) { populateW(p, no, ''); return; } if (s == null) s = 0; var d = _gx(); if (!d) return; d.open("get", $('root').value + "callback/?no=" + no + "&s=" + s + "&p=" + p, true); d.onreadystatechange = function () { if (d.readyState == 4) { populateW(p, no, d.responseText); } }; $(cb_list[p]).innerHTML = '<img style="float:left; margin-right:2px; margin-top:-2px" src="' + $('root').value + 'images/loading.gif" />'; d.send(null); }
function getC(news_id, start, count) {var kkk = news_id + ''; kkk = kkk.replace('.html', ''); kkk = kkk.slice(kkk.lastIndexOf("/") + 1);var script = document.createElement('script');script.setAttribute('src', domain + 'callback/comment/?ddd=' + ddd + '&news_id=' + kkk + '&start=' + start + '&count=' + count);script.onreadystatechange = function () {if (script.readyState == 'loaded' || script.readyState == 'complete')populateC();};script.onload = function () {script.readyState = 'loaded';script.onreadystatechange();};document.getElementsByTagName('head')[0].appendChild(script);$('divC').innerHTML = '<img style="float:left; margin-right:2px; margin-top:-2px" src="' + $('root').value + 'images/loading.gif" /> Loading ...'; }
function populateC(t) {}
function getDoc() {var d = _gx();if (!d) return;d.open("get", $('root').value + "callback/doc/?ddd=" + ddd, true);d.onreadystatechange = function () {if (d.readyState == 4) {populateDoc(d.responseText);}};d.send(null);}
function populateDoc(t) { $('divSubMenu2').innerHTML = t; }
function getSch(dd, t, dst) {var script = document.createElement('script');script.setAttribute('src', domain + 'callback/sch/?ddd=' + ddd + '&d=' + dd + '&t=' + t + '&dst=' + dst);script.onreadystatechange = function () {if (script.readyState == 'loaded' || script.readyState == 'complete')populateSch();};script.onload = function () {script.readyState = 'loaded';script.onreadystatechange();};document.getElementsByTagName('head')[0].appendChild(script);$('divSch').innerHTML = '<div style="height:200px"><img style="float:left; margin-right:2px; margin-top:-2px" src="images/loading.gif" /></div>';}
function populateSch() {}
function getProg() {var d = _gx();if (!d) return;d.open("get", $('root').value + "callback/Prog/?ddd=" + ddd, true);d.onreadystatechange = function () {if (d.readyState == 4) {populateProg(d.responseText);}};d.send(null);}
function populateProg(t) {var tt = t + '';tt = tt.replace(/href='/g, "href='" + $('root').value);$('divSubMenu1').innerHTML = tt;}
//////////////////////////////////////////////////////////////////////////////////////////////
var tickerCont = null; var tickerCurr = 0;
function playTicker() {if (tickerCont == null)tickerCont = document.getElementById('spnTickerCont');if (ticker.length == 0) return;if (tickerCurr >= ticker.length) tickerCurr = 0;if (document.all) tickerCont.innerText = ''; else tickerCont.textContent = '';s = 0;animateTicker(ticker[tickerCurr++]);}
function animateTicker(c) {if (c == '') return;if (document.all)tickerCont.innerText += c.substring(s, s + 1);else tickerCont.textContent += c.substring(s, s + 1);if (++s < c.length)setTimeout("animateTicker('" + c + "')", 10);}
/////////////////////////////////////////////////////////////////////////////////////////////////////
var currMenu = -1;
function m0(no, s) {if (currMenu == -1) {for (i = 0; i < 3; i++) {if ($('liM' + no).className == 'sel') {currMenu = i;break;}}}$('divSubMenu').style.display = s == 0 ? 'none' : 'block';$('divSubMenu' + no).style.display = s == 0 ? 'none' : 'block';if (no == currMenu) $('liM' + no).className = s == 0 ? 'sel' : 'sel1'; else $('liM' + no).className = s == 0 ? '' : 'sel1';}
function SectionAllNews() {var s = $S('divAllNews');$('divViewAll').className = s.display == 'none' || s.display == '' ? 'viewAllMinus' : 'viewAllPlus';$('divViewAll').innerHTML = s.display == 'none' || s.display == '' ? 'Hide' : 'View All';s.display = s.display == 'none' || s.display == '' ? 'block' : 'none';}
/////////////////////////////////////////////////////////////////////////////////////////////////////
var TimeToFade = 100.0;
function fade(eid) {var element = document.getElementById(eid);if (element == null)return;if (element.FadeState == null) {if (element.style.opacity == null || element.style.opacity == '' || element.style.opacity == '1') {element.FadeState = 2;}else {element.FadeState = -2;}}if (element.FadeState == 1 || element.FadeState == -1) {element.FadeState = element.FadeState == 1 ? -1 : 1;element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;}else {element.FadeState = element.FadeState == 2 ? -1 : 1;element.FadeTimeLeft = TimeToFade;setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);}}
function animateFade(lastTick, eid) {var curTick = new Date().getTime();var elapsedTicks = curTick - lastTick;var element = document.getElementById(eid);if (element.FadeTimeLeft <= elapsedTicks) {element.style.opacity = element.FadeState == 1 ? '1' : '0';element.style.filter = 'alpha(opacity = '+ (element.FadeState == 1 ? '100' : '0') + ')';element.FadeState = element.FadeState == 1 ? 2 : -2;return;}element.FadeTimeLeft -= elapsedTicks;var newOpVal = element.FadeTimeLeft / TimeToFade;if (element.FadeState == 1)newOpVal = 1 - newOpVal;element.style.opacity = newOpVal;element.style.filter = 'alpha(opacity = ' + (newOpVal * 100) + ')';setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);}
///////////////////////////////////////////////////////////////////////////////////////////////////
function map(id) {$('divNewsSubMenuMap').getElementsByTagName('img')[0].src = (id > 3510207 && id != 3510218) ? $('root').value + 'images/menumaps/1.gif' : $('root').value + 'images/menumaps/' + id + '.gif';var name = '';switch (id) {case 3510201:name = 'Iran';break;case 3510202:name = 'Middle East';break;case 3510203:name = 'United States';break;case 3510218:name = 'Britain';break;case 3510204:name = 'Asia-Pacific';break;case 3510205:name = 'Africa';break;case 3510206:name = 'Europe';break;case 3510207:name = 'Americas';break;case 3510208:name = 'Tech';break;case 3510219:name = 'Arts';break;case 3510210:name = 'Health';break;case 3510211:name = 'Sport';break;case 3510212:name = 'Society';break;case 3510213:name = 'Business';break;}$('divNewsSubMenuText').innerHTML = name;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function pausescroller(content, divId, delay) {this.content = content;this.tickerid = divId;this.delay = delay;this.mouseoverBol = 0;this.hiddendivpointer = 1;var scrollerinstance = this;scrollerinstance.initialize();}
pausescroller.prototype.initialize = function () {this.tickerdiv = document.getElementById(this.tickerid); this.visiblediv = document.getElementById(this.tickerid + "1"); this.hiddendiv = document.getElementById(this.tickerid + "2"); this.visibledivtop = parseInt(pausescroller.getCSSpadding(this.tickerdiv)); this.visiblediv.style.width = this.hiddendiv.style.width = this.tickerdiv.offsetWidth - (this.visibledivtop * 2) + "px"; this.getinline(this.visiblediv, this.hiddendiv); this.hiddendiv.style.visibility = "visible"; var scrollerinstance = this; document.getElementById(this.tickerid).onmouseover = function () { scrollerinstance.mouseoverBol = 1 }; document.getElementById(this.tickerid).onmouseout = function () { scrollerinstance.mouseoverBol = 0 };if (window.attachEvent) window.attachEvent("onunload", function () { scrollerinstance.tickerdiv.onmouseover = scrollerinstance.tickerdiv.onmouseout = null });setTimeout(function () { scrollerinstance.animateup() }, this.delay);}
pausescroller.prototype.animateup = function () {var scrollerinstance = this;if (parseInt(this.hiddendiv.style.top) > (this.visibledivtop + 5)) {this.visiblediv.style.top = parseInt(this.visiblediv.style.top) - 5 + "px";this.hiddendiv.style.top = parseInt(this.hiddendiv.style.top) - 5 + "px";setTimeout(function () { scrollerinstance.animateup() }, 50)}else {this.getinline(this.hiddendiv, this.visiblediv);this.swapdivs();setTimeout(function () { scrollerinstance.setmessage() }, this.delay);}}
pausescroller.prototype.swapdivs = function () {var tempcontainer = this.visiblediv;this.visiblediv = this.hiddendiv;this.hiddendiv = tempcontainer;}
pausescroller.prototype.getinline = function (div1, div2) {div1.style.top = this.visibledivtop + "px";div2.style.top = Math.max(div1.parentNode.offsetHeight, div1.offsetHeight) + "px";}
pausescroller.prototype.setmessage = function () {var scrollerinstance = this; if (this.mouseoverBol == 1) setTimeout(function () { scrollerinstance.setmessage() }, 100); else { var i = this.hiddendivpointer; var ceiling = this.content.length; this.hiddendivpointer = (i + 1 > ceiling - 1) ? 0 : i + 1; this.hiddendiv.innerHTML = this.content[this.hiddendivpointer]; this.animateup(); }}
pausescroller.getCSSpadding = function (tickerobj) {if (tickerobj.currentStyle)return tickerobj.currentStyle["paddingTop"];else if (window.getComputedStyle)return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top");else return 0;}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function goSearch(frm) {if ($('txtSearch').value != '') {if (!VerifySearchQ($('txtSearch').value)) { alert("Invalid search query."); }else {var strSearchLoc = domain + 'search.html?';strSearchLoc += 'q=' + leftTrim($('txtSearch').value);location.href = strSearchLoc;}}return false;}
function goV(v_id) {var opinions = $('divOptions').getElementsByTagName('input');var res = -1;for (i = 0; i < opinions.length; i++) {if (opinions[i].checked == true) { res = i; break; }}if (res == -1) { return; }var script = document.createElement('script');script.setAttribute('src', domain + 'Vote/?v_id=' + v_id + '&res=' + res + '&ddd=' + ddd);script.onreadystatechange = function () {if (script.readyState == 'loaded' || script.readyState == 'complete')populateV();};script.onload = function () {script.readyState = 'loaded';script.onreadystatechange();};document.getElementsByTagName('head')[0].appendChild(script);$S('divOptions').backgroundColor = '#c2c2c2'; }
function populateV(t) {}
function goSearch_FA(frm) {if ($('txtSearch').value != '') {if (!VerifySearchQ($('txtSearch').value)) { alert("Invalid search query."); }else {var strSearchLoc = 'search.fa.aspx?';strSearchLoc += 'q=' + leftTrim($('txtSearch').value);location.href = strSearchLoc;}}return false;}
function VerifySearchQ(srchTerm) {var htmlRegEx = new RegExp('[\w*|\W*]*<[[\w*|\W*]*|/[\w*|\W*]]>[\w*|\W*]*');if (htmlRegEx.exec(srchTerm) || (srchTerm == null) || (leftTrim(srchTerm).length == 0) || (srchTerm.indexOf(">") >= 0) || (srchTerm.indexOf(";") >= 0)) {return false;}else return true;}
function leftTrim(sString) {while (sString.substring(0, 1) == ' ') {sString = sString.substring(1, sString.length);}return sString;}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
