function isNav() {
    var app = navigator.appName;
    if (app.indexOf('Netscape') != -1) {
        return true;
    } else {
        return false;
    }
}

function setHomePage(theLink) {
    if (isNav()) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesWrite');
        navigator.preference('browser.startup.homepage', window.location.host);
    } else {
        theLink.style.behavior = 'url(#default#homepage)';
        theLink.setHomePage(window.location.host);
    }
    return false;
}

function setMashTextFieldValue() {
    document.getElementById('mash_textarea').value = embed_text;
}

function showAssetTool(event) {
    if (typeof(event) == "string") {
        var details = document.getElementById("assetToolDetails");
        for (var i = 0; i < details.childNodes.length; i++) {
            if (details.childNodes[i].nodeType == 1) {
                details.childNodes[i].style.display = "none";
            }
        }
        var d = document.getElementById(event);
        d.style.display = "block";
    } else {
        var a = event.srcElement || event.target;

        if (a.nodeName == "IMG") {
            a = a.parentNode;
        }

        var li = a.parentNode;
        var ul = li.parentNode;
        var divs = ul.getElementsByTagName("div");
        var div = (a.nextSibling.nodeType == 1) ? a.nextSibling : a.nextSibling.nextSibling;

        for (var i = 0; i < divs.length; i++) {
            divs[i].style.display = 'none';
        }

        div.style.display = "block";
        a.blur();
    }
}

function closeAssetToolDetail(detail) {
    document.getElementById(detail).style.display = "none";
}

function uncheckAssetTypeCheckBoxes(typeImg, typeVideo, typeText) {
    document.getElementById(typeImg).checked = false;
    document.getElementById(typeVideo).checked = false;
    document.getElementById(typeText).checked = false;
}

function uncheckAllAssetTypeCheckbox(typeAll) {
    document.getElementById(typeAll).checked = false;
}

function clickLink(linkId)
{
    var fireOnThis = document.getElementById(linkId)
    if (document.createEvent)
    {
        var evObj = document.createEvent('MouseEvents')
        evObj.initEvent('click', true, false)
        fireOnThis.dispatchEvent(evObj)
    }
    else if (document.createEventObject)
    {
        fireOnThis.fireEvent('onclick')
    }
}

function clickCommandOnEnterKey(evt, commandId) {
    var keycode;

    if (evt) ;
    else if (window.event) evt = window.event;
    else if (event) evt = event;
    else return true;

    if (evt.charCode) keycode = evt.charCode;
    else if (evt.keyCode) keycode = evt.keyCode;
    else if (evt.which) keycode = evt.which;
    else keycode = 0;

    if (keycode == 13) {
        var command = document.getElementById(commandId);

        if (command.dispatchEvent) {
            var clickevent = document.createEvent("MouseEvents");
            clickevent.initEvent("click", true, true);
            command.dispatchEvent(clickevent)
        } else if (command.fireEvent) {
            command.fireEvent("onclick");
        } else {
            return true;
        }

        return false;
    }

    return true;
}

function writeflash(movie, name, width, height, divTag) {
    var object = " <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" +
                 "  codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='" + width + "'" +
                 "   height='" + height + "' id='" + name + "'> " +
                 "   <param name='movie' value='" + movie + "'/>" +
                 "   <param name='quality' value='high'/>" +
                 "   <param name='menu' value='false'/> " +
                 "   <param name='wmode' value='opaque'/> " +
                 "   <param name='base' value='.'/>" +
                 "   <param name='swLiveConnect' value='true'/>" +
                 "   <param name='allowScriptAccess' value='always'/>" +
                 "   <embed src='" + movie + "' name='" + name + "' quality='high' menu='false' swLiveConnect='true' AllowScriptAccess='always' 'wmode='opaque' base='.'" +
                 "   pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + width + "'" +
                 "  height='" + height + "'></embed></object>";
    var element = document.getElementById(divTag);
    element.innerHTML = object;
}

