//BEGIN HEADER JAVASCRIPT INCLUDE
var curSearchType = 'Web';

function searchType(obj,searchType){
    if(curSearchType != obj.id){
        if(obj.id == 'Web'){
            document.searchForm.action = searchType;
            document.searchForm.target = '_blank';
        }else{
            document.searchForm.action = 'http://search.aol.com/aolcom/'+searchType;
        }
        obj.className="srchType tab_sel";
        document.getElementById(curSearchType).className = "srchType tab_clr";
        curSearchType = obj.id;
    }
}


if (staticDomain === undefined) {
    var staticDomain = "";
}

function saveInput(obj){

}

function menu(obj,eve,e)
{
    //if the browser is IE <6.0
    if(document.all){
        for(i=0;i<obj.childNodes.length;i++){
            child = obj.childNodes[i]
            if(child.tagName == 'UL'){
                if(e == 1){
                    child.className="drop"
                    for(j=0;j<obj.childNodes.length;j++){
                        grandchild = child.childNodes[j]
                        if(grandchild.tagName == 'IFRAME'){
                            grandchild.style.height = (child.offsetHeight)-4+'px';
                            grandchild.style.width  = (child.offsetWidth)-4+'px';
                            return;
                        }
                    }
                }
                else if(e == 2){
                child.className="hide"
                return;
                }
            }
				else if(child.tagName == 'A'){
                if(e == 1){
                         child.style.cssText="background-color:#A6D2FF;color:#FFF;"
                }
                else if(e == 2){
                         child.style.cssText="background-color:transparent;color:#cccccc;"
                }
            }
        }
    }
}

function moreOption(name){
	document.getElementById('moreOptions').className = name;
}

function checkforAolClient(){
	var is_aol = navigator.userAgent.toLowerCase().indexOf("aol") != -1;
	if(is_aol){
		document.getElementById('logoutBtn').style.display = "none";
	}
}

function userLogin(){
	var url = window.location.toString();
	var list =  escape(url);
	var startUrl = "/_cqr/login/login.psp?mcState=initialized&sitedomain=mobile.aol.com&authLev=1&seamless=y&lang=en&locale=us&siteState=OrigUrl%3d";
	var finalUrl = snsURL+ startUrl +list;
	window.location.href = finalUrl;
}

function userLogout(){
	var url = window.location.toString();
	var list =  escape(url);
	var startUrl = "/_cqr/logout/mcLogout.psp?mcState=initialized&sitedomain=mobile.aol.com&authLev=1&seamless=y&lang=en&locale=us&siteState=OrigUrl%3d";
	var finalUrl = snsURL+ startUrl +list;
	window.location.href = finalUrl;
}


function validateQuery(frm){
	document.searchForm.query.value = RTrim(document.searchForm.query.value);
    if(typeof frm == 'undefined')frm='';
    var val = document.searchForm.query.value;
    if(val == '' || val == ' Search Here'){
		if(curSearchType == 'Web'){
			window.location.href = 'http://search.aol.com/';
			return;
		}
        if(frm == 'submit'){
            return;
        } 
        return false;
    }
    else{
    	createCookieObj('searchTermDG',document.searchForm.query.value,1);
        if(curSearchType == 'Local'){
            window.location.href = 'http://sbgw.search.aol.com/kw/exec?lookupType=11&sourceType=416&text=&q='+document.searchForm.query.value;
            return;
        }
        document.searchForm.submit();
        //return true;
    }
}


/*FOOTER VALIDATE*/
function validateSearch(frmObj){
	document.bb_topform2.query.value = RTrim(document.bb_topform2.query.value);
	if (document.bb_topform2.query.value == ""){
		//alert("No Search Term! Please enter some query term; Example New York, Paris");
	}
	else{
		document.bb_topform2.submit();
	}
}

// Trims all spaces to the right of a specific string
function RTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            var i = s.length - 1;       
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;
            s = s.substring(0, i+1);
        }
        return s;
}

//cookie code
function createCookieObj(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookieVal(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return '';
}

function eraseCookieObj(name) {
        createCookie(name,"",-1);
}

function srchSub(ref){
  var queryval = document.searchForm.query.value.trim();
  if(queryval == 'Search Here'){
    queryval = '';
  }
  queryval = queryval.replace( /\+/, " ");
  newurl = ref.href + queryval;
  window.location = newurl;
  return false;

}
//END HEADER JAVASCRIPT INCLUDE
