function toggleZip() {
    var zipForm = document.getElementById('zipForm');
    zipForm.style.display = (zipForm.style.display != 'none' ? 'none' : '' );
    document.getElementById('zipField').select();
}
function clearSearch() {
    //if (document.getElementById('search_term').value == "Web search powered by YAHOO!") {
    if (document.getElementById('search_term').value == "Search for articles") {
        document.getElementById('search_term').value = "";
    }
}
function clearStats() {
s.pageName=""
s.channel=""
s.prop2=""
s.prop5=""
s.prop7=""
s.prop12=""
s.prop13=""
s.prop15=""
s.prop18=""
s.prop32=""
s.prop23=""
s.prop24=""
s.prop25=""
s.prop26=""
s.prop27=""
s.prop28=""
s.eVar1=""
s.hier1=""
}
function tulsaLink(author) {
    s.prop10=author + " - Tulsa World"
    s.tl();
}
function showAnimated() {
    if (document.getElementById('animatedRadar').innerHTML == "") {
        document.getElementById('animatedRadar').innerHTML = "<a href='/weather' onmouseout='hideAnimated();'><img class='radarAnimate' src='http://static.newsok.biz/sites/weather/images/thumb/radstok_animated.gif' border='0' /></a>";
    } else {
        var animated = document.getElementById('animatedRadar');
        animated.style.display = (animated.style.display != 'none' ? 'none' : '' );
    }
}
function hideAnimated() {
    var animated = document.getElementById('animatedRadar');
    animated.style.display = (animated.style.display != 'none' ? 'none' : '' );
}
function processWWWArticleData (data) {
        //function requires global variable itemTypes
        //var itemTypes = [ "articles", "blogs", "video", "audio"];
        for (var j = 0; j < itemTypes.length; j++) {
                var listWrapperEl = document.getElementById('inform_www_'+itemTypes[j]);
                var articleList = data[itemTypes[j]];
                                
                /* for each element in the collection, create a new list item */                                
                articleCount = 0;
                for (var i = 0; i < articleList.length; i++) {
                        if (articleList[i].publication != 'Oklahoman') {
                        if (articleCount < 2) {
                                    var itemEl = document.createElement("li");
                                    var newDate = articleList[i].date.substring(0,articleList[i].date.length - 11);
                                    itemEl.innerHTML = "<a target='_blank' href=\"" + articleList[i].url + "\"><b>" + articleList[i].title + "</b></a><br/>" + "<em>" + articleList[i].publication + " | " + newDate + "</em><br/>" + articleList[i].blurb;
                                    listWrapperEl.appendChild(itemEl);
                                    articleCount++;
                            };
                        };
                };
                                
                /* update the list's class to reflect the current state */
                listWrapperEl.className = articleCount ? "" : "empty";
        };
};
function toggleAction(type) {
	/* This will be uncommented when the new search goes live
    document.getElementById('srch_newsok').className = "";
    document.getElementById('srch_wimgo').className = "";
    document.getElementById('srch_yahoo').className = "";
    document.getElementById('srch_'+type).className = "selected";
	*/
    if (type == 'newsok') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    } else if (type == 'articles') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_what').name = "newsok"
        document.getElementById('content_nav').value = "contenttypenavigator|Articles"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    } else if (type == 'blog') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_what').name = "newsok"
        document.getElementById('content_nav').value = "contenttypenavigator|Blog"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    } else if (type == 'photos') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_what').name = "newsok"
        document.getElementById('content_nav').value = "contenttypenavigator|Photos"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    } else if (type == 'videos') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_what').name = "newsok"
        document.getElementById('content_nav').value = "contenttypenavigator|Video"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    } else if (type == 'wimgo') {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_form').action = "http://www.wimgo.com/events/search/";
    } else {
        document.getElementById('search_term').name = "search"
        document.getElementById('search_form').action = "http://newsok.com/search/";
    }
}
function toggleObject(id) {
    var el = document.getElementById('objectionReason_'+id);
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
}
function clearReason(id) {
    if (document.getElementById('reason_'+id).value == "Please tell us what is objectionable.") {
        document.getElementById('reason_'+id).value = "";
    }
}
function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.innerHTML = limitNum - limitField.value.length;
    }
}

function loadConnectokJSON(url, queryString, type)
{
        var headId = document.getElementsByTagName("head")[0];
        if (typeof(type) == "undefined") type = 'script';


        url += (url.indexOf('?') >= 0) ? "&" : "?";
        url += "noCacheIE=" + (new Date()).getTime() + "&" + queryString;

        if (type == 'link') {
            var link = document.createElement('link');
            link.rel = 'alternate';
            link.type = 'application/rss+xml';
            link.href = url;
        } else {
            var link = document.createElement('script');
            link.type = 'text/javascript';
            link.src = url;
        }
        headId.appendChild(link);
}