function createBookMark(title, url) {
    title = 'Voxant Asset: ' + title
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    } else if (window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

//function addBookMark(url, context, view, id, title) {
//    var bookMarkUrl = url + '/';
//    if (context != '') {
//        bookMarkUrl = bookMarkUrl + context;
//        bookMarkUrl = bookMarkUrl + '/';
//    }
//    bookMarkUrl = bookMarkUrl + view;
//    bookMarkUrl = bookMarkUrl + '?assetId=' + id;
//    title = 'Voxant Asset: ' + title;
//    createBookMark(title, bookMarkUrl);
//}
//

/******** start Editor scripts *******/
function submitEditorForm(id, action) {
    var o = document.getElementById(id);
    if (id == 'new_form')
        redir = 'new';
    else
        redir = 'edit';

    cat = document.getElementById('provider_feed_id_list');
    url = document.getElementById('provider_feed_url_list');
    for (i = 0; i < url.options.length; i++) {
        if (url.options[i].text == "change me now") {
            alert('You must provide a valid URL for this category: '
                    + cat.options[i].text);
            return true;
        }
        url.options[i].value = url.options[i].text;
    }

    all_selected('provider_source_list', 1);
    all_selected('provider_feed_id_list', 1);
    all_selected('provider_feed_url_list', 1);

    var d = document.getElementById('provider_source2_list');
    if (d) {
        // so this select box will not be submitted
        d.disabled = true;
    }
    d = document.getElementById('provider_feed2_list');
    if (d) {
        // so this select box will not be submitted
        d.disabled = true;
    }
    d = document.getElementById('feed_url_text');
    if (d) {
        // so this select box will not be submitted
        d.disabled = true;
    }

    f = eval("document." + o.name);
    if (o) {
        new Ajax.Updater('editor_main', action,
        {asynchronous:true, evalScripts:true,
            parameters:Form.serialize(f)});

        //o.action = action;
        //o.submit();
        /* code not working. TODO: find out why
           new Ajax.Request(action,
              {asynchronous:true, evalScripts:true,
               {parameters:Form.serialize(document.new_form),
                 on200:handlerFunc('list_ajax'),
                 on406:handlerFunc(redir)}
              });
        */
    }
}

function switchEditorMain(s) {
    o = document.getElementById('editor_main');
    o.style.overflow = s;
}

function enable_obj(id) {
    o = document.getElementById(id);

    check_issource = document.getElementById('provider_issource')
    check_isprovider = document.getElementById('provider_isprovider');
    check_addsource = document.getElementById('provider_addsource');
    addsource_div = document.getElementById('provider_addsource_div');

    if (id == 'provider_issource') {
        if (o.checked && !check_isprovider.checked) {
            document.getElementById('provider_provider_span').style.display = '';
            document.getElementById('provider_provider_div').style.display = '';
        } else {
            document.getElementById('provider_provider_span').style.display = 'none';
            document.getElementById('provider_provider_div').style.display = 'none';
        }
    } else if (id == 'provider_isprovider') {
        if (o.checked) {
            document.getElementById('provider_provider_span').style.display = 'none';
            document.getElementById('provider_provider_div').style.display = 'none';
        } else if (check_issource.checked) {
            document.getElementById('provider_provider_span').style.display = '';
            document.getElementById('provider_provider_div').style.display = '';
        }
    } else if (id == 'provider_addsource') {
        if (o.checked) {
            check_isprovider.checked = true;
            document.getElementById('provider_addsource_div').style.display = '';
        } else {
            document.getElementById('provider_addsource_div').style.display = 'none';
        }
    } else if (id == 'provider_isdistributor') {
        if (o.checked) {
            document.getElementById('provider_distributor_div').style.display = '';
        } else {
            document.getElementById('provider_distributor_div').style.display = 'none';
        }
    }

    if (check_issource.checked) {
        check_addsource.checked = false;
        check_addsource.disabled = true;
        addsource_div.style.display = 'none';
    } else {
        check_addsource.disabled = false;
    }
    /*
      if ( check_addsource.checked) {
         check_isprovider.checked = true;
      }

      if ( check_isprovider.checked == true ) {
         provider_div = document.getElementById('provider_provider_div');
         provider_span = document.getElementById('provider_provider_span');
         provider_div.style.display='none';
         provider_span.style.display='none';
      }
    */
}

function move(src_id, dest_id) {
    var i = 0;

    srcListBox = document.getElementById(src_id);
    destListBox = document.getElementById(dest_id);

    var srcListLength = srcListBox.options.length;
    for (var i = 0; i < srcListLength; i++) {
        if (srcListBox.options[i].selected && srcListBox.options[i] != "") {
            srcListBox.options[i].selected = false;
            // Copy from srcListBox to destListBox
            var no = new Option();
            no.value = srcListBox.options[i].value;
            no.text = srcListBox.options[i].text;
            destListBox.options[destListBox.options.length] = no;
            srcListBox.options[i].value = "";
            srcListBox.options[i].text = "";
        }
    }
    //Remove old entry from srcListBox
    compact(srcListBox);
    sort_list(src_id);
    sort_list(dest_id);

    src = document.getElementById('provider_source_list');
    if (src) {
        src.options[src.selectedIndex].selected = 0;
    }
}

function compact(abox) {
    var numRemoved = 0;
    var maxTries = abox.options.length;
    var realCounter = 0;
    var selectionMarker = -1;
    for (var i = 0; i < abox.options.length && realCounter < maxTries; i++) {
        if (i < abox.options.length && abox.options[i].value == "") {
            if (selectionMarker == -1) {
                selectionMarker = i
            }
            //Copy upwards
            for (var j = i; j < abox.options.length - 1; j++) {
                abox.options[j].value = abox.options[j + 1].value;
                abox.options[j].text = abox.options[j + 1].text;
            }
            //Need to recheck this position, since an empty may have moved in
            i = i - 1;
            numRemoved = numRemoved + 1;
        }
        realCounter = realCounter + 1;
    }
    abox.options.length = abox.options.length - numRemoved;
    if (selectionMarker > 0) {
        abox.selectedIndex = selectionMarker - 1;
    } else {
        abox.selectedIndex = 0;
    }
}

function sort_list(mylist)
{
    var lb = document.getElementById(mylist);
    arrTexts = new Array();
    arrValues = new Array();
    arrOldTexts = new Array();

    for (i = 0; i < lb.length; i++) {
        arrTexts[i] = lb.options[i].text;
        arrValues[i] = lb.options[i].value;
        arrOldTexts[i] = lb.options[i].text;
    }

    arrTexts.sort();

    for (i = 0; i < lb.length; i++) {
        lb.options[i].text = arrTexts[i];
        for (j = 0; j < lb.length; j++) {
            if (arrTexts[i] == arrOldTexts[j]) {
                lb.options[i].value = arrValues[j];
                j = lb.length;
            }
        }
    }
}

function all_selected(obj, sel) {
    var selObj = document.getElementById(obj);
    var i;
    if (selObj) {
        for (i = 0; i < selObj.options.length; i++) {
            selObj.options[i].selected = sel;
        }
    }
}

function move2(src_id, dest_id) {
    var i = 0;

    srcListBox = document.getElementById(src_id);
    destListBox = document.getElementById(dest_id);
    urlListBox = document.getElementById('provider_feed_url_list');

    all_selected('provider_feed_id_list', 0);
    all_selected('provider_feed_url_list', 0);

    var srcListLength = srcListBox.options.length;
    for (var i = 0; i < srcListLength; i++) {
        if (srcListBox.options[i].selected && srcListBox.options[i] != "") {
            srcListBox.options[i].selected = false;
            // Copy from srcListBox to destListBox
            var no = new Option();
            no.value = srcListBox.options[i].value;
            no.text = srcListBox.options[i].text;
            destListBox.options[destListBox.options.length] = no;
            srcListBox.options[i].value = "";
            srcListBox.options[i].text = "";
            if (src_id == 'provider_feed_id_list') {
                urlListBox.options[i].value = "";
                urlListBox.options[i].text = "";
            } else if (dest_id == 'provider_feed_id_list') {
                var no2 = new Option();
                no2.value = no.value;
                // to be updated later
                no2.text = "change me now";
                urlListBox.options[urlListBox.options.length] = no2;
                destListBox.options[destListBox.options.length - 1].selected = 1;
                urlListBox.options[urlListBox.options.length - 1].selected = 1;
                update_url_text('provider_feed_id_list', 'provider_feed_url_list');
            }
        }
    }
    //Remove old entry from srcListBox
    compact(srcListBox);
    if (src_id == 'provider_feed_id_list') {
        compact(urlListBox);
    }
}

function update_url_text(master, servant) {
    var mas = document.getElementById(master);
    var ser = document.getElementById(servant);

    var d = document.getElementById('feed_url_text');
    var length = mas.options.length;

    all_selected(servant, 0);
    for (var i = 0; i < length; i++) {
        if (mas.options[i].selected) {
            ser.options[i].selected = 1;
            if (master == 'provider_feed_url_list') {
                d.value = mas.options[i].text;
            } else if (servant == 'provider_feed_url_list') {
                d.value = ser.options[i].text;
            }
        }

    }
}

function update_url_list() {
    list = document.getElementById('provider_feed_url_list');
    d = document.getElementById('feed_url_text');
    for (i = 0; i < list.options.length; i++) {
        if (list.options[i].selected) {
            list.options[i].value = d.value;
            list.options[i].text = d.value;
        }
    }
}
/******** end Editor scripts *******/


/**** begin script for feedback form ****/

function disableReason( reasonFlag, subCatFlag  ) {
    r1 = document.getElementById('reason1');
    r2 = document.getElementById('reason2');
    r1.disabled = reasonFlag;
    r2.disabled = reasonFlag;
    subcat1 = document.getElementById("00N50000001PWHh");
    subcat1.disabled = subCatFlag;
}

function generateCaseReason(typeSelected) {
    document.getElementById('caseReasonSubcat').style.display = 'none';
    if (typeSelected.options[typeSelected.selectedIndex].value == 'Questions/Problems'){
        showElement('caseReason');
        resetCategorySelectBox('reason1');
        showElement('problem_question_select');
        hideElement('feature_request_select');
        hideElement('desc');
        hideElement('subj');
        disableReason(false, false);
    }
    else if (typeSelected.options[typeSelected.selectedIndex].value == 'Feature Request') {
        showElement('caseReason');
        hideElement('problem_question_select');
        resetCategorySelectBox('reason1');
        resetCategorySelectBox('reason2');
        showElement('feature_request_select');
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('API/RSS', 'API/RSS');
        subCatSelectBox.options[2] = new Option('Player', 'Player');
        subCatSelectBox.options[3] = new Option('Content', 'Content');
        subCatSelectBox.options[4] = new Option('Search', 'Search');
        subCatSelectBox.options[5] = new Option('Feeds/Playlists', 'Feeds/Playlists');
        subCatSelectBox.options[6] = new Option('Registration/MyProfile', 'Registration/MyProfile');
        subCatSelectBox.options[7] = new Option('Revenue/Reporting', 'Revenue/Reporting');
        subCatSelectBox.options[8] = new Option('Performance', 'Performance');
        subCatSelectBox.options[9] = new Option('Rewards', 'Rewards');
       // subCatSelectBox.options[10] = new Option('Content Missing', 'Content Missing');
        subCatSelectBox.options[10] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');
        disableReason(false, false);

    }
     else  if (typeSelected.options[typeSelected.selectedIndex].value == 'Advertise With Us') {
            hideElement('caseReason');
            document.getElementById('subject').value = ""
            document.getElementById('description').value = ""
            showElement('subj');
            showElement('desc');
            disableReason(true, true);
        }
    else {
        if (typeSelected.options[typeSelected.selectedIndex].value == 'Positive Feedback') {
            hideElement('caseReason');
            document.getElementById('subject').value = ""
            document.getElementById('description').value = ""
            showElement('subj');
            showElement('desc');
            disableReason(true, true);
        }
    }
}


function generateCaseReasonSubcat(caseSelected) {
    if (caseSelected.options[caseSelected.selectedIndex].value == 'User Questions/Instructions') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('Embedding', 'Embedding');
        subCatSelectBox.options[2] = new Option('Building Playlists', 'Building Playlists');
        subCatSelectBox.options[3] = new Option('Creating Feeds', 'Creating Feeds');
        subCatSelectBox.options[4] = new Option('Creating RSS Feeds', 'Creating RSS Feeds');
        subCatSelectBox.options[5] = new Option('Registration', 'Registration');
        subCatSelectBox.options[6] = new Option('Multiple Websites', 'Multiple Websites');
        subCatSelectBox.options[7] = new Option('Password Reset', 'Password Reset');
        subCatSelectBox.options[8] = new Option('Auto-Play', 'Auto-Play');
        subCatSelectBox.options[9] = new Option('Video/Text/Image Resizing', 'Video/Text/Image Resizing');
        subCatSelectBox.options[10] = new Option('Foreign Content', 'Foreign Content');
        subCatSelectBox.options[11] = new Option('Content Updates', 'Content Updates');
        subCatSelectBox.options[12] = new Option('NewsPERKS', 'NewsPERKS');
        subCatSelectBox.options[13] = new Option('Affiliate Programs/Ambassadors', 'Affiliate Programs/Ambassadors');
        subCatSelectBox.options[14] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');

    }

    if (caseSelected.options[caseSelected.selectedIndex].value == 'User Issues') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('Auto-Play', 'Auto-Play');
        subCatSelectBox.options[2] = new Option('Video Stopping', 'Video Stopping');
        subCatSelectBox.options[3] = new Option('Video Loading', 'Video Loading');
        subCatSelectBox.options[4] = new Option('Copy/Paste', 'Copy/Paste');
        subCatSelectBox.options[5] = new Option('HTML Editor/Code', 'HTML Editor/Code');
        subCatSelectBox.options[6] = new Option('Feeds', 'Feeds');
        subCatSelectBox.options[7] = new Option('Size', 'Size');
        subCatSelectBox.options[8] = new Option('Play Lists', 'Play Lists');
        subCatSelectBox.options[9] = new Option('Error', 'Error');
        subCatSelectBox.options[10] = new Option('Auto-Feed', 'Auto-Feed');
        subCatSelectBox.options[11] = new Option('RSS Feed', 'RSS Feed');
        subCatSelectBox.options[12] = new Option('Page Errors', 'Page Errors');
        subCatSelectBox.options[13] = new Option('Players', 'Players');
        subCatSelectBox.options[14] = new Option('Content Update', 'Content Update');
        subCatSelectBox.options[15] = new Option('Advertisements', 'Advertisements');
        subCatSelectBox.options[16] = new Option('Content Missing', 'Content Missing');
        subCatSelectBox.options[17] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');
    }

    if (caseSelected.options[caseSelected.selectedIndex].value == 'MyRevenue') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('Revenue Activity', 'Revenue Activity');
        subCatSelectBox.options[2] = new Option('Disputes', 'Disputes');
        subCatSelectBox.options[3] = new Option('Earnings', 'Earnings');
        subCatSelectBox.options[4] = new Option('Payments', 'Payments');
        subCatSelectBox.options[5] = new Option('Paypal', 'Paypal');
        subCatSelectBox.options[6] = new Option('Tax', 'Tax');
        subCatSelectBox.options[6] = new Option('Referrals', 'Referrals');
        subCatSelectBox.options[7] = new Option('Number of Plays/Renders/Impressions', 'Number of Plays/Renders/Impressions');
        subCatSelectBox.options[8] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');
    }

    if (caseSelected.options[caseSelected.selectedIndex].value == 'Product Improvement') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('API', 'API');
        subCatSelectBox.options[2] = new Option('Player', 'Player');
        subCatSelectBox.options[3] = new Option('Content', 'Content');
        subCatSelectBox.options[4] = new Option('Search', 'Search');
        subCatSelectBox.options[5] = new Option('Feeds/Playlists', 'Feeds/Playlists');
        subCatSelectBox.options[6] = new Option('Registration/MyProfile', 'Registration/MyProfile');
        subCatSelectBox.options[7] = new Option('Revenue/Reporting', 'Revenue/Reporting');
        subCatSelectBox.options[8] = new Option('Performance', 'Performance');
        subCatSelectBox.options[9] = new Option('Rewards', 'Rewards');
        subCatSelectBox.options[10] = new Option('Content Missing', 'Content Missing');
        subCatSelectBox.options[11] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');

    }

    if (caseSelected.options[caseSelected.selectedIndex].value == 'Fulfillment/Video/Transcript Order') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox.options[0] = new Option('--None--', '');
        subCatSelectBox.options[1] = new Option('DVD Order', 'DVD Order');
        subCatSelectBox.options[2] = new Option('Transcripts Missing', 'Transcripts Missing');
        subCatSelectBox.options[3] = new Option('Transcripts Order', 'Transcripts Order');
        subCatSelectBox.options[4] = new Option('Other', 'Other');
        hideElement('subj');
        hideElement('desc');
    }

    if (caseSelected.options[caseSelected.selectedIndex].value == 'Other') {
        showElement('caseReasonSubcat');
        subCatSelectBox = document.getElementById("00N50000001PWHh");
        resetSubcatSelectBox(subCatSelectBox);
        subCatSelectBox[0] = new Option('Other', 'Other');
        showElement('subj');
        showElement('desc');
    }
}


