﻿function $(element) { return document.getElementById(element); }
function $S(element) { return document.getElementById(element).style; }
var a_crawl = $('a_crawl');
var s = 0;
var mainCurr = 0;
var l;
var crawlCurr = 0;
var lastMainPlace;
var mainOther = new Array(0, 1, 2, 3, 4, 5);
setInterval('playCrawl()', 10000);
playCrawl();
function aa(indx) {
    //alert(indx);
    for (i = 0; i < 15; i++) {
        document.getElementById('divLatestWraper' + i).className = 'ord';
        document.getElementById('divLatestDesc' + i).className = 'f_desc hid';
    }
    document.getElementById('divLatestWraper' + indx).className = 'ord sel';
    document.getElementById('divLatestDesc' + indx).className = 'f_desc';
}
function bb(indx) {
    for (i = 0; i < 10; i++) {
        document.getElementById('divMPWraper' + i).className = 'ord';
        document.getElementById('divMPDesc' + i).className = 'f_desc hid';
    }
    document.getElementById('divMPWraper' + indx).className = 'ord sel';
    document.getElementById('divMPDesc' + indx).className = 'f_desc';
}
function cc(indx) {
    if (lastMainPlace != indx) {
        for (i = 0; i < 8; i++) {
            document.getElementById('divMain' + i).style.display = 'none';
            document.getElementById('divMainTitle' + i).className = '';
        }
        document.getElementById('divMain' + indx).style.display = 'inline';
        document.getElementById('divMainTitle' + indx).className = 'sel';
        
        lastMainPlace = indx;
    }
}
function dd(indx) {
    for (i = 0; i < 6; i++) {
        document.getElementById('divSubMenu' + i).style.display = 'none';
        document.getElementById('liMenu' + i).style.backgroundColor = '';
        document.getElementById('liMenu' + i).childNodes[0].style.color = '#1a1a1a';
    }
    document.getElementById('divSubMenu' + indx).style.display = 'block';
    document.getElementById('liMenu' + indx).style.backgroundColor = '#a7a9ac';
    document.getElementById('liMenu' + indx).childNodes[0].style.color = 'white';
}
function ee(indx) {
    document.getElementById('divRightPaneHeadtab0').className = 'rightPaneHeadtab';
    document.getElementById('divRightPaneHeadtab1').className = 'rightPaneHeadtab';
    document.getElementById('divRightPaneHeadtab' + indx).className = 'rightPaneHeadtab sel';
    if (indx == 0) {
        document.getElementById('divVideoContent').style.display = 'block';
        document.getElementById('divPhotoContent').style.display = 'none';
    }
    else if (indx == 1) {
        document.getElementById('divVideoContent').style.display = 'none';
        document.getElementById('divPhotoContent').style.display = 'block';
    }
}


function playCrawl() {
    if (crawl.length == 0)
        return;
    if (crawlCurr >= crawl.length)
        crawlCurr = 0;
    //document.getElementById('divCrawlContetnt').innerHTML = crawl[crawlCurr];
    if (document.all)
        a_crawl.innerText = '';
    else
        a_crawl.textContent = '';
    s = 0;
    a_crawl.setAttribute('href', crawl_link[crawlCurr]);
    animateCrawl(crawl[crawlCurr]);
    crawlCurr++;
}
function animateCrawl(c) {
    //document.getElementById('divCrawlContetnt').innerHTML = c;
    if (c == '')
        return;
    if (document.all)
        a_crawl.innerText += c.substring(s, s + 1);
    else
        a_crawl.textContent += c.substring(s, s + 1);

    s++;
    l = c.length;
    if (s < l)
        setTimeout("animateCrawl('" + c + "')", 10);
}
function getVoteResult() {
    $S('divQVoteRes').backgroundColor = '#d9e9f6';
    _value = 'vote;';
    Go_Server();
}
function setVote() {
    $S('divQVoteRes').backgroundColor = '#ccc';
    var i = 0;
    var selectedIndex = -1;
    while ($('rdoVote_' + i) != null) {
        if ($('rdoVote_' + i).checked) {
            selectedIndex = i;
            break;
        }
        i++;
    }
    if (selectedIndex == -1)
        _value = 'vote;';
    else
        _value = 'vote;' + selectedIndex;
    Go_Server();
}
var _value;
function ShowResult(val) {
    if (_value.indexOf('vote;') == 0) {
        $S('divQVoteRes').backgroundColor = 'white';
        $('divQVoteRes').innerHTML = val;
    }
}

function changeMP(indx) {
    switch (indx) {
        case 1:
            $('mp1').className = 'sel';
            $('mp7').className = 'mid';
            $('mp30').className = '';
            $('divMP7').style.display = $('divMP30').style.display = 'none';
            $('divMP1').style.display = 'block';
            break;
        case 7:
            $('mp1').className = '';
            $('mp7').className = 'sel mid';
            $('mp30').className = '';
            $('divMP1').style.display = $('divMP30').style.display = 'none';
            $('divMP7').style.display = 'block';
            break;
        case 30:
            $('mp1').className = '';
            $('mp7').className = 'mid';
            $('mp30').className = 'sel';
            $('divMP1').style.display = $('divMP7').style.display = 'none';
            $('divMP30').style.display = 'block';
            break;
    }
}

function goSearch(frm) {
    if ($('txtSearch').value != '') {
        if (!VerifySearchQ($('txtSearch').value)) { alert("Invalid search query."); }
        else {
            var strSearchLoc = 'search.aspx?';
            strSearchLoc += 'q=' + leftTrim($('txtSearch').value);
            if (location.href.indexOf('persian.aspx') != -1)
                strSearchLoc += '&lan=fa'; 
            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;
}
function changeSpotlight(n) {
    for (i = 1; i < 4; i++) {
        document.getElementById('divSpotlightContent' + i).style.display = 'none';
        document.getElementById('liSpotlight' + i).className = 'none';
        if(i==2)
            document.getElementById('liSpotlight' + i).className = 'mid';
    }
    document.getElementById('divSpotlightContent' + n).style.display = 'block';
    document.getElementById('liSpotlight' + n).className = 'sel';
    if (n == 2)
        document.getElementById('liSpotlight' + n).className = 'mid sel';
}
function changeOnTheGo(n) {
    for (i = 1; i < 4; i++) {
        document.getElementById('divOnTheGoContent' + i).style.display = 'none';
        document.getElementById('liOnTheGoHead' + i).className = 'none';
        if (i == 2)
            document.getElementById('liOnTheGoHead' + i).className = 'mid';
    }
    document.getElementById('divOnTheGoContent' + n).style.display = 'block';
    document.getElementById('liOnTheGoHead' + n).className = 'sel';
    if (n == 2)
        document.getElementById('liOnTheGoHead' + n).className = 'mid sel';
}
function feedback() {
    window.open("pop/feedback", "feedback", "status=no,scrollbars=no,resizable=no,width=420,height=300", "");
}

var divPhotoContent = document.getElementById('divPhotoContent');
if (divPhotoContent != null) {
    var aa = divPhotoContent.getElementsByTagName('a');
    for (i = 0; i < aa.length; i++) {
        aa[i].setAttribute("href", "photolog.aspx?indx=" + i);
    }
}
var spnDocs = document.getElementById('spnDocs');
if (spnDocs != null) {
    var sd = spnDocs.getElementsByTagName('div');
    sd[3].innerHTML = '';
}