
function openMiniWin(url,domain,section,returnWindow){
    //scroll=true
    OpenWindow=window.open(url, "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    if (returnWindow) {
        return OpenWindow;
    }
    return false;
}
function openHelpPopup(section){
    var url = "/howitworks/site_report_definitions.html" + section;
    OpenWindow=window.open(url, "helpWin", "toolbar=no, scrollbars, menubar=no");
    if (window.focus) {OpenWindow.focus()}
    OpenWindow.document.close();
    return false;            
}

function openDlOrSiteSuggestionPopup(dlOrSite,returnWindow){
    var dlOrSiteStr = "name or a Web site";
    var dlOrSiteName = "domainSuggestion";
    if (dlOrSite == 'dl') {
        dlOrSiteStr = "download URL";
        dlOrSiteName = "downloadSuggestion";
    } 
    var html = "<b>Type or paste the " + dlOrSiteStr + " that you would like us to check.</b><br/><br/>" +
            "<form name='"+dlOrSiteName+"' action='http://www.siteadvisor.com/sites/domain/writeComments?domain=domain&amp;' method=post>"+
            "<input type=hidden name=section value='"+dlOrSiteName+"'>"+
            "<input type=text name=comments><br/><br/>"+
            "<input type=submit value='Submit "+dlOrSiteStr+" for review'>"+
            "</form>";
    OpenWindow=window.open('', "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    if (window.focus) {OpenWindow.focus()}
    OpenWindow.document.write(html);
    OpenWindow.document.close();
    if (returnWindow) {
        return OpenWindow;
    }
    return false;            

}


function openDownloadSuggestionPopup(url,domain,section,form,returnWindow){
    dlHtml = "<b>Type or paste the download URL you'd like us to check.</b><br/><br/>" +
            "<form name=downloadSuggestion action='/sites/domain/writeComments?domain="+domain+"&amp;' method=post>"+
            "<input type=hidden name=section value='downloadSuggestion'>"+
            "<input type=text name=comments><br/><br/>"+
            "<input type=submit value='Submit download for review'>"+
            "</form>";
    OpenWindow=window.open('', "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    if (window.focus) {OpenWindow.focus()}
    OpenWindow.document.write(dlHtml);
    OpenWindow.document.close();
    if (returnWindow) {
        return OpenWindow;
    }
    return false;            
}
function openDomainSuggestionPopup(domain,returnWindow){
    dlHtml = "<b>Please paste in the name of a Web site that you would like us to check.</b><br/><br/>" +
            "<form name=domainSuggestion action='/sites/domain/writeComments?domain="+domain+"&amp;' method=post>"+
            "<input type=hidden name=section value='domainSuggestion'>"+
            "<input type=text name=comments value='" + domain + "'><br/><br/>"+
            "<input type=submit value='Submit a Web site for review'>"+
            "</form>";
    OpenWindow=window.open('', "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    if (window.focus) {OpenWindow.focus()}
    OpenWindow.document.write(dlHtml);
    OpenWindow.document.close();
    if (returnWindow) {
        return OpenWindow;
    }
    return false;            
}


function changeComplaint(selectbox){
    var subDiv = document.getElementById("subRatingSelect");
    var select = document.getElementById("complaintSub");
    for (i =document.forms['comments'].complaintSub.options.length;i>0;i--){
        document.forms['comments'].complaintSub.options[i]=null;
    }
    if (selectbox.selectedIndex==4){
        subDiv.style.height=100;
        select.style.height=80;
        subDiv.style.visibility = "visible";
        document.forms['comments'].complaintSub.options[0]=new Option('------------ Select relevant items from the list below ------------','-1');
        document.forms['comments'].complaintSub.options[1]=new Option('a. Bad Customer Service' ,'Bad Customer Service');
        document.forms['comments'].complaintSub.options[2]=new Option('b. Bad Return Policy' ,'Bad Return Policy');
        document.forms['comments'].complaintSub.options[3]=new Option('c. Shipping Time was too long'  ,'Shipping Time was too long');
        document.forms['comments'].complaintSub.options[4]=new Option('d. Poor Product Quality'  ,'Poor Product Quality');
        document.forms['comments'].complaintSub.options[5]=new Option('e. Misleading Product/Service'  ,'Misleading Product/Service');
        document.forms['comments'].complaintSub.options[6]=new Option('f. Automatically rebills for the product or service without notification.' ,'Automatically rebills for the product or service without notification.');
        document.forms['comments'].complaintSub.options[7]=new Option('g. Other','Other');
    }
    else if (selectbox.selectedIndex==5){
        subDiv.style.height=100;
        select.style.height=80;
        subDiv.style.visibility = "visible";
        document.forms['comments'].complaintSub.options[0]=new Option('------------ Select relevant items from the list below ------------','-1');
        document.forms['comments'].complaintSub.options[1]=new Option('a. Steals user information' ,'Steals user information');
        document.forms['comments'].complaintSub.options[2]=new Option('b. Illegitimate site (fake)' ,'Illegitimate site (fake)');
        document.forms['comments'].complaintSub.options[3]=new Option('c. Counterfeit goods' ,'Counterfeit goods');
        document.forms['comments'].complaintSub.options[4]=new Option('d. Designed to mimic a legitimate site' ,'Designed to mimic a legitimate site');
        document.forms['comments'].complaintSub.options[5]=new Option('e. Phishing','Phishing');
        document.forms['comments'].complaintSub.options[6]=new Option('f. Other','Other');
    }
    else if (selectbox.selectedIndex==6){
        subDiv.style.height=100;
        select.style.height=80;
        subDiv.style.visibility = "visible";
        document.forms['comments'].complaintSub.options[0]=new Option('------------ Select relevant items from the list below ------------','-1');
        document.forms['comments'].complaintSub.options[1]=new Option('a. Sells customer information ' ,'Sells customer information');
        document.forms['comments'].complaintSub.options[2]=new Option('b. Fraudulent' ,'Fraudulent');
        document.forms['comments'].complaintSub.options[3]=new Option('c. Distributes spyware' ,'Distributes spyware');
        document.forms['comments'].complaintSub.options[4]=new Option('d. Misleading product or service' ,'Misleading product or service');
        document.forms['comments'].complaintSub.options[5]=new Option('e. Sells a poor quality product or service' ,'Sells a poor quality product or service');
        document.forms['comments'].complaintSub.options[6]=new Option('f. Bad Customer Service' ,'Bad Customer Service');
        document.forms['comments'].complaintSub.options[7]=new Option('g. Bad policies for returns or rebilling.' ,'Bad policies for returns or rebilling.');
        document.forms['comments'].complaintSub.options[8]=new Option('h. Other','Other');
    }
    else {
        subDiv.style.visibility = "hidden";
        subDiv.style.height=1;
        select.style.height=1;
        document.forms['comments'].complaintSub.options[0]=new Option('------------ No sub question for the selection above ------------','-1');
    }
}



function openMiniWinGetSelectValue(url,domain,section,form,returnWindow){
    //scroll=true
    var box = form.complaint;
    var value = box.options[box.selectedIndex].value;
    if (box.selectedIndex == 0){
        alert("You must select one of the complaint options");
        return false;
    }
    var popupHtml = "Thank you for your feedback! <a href=javascript:window.close()>Close window</a>";
    if (value=='4'){
        popupHtml = "<b>Follow-up Question: Why do you consider purchasing/ordering things on this site to be a bad idea? (check all that apply):</b><br/>"+
            "<form name=complaints action='/sites/domain/writeComments?domain="+domain+"&amp;' method=post>"+
            "<input type=hidden name=section value='complaintSub4'>"+
            "<input type=checkbox name=comments value='a. Bad Customer Service' />a. Bad Customer Service<br/>" +
            "<input type=checkbox name=comments value='b. Bad Return Policy' />b. Bad Return Policy<br/>" +
            "<input type=checkbox name=comments value='c. Shipping Time was too long' />c. Shipping Time was too long<br/>" +
            "<input type=checkbox name=comments value='d. Poor Product Quality' />d. Poor Product Quality<br/>" +
            "<input type=checkbox name=comments value='e. Misleading Product/Service' />f. Misleading Product/Service<br/>" +
            "<input type=checkbox name=comments value='f. Automatically rebills for the product or service without notification.' />g. Automatically rebills for the product or service without notification.<br/>" +
            "g. Other: <input type=text name=otherComments ><br/>" +
            "<input type=submit><br/>"+
            ""+
            "</form>";
    }
    if (value=='5'){
        popupHtml = "<b>Follow-up Question: Why would you classify this site as fraudulent? (check all that apply):</b><br/>"+
            "<form name=complaints action='/sites/domain/writeComments?domain="+domain+"&amp;' method=post>"+
            "<input type=hidden name=section value='complaintSub5'>"+
            "<input type=checkbox name=comments value='a. Steals user information' />a. Steals user information<br/>" +
            "<input type=checkbox name=comments value='b. Illegitimate site (fake)' />b. Illegitimate site (fake)<br/>" +
            "<input type=checkbox name=comments value='c. Counterfeit goods' />c. Counterfeit goods<br/>" +
            "<input type=checkbox name=comments value='d. Designed to mimic a legitimate site' />d. Designed to mimic a legitimate site<br/>" +
            "<input type=checkbox name=comments value='e. Phishing' />e. Phishing<br/>" +
            "f. Other: <input type=text name=otherComments><br/>" +
            "<input type=submit><br/>"+
            ""+
            "</form>";
    }
    if (value=='6'){
        popupHtml = "<b>Follow-up Question: Why would you classify this site as employing bad business practices?</b><br/>"+
            "<form name=complaints action='/sites/domain/writeComments?domain="+domain+"&amp;' method=post>"+
            "<input type=hidden name=section value='complaintSub6'>"+
            "<input type=checkbox name=comments value='a. Sells customer information ' />a. Sells customer information <br/>" +
            "<input type=checkbox name=comments value='b. Fraudulent' />b. Fraudulent<br/>" +
            "<input type=checkbox name=comments value='c. Distributes spyware' />c. Distributes spyware<br/>" +
            "<input type=checkbox name=comments value='d. Misleading product or service' />d. Misleading product or service<br/>" +
            "<input type=checkbox name=comments value='e. Sells a poor quality product or service' />e. Sells a poor quality product or service<br/>" +
            "<input type=checkbox name=comments value='f. Bad Customer Service' />f. Bad Customer Service<br/>" +
            "<input type=checkbox name=comments value='g. Bad policies for returns or rebilling.' />g. Bad policies for returns or rebilling.<br/>" +
            "h. Is there a competitor you can recommend? <input type=text name=otherComments><br/>"+
            "i. Other: <input type=text name=comments ><br/>" +
            "<input type=submit><br/>"+
            ""+
            "</form>";
    }


//    OpenWindow=window.open(url + encodeURI(value), "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    loadXMLDoc(url + encodeURI(value));
    OpenWindow=window.open('', "newwin", "height=250, width=450,toolbar=no,scrollbars,menubar=no");
    if (window.focus) {OpenWindow.focus()}
    OpenWindow.document.write(popupHtml);
    OpenWindow.document.close();
    if (returnWindow) {
        return OpenWindow;
    }
    return false;
}
var req;

// crazy AJAX 
function loadXMLDoc(url) 
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange() 
{
    // only if req shows "complete"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
          // ...processing statements go here...
          //response  = req.responseXML.documentElement;
          response = req.responseText;
          //method = response.getElementsByTagName('method')[0].firstChild.data;
          //result = response.getElementsByTagName('result')[0].firstChild.data;
          //eval(method + '(\'\', result)');
          //alert("response received: " + response);
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}
function noop(a,b){
    return;
}


function writeHtml(domain,section,flag,OpenWindow){
    
    OpenWindow.document.write("<TITLE>" + domain + " Notes</TITLE>")
    OpenWindow.document.write("<style>body{font-family:Arial,Helvetica,SansSerif;font-size:12px;}</style>")
    OpenWindow.document.write("<BODY>")
    OpenWindow.document.write("<br /><b>Comments about the " );
    if (flag == "comments"){
        OpenWindow.document.write( section + " section ");
    } else {
        OpenWindow.document.write( flag + " flag ");
    }
    OpenWindow.document.write("for " + domain + "</b><br /><br />\n")
    OpenWindow.document.write("<form action='/sites/domain/writeComments'>");
    OpenWindow.document.write("<input type=hidden name=section value='"+section+"'>")
    OpenWindow.document.write("<input type=hidden name=domain value='"+domain+"'>");
    OpenWindow.document.write("<input type=hidden name=flag value='"+flag+"'>");
    OpenWindow.document.write("<input type=hidden name=fromPopup value=true>");
    OpenWindow.document.write("<textarea rows=4 cols=40 name=comments></textarea>");
    OpenWindow.document.write("<br /><input type=submit value='Submit comments' class=xx>")
    OpenWindow.document.write("</form>")
    OpenWindow.document.write("</BODY>")
    OpenWindow.document.write("</HTML>")

    OpenWindow.document.close()
}
function openMiniWinAndWriteHtml(url,domain,section,flag){
    ow = openMiniWin(url,domain,section,true);
    writeHtml(domain,section,flag,ow);
}

function handleDynamicGrey(navName){
    var greyedOutColor ='#eeeeee';//'#8A644A';
    var greyedOutTextColor ='#dddddd';
    var borderStyle = "1px solid " + greyedOutTextColor;

    if (navName == "nav2"){
        base = "mail";
    } else if (navName == "nav3"){
        base = "shop";
    } else {
        return;
    }
    
    e = document.getElementById(base + "Header");
    if (e != null) {
        e.style.backgroundColor = greyedOutColor;
        e.style.border = borderStyle;
    }
    e = document.getElementById(base + "HeaderLink")
    if (e != null) {
        e.style.color = greyedOutTextColor;
        e = document.getElementById(base + "HeaderEditLink")
        e.style.color = greyedOutTextColor;
    }
    e = document.getElementsByName(base + "Data");
    if (e != null) {
        for (var i=0;i<e.length;i++){
            if (e[i].className == "underlineTd"){
                e[i].style.borderBottom=borderStyle;
            } else {
                e[i].style.color = greyedOutTextColor;
                e[i].style.border = borderStyle;
            }
        }
    }
    e = document.getElementById(base + "HeaderImg");
    if (e != null) {
        e.src = "/images/spacer.gif";
        e.width = "33";
        e.height = "33";
    }        
}

function greyOutNav(elementName){
    var str = "";
    var greyedOutColor ='#eeeeee';//'#8A644A';
    var greyedOutTextColor ='#dddddd';
    var borderStyle = "1px solid " + greyedOutTextColor;
    e = document.getElementById(elementName);
    e.style.backgroundColor=greyedOutColor;
    a = e.childNodes;
    for (var i =0;i<a.length;i++){
        if (a[i].nodeName == 'A'){
            a[i].style.backgroundColor=greyedOutColor;
            a[i].style.color=greyedOutTextColor;
            a[i].style.borderLeft=borderStyle;
            a[i].style.borderTop=borderStyle;
            a[i].style.borderRight=borderStyle;
            a[i].href='#';
            b = document.getElementById(elementName +"img");
            b.src='/images/spacer.gif';
            b.width=19;
            b.height=19;
        }        
    }
    handleDynamicGrey(elementName);
}

function checkEmailAddressAndNickname(form)
{
    var x = form.user_id.value;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(x)) {
        alert("The email address you entered is malformed, please try again.");
        return false;
    }
    x = form.nickname.value;
    filter  = /^([a-zA-Z0-9_\-])+$/;
    if (!filter.test(x)){ 
        alert("The nickname you entered is malformed, please try again. Nicknames may only contain letters, numbers, underscores ('_'), and dashes ('-')");
        return false;
    }
    if (form.password.value != form.password2.value)  {
        alert("The passwords you entered do not match. Please try again.");
        return false;
    }
    return true;
    
}

function checkCommentsBox(form)
{
    var x = form.comments.value;
    var re = /[ \n\t]*/;
    x = x.replace(re,'');
    r = document.getElementById('otherCommentsRateThisSite');
    if (x=="" && r.selectedIndex==0){
        alert("You must either enter a comment in the comment box or rate the site.");
        return false;
    }
    return true;
}

