String.prototype.trim = function() 
{
    return this.replace(/^\s+|\s+$/g,"");
};

function validateSearch()
{
    var sk = document.getElementById('searchkey').value;
    if ( sk.trim() == '' )
    {
        alert ( "Please enter a valid search term" );
        return false;
    }
    
    document.searchFrm.submit();
}

function goToLoc(url)
{
    document.location.href = url;
}
function goToSite(e)
{   
    var url = e.options[e.selectedIndex].value;
    document.location.href = url;
    return true;
}
function setOrientation() 
{
    window.scrollTo(0, 1);
    var orient = Math.abs(window.orientation) === 90 ? 'landscape' : 'portrait';
    
    var cl = document.body.className;
    if ( cl == '' )
    {    
        document.body.className = orient;
    }
    else
    {
        cl = cl.replace(/portrait|landscape/, orient);
        document.body.className = cl;
    }    
}   
function clearTxt(cmp)
{
    if ( this.value == cmp )
        this.value = '';
    return false;
}
function isValidZip(zip)
{
    var zipvalidation = /\d{5}/;
    if(zip.search(zipvalidation) == -1)
        return false;
    return true;
}
function isValidPhone(phone)
{
    var phonevalidation = /\d{10}/;
    if(phone.search(phonevalidation) == -1)
        return false;
    return true;
}

function validateShare()
{
    var frm = document.shrForm;
    var phone = frm.phone.value;
    
    if ( isValidPhone(phone) )
    {
    	frm.RNUMBER.value = phone;
        frm.submit();
    }    
    else
    {
        alert ( "Please enter a valid phone number");
        return false;
    }
    return false;
}

function validateReg()
{
    var frm = document.videoFrm;
    var zip = frm.favzip.value;
    var phone = frm.favphone.value;
    if ( !isValidPhone(phone) )
    {
        alert ( "Please enter a valid Phone Number" );
        frm.favphone.focus()
        return false;
    }
    if ( !isValidZip(zip))
    {
        alert ( "Please enter a valid Zip Code" );
        frm.favzip.focus();
        return false;
    }
    frm.submit();
}
function addToFav(vidid)
{
    var url = "site?sid=cbsnews_ip&pid=video.fav&vidid="+ encodeURIComponent(vidid);
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", url, false, user, passwd);
    xmlHttp.setRequestHeader("Content-Type", "text/xml");
    xmlHttp.send(null);
    var xmlResponse = new XML(xmlHttp.responseText);
    return xmlResponse;
}
function changeAdImgWidth()
{
    var im = $("#wid_topAd").find("img");
    if ( im ) 
    {   
        if ( parseInt(im.attr("width"),10) > 300 )
        {
            im.attr({width: "300"});
        }    
    }
    return;    
}
window.addEventListener('orientationchange', setOrientation, false);
window.addEventListener('load', setOrientation, false);