function hideElement(elemName) {
    document.getElementById(elemName).style.display = 'none';

}

function showElement(elemName) {
    document.getElementById(elemName).style.display = '';
}

function resetSubcatSelectBox(element) {
    for (i = element.options.length - 1; i >= 0; i--) {
        element.remove(i);
    }
}

function resetCategorySelectBox(element) {
    elem = document.getElementById(element);
    elem.options[0].selected = true;
}

function generateDescSubj() {
    document.getElementById('subject').value = ''
    document.getElementById('description').value = ''
    showElement('subj');
    showElement('desc');
}


function submitFeedBackForm() {

    if (empty(stripSpaces(document.getElementById('name').value))) {
        alert('Please enter Contact Name');
        return false;
    }
    if (empty(stripSpaces(document.getElementById('email').value))) {
        alert('Please enter an Email address');
        return false;
    }
    if(!checkEmail()){
        return false;
    }

    type = document.getElementById('type');
    reason1 = document.getElementById('reason1');
    reason2 = document.getElementById('reason2');
    subreason = document.getElementById('00N50000001PWHh');

   if (type.options[type.selectedIndex].value == '') {
        alert("Please choose a reason for contacting TheNewsroom");
        return false;
    }


    if (reason1.options[reason1.selectedIndex].value == '' && type.options[type.selectedIndex].value == 'Questions/Problems') {
        alert("Please choose a category of reason for contacting TheNewsRoom ");
        return false;
    }
   if (reason2.options[reason2.selectedIndex].value == '' && type.options[type.selectedIndex].value == 'Feature Request') {
        alert("Please choose a category of reason for contacting TheNewsRoom ");
        return false;
    }
   if (subreason.options.length > 0)
        if (subreason.options[subreason.selectedIndex].value == '' &&
            reason1.options[reason1.selectedIndex].value != "Other" &&
            type.options[type.selectedIndex].value != 'Positive Feedback'  &&
            type.options[type.selectedIndex].value != 'Advertise With Us'
                ) {
            alert("Please choose a sub-category of reason for contacting TheNewsRoom");
            return false;
        }


    if (document.getElementById('subj').style.display == '')
        if (empty(stripSpaces(document.getElementById('subject').value))) {
            alert('Please enter a Subject');
            return false;
        }

    if (document.getElementById('desc').style.display == '')
        if (empty(stripSpaces(document.getElementById('description').value))) {
            alert('Please enter a Description');
            return false;
        }
  if( (reason1.disabled == false) && 
       (reason1.options[reason1.selectedIndex].value != '') ) {
     document.getElementById('reason').value=
      reason1.options[reason1.selectedIndex].value;
  } else if( (reason2.disabled == false) &&
        (reason2.options[reason2.selectedIndex].value != '') ) {
     document.getElementById('reason').value=
       reason2.options[reason2.selectedIndex].value;
  }
  disableReason(true, false);
}

