/*
    Common Script functions
*/

function ItemRatingCallBack( vote, id )
{
   // alert("vote=" + vote + " ident=" + ident);
    /*
<a onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'POST', onSuccess: Function.createDelegate(this, onSuccessVote) });" href="/ConsultantVote?vote=123&amp;id=fff">show alert</a>
    */
    var ajaxOptions = { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'POST', onSuccess: Function.createDelegate(this, onSuccessVote) };
    var anchor = new Object();
    anchor.href = "/ConsultantVote?vote=" + vote + "&consultantId=" + id;
    var event = new Object();
    event.preventDefault = function () { };
    Sys.Mvc.AsyncHyperlink.handleClick(anchor, event, ajaxOptions);
}

// For Future
function onSuccessVote(result) {
 //   var data = result.get_object();
 //   alert("Controller return: " + data.Message);
}


function AddToConsultantCompare(id) {
    var ajaxOptions = { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'POST', onSuccess: Function.createDelegate(this, onSuccessAddToConsultantCompare) };
    var anchor = new Object();
    anchor.href = "/AddRemoveCompare?consultantId=" + id;
    var event = new Object();
    event.preventDefault = function () { };
    Sys.Mvc.AsyncHyperlink.handleClick(anchor, event, ajaxOptions);
}

function onSuccessAddToConsultantCompare(result) {

    var data = result.get_object();

    var img_id = "compare_img_" + data.id;
    var img = $$('#' + img_id)[0];

    var all_compare_count = $$("#all_compare_count")[0];
    if (all_compare_count != null) {
        all_compare_count.innerHTML = data.all;
    }

    if (data.action == "add") {
        img.src = "../../Content/compare1.png";
        img.alt = "Delete from compare";
        img.title = "::" + img.alt;
        var JTooltips = new Tips($$('#' + img_id), { maxTitleChars: 50, fixed: false });
    } else if (data.action == "remove") {
        img.src = "../../Content/compare0.png";
        img.alt = "Add to compare";
        img.title = "::" + img.alt;
        var JTooltips = new Tips($$('#' + img_id), { maxTitleChars: 50, fixed: false });
    } else if (data.action == "no more") {
        alert("You reached maximum number of records you can compare. Please delete other records before add new one.");
    }

}

function emailValidate(emailField) {
    var place = emailField.value.indexOf("@", 1);
    var point = emailField.value.indexOf(".", place + 1);
    if (emailField.value == "" || emailField.value == "E-mail") {
        return false;
    }
    else {
        if ((place > -1) && (emailField.value.length > 2) && (point > 1)) {
            return true;
        }
        else {
            return false;
        }
    }
}

function requiredValidate(field) {
    var str = jQuery.trim(field.value);
    return str != null && str != ""; 
}

function submitform() {
    document.adminForm.submit();
}

