﻿

var adORD = Math.floor(Math.random()*(10000000000000000000));// DoubleClick initialization
window["wtPlayer"] = new Object();

function getElement(e){
	if(document.getElementById) return document.getElementById(e);
	else if(document.all) return document.all[e];
	else return null;
}

function addLoadEvent(f) {
  var args = addLoadEvent.arguments;
  var orig = window.onload;

  if (typeof window.onload != 'function') {
    if(args.length > 1){
        window.onload = function(){
            f(args[1]);
        };
    }
    else window.onload = f;
  } else {
    window.onload = function() {
      if (orig) {
        orig();
      }
      if(args.length > 1) f(args[1]);
      else f();
    }
  }
}

function clickSubmitOnEnter(submitButton, evt) {
    var result = true;
    var but = getElement(submitButton);

    if ((evt.which && evt.which == 13) || (evt.keyCode && evt.keyCode == 13))
    {
        result = false;
        if (but != null && but.click) but.click();
    }

    return result;
}

function whitetailPopUp(theURL, winName, features) {
    var hWnd = window.open(theURL, 'hWnd', features);
    if(hWnd) hWnd.focus();
    return false;
}

function setCookie(name, value)
{
    var def = 1;    // Default hours to expire the cookie
    var magnifier = 1000*60*60;
    var expires = new Date();
    var argv = setCookie.arguments;  
    var argc = setCookie.arguments.length;  
    ((argc > 2)? expires.setTime(expires.getTime()+ magnifier * argv[2]) :
                expires.setTime(expires.getTime()+ magnifier * def));  
    path = (argc > 3)? argv[3] : null;  
    domain = (argc > 4)? argv[4] : null;  
    secure = (argc > 5)? argv[5] : false;  
    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + 
    ((path==null)? "" : ("; path="+path)) +
    ((domain==null)? "" : ("; domain="+domain)) +    
    ((secure==true)? "; secure" : "");

}// endfcn

function getCookie(name)
{  
   search = name + "=";  
   searchLen = search.length;  
   cookieLen = document.cookie.length;  
   var l = 0;  
   while (l < cookieLen){    
     offset = l + searchLen;    
     if(document.cookie.substring(l, offset) == search){
       endstr = document.cookie.indexOf (";", offset);  
	 if(endstr == -1)  endstr = document.cookie.length;  
	 return unescape(document.cookie.substring(offset, endstr));
     }// endif
     l = document.cookie.indexOf(" ", l) + 1;    
     if(l == 0) break;   
   }// endwhile
  
return null;
}

function deleteCookie(name)
{  
   var exp = new Date();  
   exp.setTime(exp.getTime() - 1); 
   var cookieVal = getCookie(name);  
   document.cookie = name + "=" + cookieVal + "; expires=" + exp.toGMTString();
}

function searchBoxFocus(txt){
    if(txt.value == 'Search VS. Country') txt.value = '';
    txt.className = 'search-box-focus';
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function channelFinderHack(url){
    var winCf = window.open(url,'winCf','');
}

function closeLoginPopup(){
    var ds = $find('pceLoginBehaviorShare');
    var dc = $find('pceLoginBehaviorComment');
    var da = $find('pceLoginBehaviorAssetInfo');
    var dv = $find('pceLoginBehaviorVideo');
    var du = $find('pceLoginBehaviorUpload');
    var dq = $find('pceLoginBehaviorQuestion');
    var dt = $find('pceLoginBehaviorTip');
    var ugcRating = $find('pceLoginBehaviorUGCRating');
    var aws = $find('pceLoginBehaviorAWShare');
    var abuse = $find('pceLoginBehaviorAbuse');

    if(ds) ds.hidePopup();
    if(dc) dc.hidePopup();
    if(da) da.hidePopup();
    if(dv) dv.hidePopup();
    if(du) du.hidePopup();
    if(dq) dq.hidePopup();
    if(dt) dt.hidePopup();
    if(ugcRating) ugcRating.hidePopup();
    if(aws) aws.hidePopup();
    if(abuse) abuse.hidePopup();
    
    return false;
}