function connectokMakeObjection(c_id, reason, e_id)
    {
        var c_id = c_id;
        if(e_id.length == 0){
            alert('You must be logged in to make an objection');
            return;
        }
        //url = apiUrl+"json";
        url = "http://api.connectok.com/json";
        queryString  = "method=Objection.MakeObjection";
        queryString += "&callBack=connectokObjectionMade";
        queryString += "&uid="      + "Comment_" + c_id;
        queryString += "&e_id="      + encodeURIComponent(e_id);
        queryString += "&reason="   + encodeURIComponent(reason);
        loadConnectokJSON(url,queryString,'script');
    }
function connectokObjectionMade(data)
{
        document.getElementById(data.result.uid+'_object').innerHTML = "<span style='color: #A02C2C;'><b>Your objection has been sent.</b></span>";
}   

function addLoadEvent(func) {    
    var oldonload = window.onload;  
    if (typeof window.onload != 'function') {  
      window.onload = func;  
    } else {  
      window.onload = function() {  
        if (oldonload) {  
          oldonload();  
        }  
        func();  
      }  
    }  
}
function toggleID(id) {
    var object = document.getElementById(id);
    object.style.display = (object.style.display != 'none' ? 'none' : '' );
}
function clearUser() {
    document.getElementById('usernameInput').value = '';
}
function clearPass() {
    document.getElementById('passwordInput').style.background = '#FFF';
}
function showLogin() {
    document.getElementById('loginForm').style.display = 'block';
    document.getElementById('joinUs').style.display = 'none';
}

function swapBars(holder, bar){
    var url = '/ajax/bar.php';
    var params = 'bar='+bar;
    new Ajax.Updater(holder, url, {parameters: params, asynchronous:true});
}
function checkFeedbackForm() {
  if (document.getElementById('msg').value != "" && document.getElementById('email').value != "") {
    document.getElementById('response').innerHTML = "Thank you for your question.";
    return true;
  } else {
    document.getElementById('response').innerHTML = "Please fill in both the email and message fields above.";
    return false;
  }
}

/****   Email Article to a Friend Code   ******/

function invite_friend(tf_url){
    var email = document.getElementById('tf_email').value;
    var your_email = document.getElementById('tf_your_email').value;
    var message = document.getElementById('tf_message').value;
    var url = "/ajax/okla365/invite_friend.php?from="+your_email+"&email="+email+"&message="+message+"&url="+tf_url; // Ryan need you help on this line
    new Ajax.Request(url, { method:'get', onSuccess: function(transport) { doJSON(transport); }}); // Ryan need you help on this line too
}
function invited_friends(data){
    if(data.success == 1){
        document.getElementById('tf_msg').innerHTML = "Your email has been sent.";
    }else{
        document.getElementById('tf_msg').innerHTML = "A problem was encoutered sending email.";
    }
}
function togglePrint() {
    document.getElementById('emailFriend').style.display = '';
}
var jsonUrl = 'http://api.connectok.com/json';
function getWidgetGalleryList(id, currentPage, sections, limit, numPerPage)
{
   
   var qString = 'callBack=displayWidgetGalleryList&divId=galleryList&method=Widget.getWidget&widgetTypeId=19&id='+id+'&widgetcurrentPage='+currentPage+'&sections='+escape(sections)+'&limit='+escape(limit)+'&numPerPage='+escape(numPerPage);
    loadJSON(jsonUrl, qString);
}
function displayWidgetGalleryList(res)
{
   document.getElementById(res.divId).innerHTML = res.html;
}
function photoPages(current, next) {
   document.getElementById(current).style.display = "none";
   document.getElementById(next).style.display = "block";
}

function shareWithFriend() {
    if (document.getElementById('emailMessage').value == "Add your message here (optional)") {
        document.getElementById('emailMessage').value = "";
    }
    var validateShareEmail = new Boolean(social.shareVideoViaEmail(document.getElementById('yourEmail').value, document.getElementById('friendsEmail').value, document.getElementById('emailMessage').value));
    if (validateShareEmail == true) {
        document.getElementById('emailMsg').innerHTML = "<b>Your message has been sent.</b><br /><br />"
    } else {
        document.getElementById('emailMsg').innerHTML = "<b>Oops, something went wrong.</b> Please verify that <b>your email</b> and <b>your friends email</b> is properly keyed in. Then try again.<br /><br />"
    }
}

