﻿var xmlHttp;
var currentLoopIndex;

function ShowReportAbuse(loopIndex, commentid, ok) {
    if (currentLoopIndex != null) {
        document.getElementById("popupRA" + currentLoopIndex).innerHTML = "";
        document.getElementById("popupRA" + currentLoopIndex).style.display = "none";
    }
    
    currentLoopIndex = loopIndex;
    if (!ok) {
        document.getElementById("popupRA" + loopIndex).innerHTML = "";
        document.getElementById("popupRA" + loopIndex).style.display = "none";
        return;
    }
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        return;
    }
    document.getElementById("popupRA" + loopIndex).style.display = "block";
    var url = "/moneyweek/global/report%20abuse/report.aspx?LoopIndex=" + loopIndex + "&CommentID=" + commentid;
    xmlHttp.onreadystatechange = PPPopUpstateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);    
}

function PPPopUpstateChanged() {
    if (xmlHttp.readyState == 4) {
        document.getElementById("popupRA" + currentLoopIndex).innerHTML = "<div class=\"friendFilter pngWrapper\">" + xmlHttp.responseText + "<a onclick=\"ShowReportAbuse(" + currentLoopIndex + ",'',false)\" style=\"cursor: pointer;\" class=\"close\" style=\"color:#fff\">Close</a></div>";
    }
}

function SendReportAbuse(loopIndex, commentid) {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        return;
    }
    var url = "/ReportAbuseHandler.ashx?Option=" + document.getElementById("Option" + currentLoopIndex).value + "&YourEmail=" + document.getElementById("YourEmail" + currentLoopIndex).value + "&CommentID=" + commentid + "&Note=" + document.getElementById("note" + currentLoopIndex).value;
    xmlHttp.onreadystatechange = SRPopUpstateChanged;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);  
    
}

function SRPopUpstateChanged() {
    if (xmlHttp.readyState == 4) {
        document.getElementById("popupRA" + currentLoopIndex).innerHTML = "<div class=\"friendFilter pngWrapper\"><div class=\"sendform\">" + xmlHttp.responseText + "</div><a onclick=\"ShowReportAbuse(" + currentLoopIndex + ",false)\" style=\"cursor: pointer;\" class=\"close\" style=\"color:#fff\">Close</a></div>";
    }
}

function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

function isValidEmail(email, required) {
    if (required == undefined) {   // if not specified, assume it's required
        required = true;
    }
    if (email == null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length == 0) {
        if (required) {
            return false;
        }
        return true;
    }

    //var re = ^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$;
    var re = /^.+\@.+\..{2,4}$/gi;
    if (!email.match(re)) {
        email.focus;
        return false;
    }
    //document.forms["toprightsignup"].submit();
    return true;
}