/* global script for mmod.ncaa.com */

/* GET BROWSER DETECTION FROM YUI? */
var IE = (document.all) ? 1 : 0;
var DOM = (document.getElementById) ? 1 : 0;
var MAC = ((navigator.appVersion.indexOf("PPC") >0) || (navigator.appVersion.indexOf("Mac") >0)) ? 1 : 0;
var ua = navigator.userAgent;
var OPERA = (ua.indexOf("Opera") > 0) ? 1 : 0;

/* Cookie functions */
function readCookie(name) {
    if(document.cookie == '') { 
    return false; 
    } else { 
    var firstChar, lastChar;
    var theBigCookie = document.cookie;
    name = name + '=';
    firstChar = theBigCookie.indexOf(name);	
    if (firstChar != -1) {
        firstChar += name.length;
        lastChar = theBigCookie.indexOf(';', firstChar); 
        if(lastChar == -1) lastChar = theBigCookie.length;
        return unescape(theBigCookie.substring(firstChar, lastChar));
    } else {return false;}
    }
} 

function setCookie (name, value, expires) {
    if (!expires) expires = new Date();
    document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() +";domain=.ncaasport.com; path=/";
}

//AJAX
function getHTTPObject() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }

    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
                xmlhttp = new XMLHttpRequest();
        } catch (e) {
                xmlhttp = false;
        }
    }
    return xmlhttp;
}

function shareLinks(){};
    shareLinks.prototype.allowClose = false;
    shareLinks.prototype.showButtons = function() {
        this.allowClose=false;
        document.getElementById('shareBoxi').style.visibility="visible";
    }
    shareLinks.prototype.shareOff = function() {
        if (this.allowClose==true) {
         document.getElementById('shareBoxi').style.visibility="hidden";
        }
    }
    shareLinks.prototype.hideButtons = function() {
        this.allowClose=true;
        setTimeout("shareLinks.prototype.shareOff()",1000);
    }

/* LPS */
function externalWrite( string ) {
    document.write( string );
}

/* Form:select text*/
function selectFormText(inElement) {
    var textVal=document.getElementById(inElement);
    textVal.focus();
    textVal.select();
    return;
}

//Generic popup 
function openPopup(url,name,width,height) {
	popupWin = window.open(url, name, 'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,width=' +width +',height=' +height +',left=50,top=50');
}

//Splash page: Facebook link to open 2 windows
function open_video_and_feed() {
    var ie = navigator.userAgent && navigator.userAgent.indexOf('MSIE') > -1;
    var params = 'resizable=0,scrollbars=0,directories=0,location=0,menubar=0,status=0,toolbar=0';
 
    var video_width  = 1000;
    var video_height = 630;
    var feed_width   = 300;
    var feed_height  = 448;
    var video_params = params+',width='+video_width+',height='+video_height;
    var video_left, video_top;
    // IE doesn't allow cross-domain access of window properties,
    // so we need to set the position explicitly
    if (ie) {
        video_left = 50;
        video_top  = 50;
        video_params += ',top='+video_top+',left='+video_left+',screenY='+video_top+',screenX='+video_left;
    }
 
    var video_window = window.open('http://mmod.ncaa.com/video/', 
                                'mmodvideo', 
                                video_params);
 
    // IE doesn't allow cross-domain access of window properties,
    // so we can't access the screenLeft/screenTop in IE
    if (!ie) {
        video_left = video_window.screenLeft ? video_window.screenLeft : video_window.screenX;
        video_top  = video_window.screenTop  ? video_window.screenTop  : video_window.screenY;
    }
    var feed_left = video_left + (video_width  - feed_width )/2;
    var feed_top  = video_top  + (video_height - feed_height)/2;
    
    var feed_params = params+',width='+feed_width+',height='+feed_height
                          +',top='+feed_top+',left='+feed_left
                          +',screenY='+feed_top+',screenX='+feed_left
                          
    var feed_window = window.open('http://mmod.ncaa.com/video/livefeed',
                                'livefeed',
                                feed_params);
}

//Developer page: used to load specific game TEXTAREA with a link to the selected game
function loadGameCode(code,target,url) {
    if (code == '') {
        document.getElementById(target).value = '<insert:/ncaasports/mmod/dtk-nogames.html>';
    }
    else {
        document.getElementById(target).value = '<a href="http://mmod.ncaa.com/video?gameid=' + code + '" onclick="window.open(\'http://mmod.ncaa.com/video?gameid=' + code + '\', \'mmodvideo\', \'resizable=0, scrollbars=0, directories=0, location=0, menubar=0, status=0, toolbar=0, width=1000, height=630\'); location.href = \'' + url + '\'; return false;">Click Here</a>';
    }
}