﻿var lastLang = "";
//var similarsProds = new Array();
var prodArray = new Array();
var coordsProds = new Array();
var colorsProds = new Array();
var gridPrices = new Array();

function changeEntryLinks(selectedLang) {
    var hurl = $("#rawsUrl").val();
    if (lastLang == "") {
        $("a")
        .each(function () {
            this.href = "/" + selectedLang + hurl;
        });
    } else {
        $("a")
        .each(function () {
            this.href = this.href.replace("/" + lastLang + "/", "/" + selectedLang + "/");
        });
    }
    lastLang = selectedLang;
}

/** Array of Similar Products **/
var SimilarProducts = new Array();

/** Array of Coordinate Products **/
var CoordinateProducts = new Array();

/**
* Construct a new Product
*
* @constructor
*/

function Product(prodId, style, name, descrp, price, imgFile, cat) {
    this.ProductID = prodId;
    this.Style = style;
    this.Name = name;
    this.Description = descrp;
    this.Price = price;
    this.ImageFile = imgFile;
    this.CategoryID = cat;
}

var imgPopup;

function openZoom(imgName, size, msgSuffix) {
    if (imgPopup && !imgPopup.closed)
        imgPopup.location = "/Content/" + msgSuffix + "_Images/products/zoom/" + imgName;
    else {
        imgPopup = window.open("/Content/" + msgSuffix + "_Images/products/zoom/" + imgName, 'imageZoom', "width=870,height=960,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no");
    }

//    if (imgPopup && !imgPopup.closed)
//        imgPopup.location = "/Content/Images/products/zoom/" + imgName;
//    else {
//        imgPopup = window.open("/Content/Images/products/zoom/" + imgName, 'imageZoom', "width=870,height=960,resizable=yes,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no");
//    }

    if(size == 1)
        imgPopup.resizeTo(870,960);
    else if(size == 2)
        imgPopup.resizeTo(1000,1000);
    else if(size == 3)
        imgPopup.resizeTo(393, 612);

    imgPopup.focus();
//    if(size == 1)
//        imgPopup = window.open("/Content/Images/products/zoom/" + imgName, 'imageZoom', "width=870,height=960,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no");
//    else if(size == 2)
//        imgPopup = window.open("/Content/Images/products/zoom/" + imgName, 'imageZoom', "width=1000,height=1000,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no");
//    else if(size == 3)
//        imgPopup = window.open("/Content/Images/products/zoom/" + imgName, 'imageZoom', "width=393,height=612,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,copyhistory=no");
}

function changeMainImage(imgName, size, prodColor, price, fabric, itemID, msgSuffix) {
    $("#mainImage").attr("src", "/Content/" + msgSuffix + "_Images/products/product-detail/" + imgName);
    //$("#mainImage").attr("src", "/Content/Images/products/product-detail/" + imgName);
    //$("#openMainImage").attr("href", "/Content/Images/products/zoom/" + imgName);
    //$("#zoomMainImage").attr("href", "/Content/Images/products/zoom/" + imgName);
    $("#openMainImage").attr("href", "javascript:openZoom('" + imgName + "'," + size + ", '" + msgSuffix  + "')");
    $("#zoomMainImage").attr("href", "javascript:openZoom('" + imgName + "'," + size + ", '" + msgSuffix + "')");
    $("#downloadMainImage").attr("href", "/DownloadCenter/downloadImage/" + imgName);
    $("#mainColor").html(prodColor);
    $("#idItem").val(itemID);//EG
    if (price > -1)
        $(".price_table_container").html(gridPrices[price]); // (unescape(price)); 
    if (fabric != "")
        $("#Fabric").html("<b>" + fabric + "</b>");
    //else
      //  $(".price_table_container").html(mainPrice);
}

/**

check the size of the content vs the screen 
to resize the content so its 100% height

**/
function resizeContent() {
    //minimun size of content container
    $(".content").css('height', 'auto');
    var contentHeightReq = $(window).height() - ($('#footer').offset().top + $('#footer').outerHeight(true));
    if (contentHeightReq > 0) {
        $(".content").css('height', ($(".content").outerHeight(true) + contentHeightReq - 57) + 'px');
    }
}

function SafeHTML(S) {
    return S.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

function IsValidEmail(email) {
    var filter = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;

    return filter.test(email);
}

function IsValidPassword(password) {
    if (password.length > 0) return true;
    else return false;
}

function IsValidEmail(email) {
    pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

    return pattern.test(email)
}

//function setUrlGetPage(page) {
//    location.get = "page=" + page;
//    history.pushState(
//}

