﻿function RegisterNewsletter(_emailid) {
    $(".iletisim_left_box_content .result").html("");
    try {
        var email = $("#" + _emailid).val();
        var errormessage = $("#" + _emailid).attr("ErrorMessage");
        if (!validateEmail(email)) {
            $(".iletisim_left_box_content .result").html(errormessage);
        }
        else {
            $.ajax({
                type: "POST",
                url: "/Content/WebService/ClientSiteWebService.asmx/RegisterNewsletter",
                data: "{Email:'" + email + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    $(".iletisim_left_box_content .result").html(msg.d);
                },
                error: function (msg) {
                    return false;
                }
            });
        }

    } catch (e) {

    }
    return false;
}

function ChangeCapthca(ImgID, frm) {


    var date = new Date();

    $("#" + ImgID).attr("src", "/Page/Images/SecureCode.aspx?frm=" + frm + "&Date=" + date.getTime() + "");



}

function setText(a, b) {
    x = document.getElementById(a);
    if (x)
        x.innerHTML = b.options[b.selectedIndex].innerHTML;
}

function openUploadFile(ID) {

    alert(document.getElementById(ID));
    document.getElementById(ID).click();

}
function SuggestToFriend(_SendedEmail, _FromEmail, _SendedName, _FromName, _Nots) {



    try {
        $.ajax({
            type: "POST",
            url: "/Content/WebService/ClientSiteWebService.asmx/SuggestToFriend",
            data: "{SendedEmail:'" + $("#" + _SendedEmail).val() + "',FromEmail:'" + $("#" + _FromEmail).val() + "',FromName:'" + $("#" + _FromName).val() + "',SendedName:'" + $("#" + _SendedName).val() + "',Nots:'" + $("#" + _Nots).val() + "',Url:'" + location.href + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $.fancybox.close();
                alert(msg.d);
            },
            error: function (msg) {

                $.fancybox.close();
                alert(msg.d);
            }
        });

    } catch (e) {

    }
    return false;

}

var activeproductindex;

function PropSelection(itemid) {

    var clickitem = $("#" + itemid).children("img");
    if (clickitem.attr("class") == "PropActive") {
        clickitem.attr("class", "PropPassive");
        clickitem.attr("src", clickitem.attr("imguri"));
    }
    else {
        clickitem.attr("class", "PropActive");
        clickitem.attr("src", clickitem.attr("imguriactive"));
    }

    $(".kesif_detay > .right > .panel > .thumbs > ul > li").remove();

    var mids = "";

    $(".kesif_detay > .left > ul.thumbs > li > a > img.PropActive").each(function (index) {
        var eitem = $("#" + this.id);
        $(".kesif_detay > .right > .panel > .thumbs > ul").append("<li><img src='" + eitem.attr("imguriactive") + "' id='" + eitem.attr("mid") + "' alt='" + eitem.attr("alt") + "'/></li>");
        if ($(".kesif_detay > .left > ul.thumbs > li > a > img.PropActive").length > (index + 1)) $(".kesif_detay > .right > .panel > .thumbs > ul").append("<li class='seperator'></li>");
        mids += eitem.attr("mid") + "_";
    });

    if (mids.length > 0) GetProducts(mids);
}

function GetProducts(mids) {
    $(".kesif_detay > .right > .intro").hide();
    $(".kesif_detay > .right > .panel").show();

    activeproductindex = 0;
    $(".kesif_detay > .right > .panel > .product_info > .product_container").html("<img src='/content/images/preloading.gif' style='margin:100px 0 0 100px;' />'");
    $.ajax({
        type: "POST",
        url: "/Content/WebService/ClientSiteWebService.asmx/GetProductFromInfoBox",
        data: "{InfoIDS:'" + mids + "',SearchType:'" + $("#hfltype").val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            $(".kesif_detay > .right > .panel > .product_info > .product_container").html(msg.d);
            UpdateProductPageNumber();
        },
        error: function (msg) {
        }
    });
}

var scrollproduct = false;
function GetPrevProduct() {
    if (scrollproduct) return;
    if (activeproductindex <= 0) return;

    scrollproduct = true;

    var animitem = $(".kesif_detay > .right > .panel > .product_info > .product_container");

    var activeleft = parseFloat(parseFloat(animitem.css("left").replace("px", "")).toString().replace("NaN", "0"));
    if (activeleft == "") activeleft = 0;

    activeleft += 300;
    activeproductindex--;
    animitem.animate({ left: (activeleft.toString() + 'px') }, function () { scrollproduct = false; });
    UpdateProductPageNumber();
    
}

function GetNextProduct() {
    if (scrollproduct) return;
    if ((activeproductindex) >= ($(".kesif_detay > .right > .panel > .product_info > .product_container > .product_item").length - 1)) return;

    scrollproduct = true;

    var animitem = $(".kesif_detay > .right > .panel > .product_info > .product_container");
    var activeleft = parseFloat(parseFloat(animitem.css("left").replace("px", "")).toString().replace("NaN", "0"));
    if (activeleft == "") activeleft = 0;

    activeleft -= 300;
    activeproductindex++;
    animitem.animate({ left: (activeleft.toString() + 'px') }, function () { scrollproduct = false; });
    UpdateProductPageNumber();

    
}

function UpdateProductPageNumber() {
    var pager = $(".kesif_detay > .right > .panel > .page_number");
    var pagecount = $(".kesif_detay > .right > .panel > .product_info > .product_container > .product_item").length;
    if (pagecount > 0) pager.html((activeproductindex + 1) + "/" + pagecount);
    else pager.html("");
}

function setText(a, b) {
    x = document.getElementById(a);
    if (x)
        x.innerHTML = b.options[b.selectedIndex].innerHTML;
}

function setTextLoad(a, b) { 
    $('#' + a).text($('#' + b + " :selected").text());
}


function SearchDealer(cid, tid, vtype) {
    document.location.href = "/Page/Dealer/" + vtype + ".aspx?CID=" + $("#" + cid).val() + "&TID=" + $("#" + tid).val();
}

function MainSearchAutoComplete(inputid, hiddenfieldid) {
    if ($("#" + hiddenfieldid).val().length > 0) document.location.href = '/' + $("#" + hiddenfieldid).val();
    else MainSearch(inputid);
    return false;
}

function ClientValidate(source, arguments) {

    if ($("#ctl00_ContentPlaceHolder1_DrpUnit").val() == "4" && $("#ctl00_ContentPlaceHolder1_TxtSerialNo").val()=='')
        arguments.IsValid = false;
      else
       arguments.IsValid = true;
    
}