function stripSpaces(x) {
    while (x.substring(0,1) == ' ') x = x.substring(1);
    return x;
}

function empty(x) { if (x.length > 0) return false; else return true; }
/**** end script for feedback form ****/

 function placeFocus(elem){
    elem.focus();
 }

function checkEmail() {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById('email').value)){
return (true)
}
alert("Email Address should be in the format 'name@domain.tld'")
return (false)
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

/* function to copy to clipboard */
function copyToClipBoard(sourceId)
{
  var source = document.getElementById(sourceId);

  var sourcetext = '';
  if (source.innerHTML)
     sourcetext = source.innerHTML.toString();
  else if (source.value)
     sourcetext = source.value;
     
  sourcetext = trimString(sourcetext);
  if( window.clipboardData && clipboardData.setData ) {
	 clipboardData.setData("Text", sourcetext);
  } else if (window.netscape) {
    try {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    } catch(err) {
      alert(err + ' Please enable this privilege to make Copy function work.');
      return false;
    }
    
    var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
    if (!clip) return;
    var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
    if (!trans) return;

    trans.addDataFlavor('text/unicode');
    var str = new Object();
    var len = new Object();
    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
 
    str.data=sourcetext;
    trans.setTransferData("text/unicode",str, sourcetext.length*2);
    var clipid=Components.interfaces.nsIClipboard;
   
    if (!clipid) return false;
    clip.setData(trans,null,clipid.kGlobalClipboard);
  }
  new Effect.Highlight(sourceId,{duration:0.35,startcolor:'#15317E'}); 
  window.setTimeout("Effect.Appear('"+sourceId+"', {duration:0.15})",1500);
  return false;
}