function clearInputField(id, value) {
    if (value == document.getElementById(id).value) {
        document.getElementById(id).value = "";
    } else {
        document.getElementById(id).select();
    }
}
var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {
            string: navigator.userAgent,
            subString: "Chrome",
            identity: "Chrome"
        },
        {   string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari",
            versionSearch: "Version"
        },
        {
            prop: window.opera,
            identity: "Opera"
        },
        {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        },
        {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        },
        {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        },
        {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        },
        {       // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        },
        {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
        },
        {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        },
        {       // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        },
        {
               string: navigator.userAgent,
               subString: "iPhone",
               identity: "iPhone/iPod"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }
    ]

};
BrowserDetect.init();
function DHTMLSound(surl) {
    document.getElementById("yspan").innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
function ajaxBlk(id, blk) {
    jQuery("#"+id).load("/block/"+blk);
}
function loadWidget(id, blk) {
    jQuery("#"+id).load("/widget?widgetId="+blk);
}
function timelineHTML(div, content) {
    document.getElementById(div).innerHTML = unescape(content);
}

function embedVideo(autoPlay, id) {
    embedVideo = '';
    embedVideo += '<object id="myExperience" class="BrightcoveExperience">';
    embedVideo += '  <param name="bgcolor" value="#FFFFFF" />';
    embedVideo += '  <param name="width" value="620" />';
    embedVideo += '  <param name="height" value="398" />';
    embedVideo += '  <param name="playerID" value="4659235001" />';
    embedVideo += '  <param name="publisherID" value="713285227"/>';
    embedVideo += '  <param name="dynamicStreaming" value="true"/>';
    embedVideo += '  <param name="isVid" value="true" />';
    if (autoPlay == "false") {
    embedVideo += '  <param name="autoStart" value="false" />';
    }
    embedVideo += '  <param name="@videoPlayer" value="'+id+'" />';
    embedVideo += '</object>';
    document.getElementById('bc_inline_player').innerHTML = embedVideo;
}

function autoStart(boo, id) {
    embedVideo(boo, id);
}
currentPageIndex = 0;
function movePage(dir) {
    limit = jQuery('.okpage').size();
    if (dir == "left") {
        if (limit > currentPageIndex+1) {
            jQuery('#leftArrow').addClass('on');
            jQuery('#frontPages').animate({
                left: "-=238px"
            }, 1000 );
            currentPageIndex++;
            if (limit == currentPageIndex+1) {
                jQuery('#rightArrow').removeClass('on');
            }
        }
    }
    if (dir == "right") {
        if (currentPageIndex > 0) {
            jQuery('#rightArrow').addClass('on');
            jQuery('#frontPages').animate({
                left: "+=238px"
            }, 1000 );
            currentPageIndex--;
            if (currentPageIndex == 0) {
                jQuery('#leftArrow').removeClass('on');
            }
        }
    }
}
var jsonURL = "http://api.connectok.com/json/";
function emailThis(url){
    to = "";
    if (document.getElementById('emailThisTo').value) {
        to     = document.getElementById('emailThisTo').value;
    }
    if (document.getElementById('emailThisTo_2').value) {
        to     += "," + document.getElementById('emailThisTo_2').value;
    }
    if (document.getElementById('emailThisTo_3').value) {
        to     += "," + document.getElementById('emailThisTo_3').value;
    }
    if (document.getElementById('emailThisTo_4').value) {
        to     += "," + document.getElementById('emailThisTo_4').value;
    }
    if (document.getElementById('emailThisTo_5').value) {
        to     += "," + document.getElementById('emailThisTo_5').value;
    }
    if (jQuery('#emailmetoo').attr('checked')) {
        if (to == "") {
            to     += document.getElementById('emailThisFrom').value;
        } else {
            to     += "," + document.getElementById('emailThisFrom').value;
        }
    }
    from            = document.getElementById('emailThisFrom').value;
    name            = document.getElementById('emailThisFromName').value;
    msg             = document.getElementById('emailThisMsg').value;
    subject         = document.getElementById('emailSubject').value;
    moduleid        = document.getElementById('moduleId').value;
    moduletypeid    = document.getElementById('moduleTypeId').value;

    if (to == "" || from == "") {
        alert("Make sure you provide your email address and at least one email address of a friend");
        return false;
    }

    qString = "callBack=emailSent&method=EmailThis.Send&name="+name+"&moduleId="+moduleid+"&moduleTypeId="+moduletypeid+"&subject="+encodeURI(subject)+"&to="+encodeURI(to)+"&from="+encodeURI(from)+"&msg="+encodeURI(msg)+"&url="+encodeURI(url);
    loadJSON(jsonURL, qString, 'script');
}
function emailSent(data)
{
    if(data.success == 1){
        document.getElementById('formContainer').style.display = "none";
        document.getElementById('emailThisTo').value = "";
        document.getElementById('emailThisTo_2').value = "";
        document.getElementById('emailThisTo_3').value = "";
        document.getElementById('emailThisTo_4').value = "";
        document.getElementById('emailThisTo_5').value = "";
        document.getElementById('otherHeadlines').style.display = "block";
    }else{
        document.getElementById('emailThisResponse').innerHTML = data.result.message;
    }
}