function setCheckboxes(formName,fieldNames,value){
  if(!document.getElementById(formName))
		return;
	for (var i=0;i<fieldNames.length;i++) {
  	var checkbox = document.getElementById(formName).elements[fieldNames[i]];
  	if(!checkbox)
  		continue;
		checkbox.checked = value;
	}
}

/* for custom feed search results */
function change_cursor( status ) {
   document.body.style.cursor = status ;
}
function ajax_update(update, form, url) {
  change_cursor('wait');
  url = url  + '?rd=' + Math.random();
  new Ajax.Updater(update, url,
      {asynchronous:true, evalScripts:true,
       parameters:Form.serialize(form),
       onLoaded:function(request){change_cursor('default')}}); 
}

function changeColor( id, color ) {
  o = document.getElementById(id);
  if (o) o.className = color;
}

function get_skin_icon(elem,action,dist_id,asset_id,n_user,c_id,thumb_set){
   skin = elem.value;
   action = action+"?skin_id="+skin+"&d_id="+dist_id+"&asset="+asset_id+"&n_user="+n_user+"&c_id="+c_id+"&th="+thumb_set;
    new Ajax.Request( action,
        {asynchronous:true, evalScripts:true});
     //new Ajax.Updater('skin_icon', action,
       // {asynchronous:true, evalScripts:true});
    return false;
  }

function rename_player(elem,action,player_id){
    player_name = elem.value.replace(/^\s*/, "").replace(/\s*$/, "");
    if (player_name.length==0) {
      alert("Please enter a name and try again.");
      return false;
    }
    action = action +"?player_id="+player_id+"&player_name="+player_name;
    new Ajax.Request( action,
        {asynchronous:true, evalScripts:true});
    return false;
}
/* end custom feed search results */

/* We should just use maxlength="120" or whatever value on the textfields instead
function limitLength(theFld, num, alertFlag){
  if(theFld.value.length > num ) {
    if ( alertFlag ) alert('Only ' + num + " characters are allowed.");
    theFld.value=theFld.value.substr(0, num );
  }
  return false;
}
*/

/* used in advanced_embed */
function validate_set_default_color( input_id ) {
  var clr_div = document.getElementById(input_id);
  var clr = clr_div.value;
  clr = trimString(clr);
  if (clr.length == 0 ) {
    clr = "FFFFFF";
    clr_div.value = clr;
    return;
  } else if (clr.length != 6) {
    clr_div.value = "FFFFFF";
    return;
  }
  if (clr.length == 6) {
    for(var j=0; j< clr.length; j++) {
      var alphaa = clr.charAt(j);
      var hh = alphaa.charCodeAt(0);
      if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)) {
      } else {
        clr_div.value = "FFFFFF";
        return;
      }
    }
  }
}

function reset_more_options(state) {
  url = "/search/reset_more_options?more=" + state;
  new Ajax.Request(url, {asynchronous:true, evalScripts:true});
}


