﻿//-----------------------------------------------------------------------------
// Product Selection
//-----------------------------------------------------------------------------
var CurPrType = 0;
var CutProd = 0;

function prod_type_clicked(iTypeID,iNullPriceProdID) {

    if (CutProd != 0) {
        $("#prod_price_" + CutProd).hide();
        document.getElementById("prod_" + CutProd).checked = false;
        document.getElementById("ctl00_About_us_hidProdSelected").value = 0;
        document.getElementById("ctl00_About_us_hidProdTypeTypeSelected").value = 0;
    }
    if (CurPrType!=0)
    {
        $("#prodgroup_" + CurPrType).hide();
        $("#prtype_title_" + CurPrType).hide();
        $("#prtype_features_" + CurPrType).hide();       
    }

    if (iNullPriceProdID > 0) {
        //do not show product, precheck product
        document.getElementById("prod_" + iNullPriceProdID).checked = true;
        document.getElementById("ctl00_About_us_hidProdSelected").value = iNullPriceProdID;
        document.getElementById("ctl00_About_us_hidProdTypeTypeSelected").value = iNullPriceProdID;
    } else {
        $("#prodgroup_" + iTypeID).show();
    }
    $("#prtype_title_" + iTypeID).show();
    $("#prtype_features_" + iTypeID).show();

    CurPrType = iTypeID;
    document.getElementById("ctl00_About_us_hidProdTypeSelected").value = iTypeID;
}

function prod_clicked(iProdID) {
    if (CutProd != 0)
        $("#prod_price_" + CutProd).hide();

    $("#prod_price_" + iProdID).show();
    CutProd = iProdID;
    document.getElementById("ctl00_About_us_hidProdSelected").value = iProdID;
    document.getElementById("ctl00_About_us_hidProdTypeTypeSelected").value = 0;
}

function presetProd(type_id, type_type, prod_sel) {
    var prod_type_id = 0;
    var prod_type_type = 0;
    var prod_id = 0;
    if (document.getElementById(type_id)!=null)
        prod_type_id = document.getElementById(type_id).value;
    if (document.getElementById(type_type)!=null)
        prod_type_type = document.getElementById(type_type).value;
    if (document.getElementById(prod_sel) != null)        
        prod_id = document.getElementById(prod_sel).value;
    if (prod_type_id != 0) {
        prod_type_clicked(prod_type_id, prod_type_type);
        document.getElementById("prtype_" + prod_type_id).checked = true;        
    }
    if (prod_type_type == 0 && prod_id != 0) {
        prod_clicked(prod_id);
        document.getElementById("prod_" + prod_id).checked = true;        
    }
}

function checkSelection() 
{
    if (document.getElementById("ctl00_About_us_hidProdSelected").value == 0) {
        alert("Please choose your required product.");
        return false;
    }
    return true;
}

function echeckEML(str) {
    var at = "@";
    var dot = ".";
    var lat = str.indexOf(at);
    var lstr = str.length;
    var ldot = str.indexOf(dot);
	if (str.indexOf(at)==-1){alert("Invalid Email address");return false; }
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    alert("Invalid Email address");
	    return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid Email address");
	    return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid Email address");
	    return false;
	}
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid Email address");
        return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid Email address");
	    return false;
	}
	if (str.indexOf(" ")!=-1){
	    alert("Invalid Email address");
	    return false;
	}
	return true;
}

var lastwwdstbl = 0;
function doShowSendTofriend(blockid) {
    if ($("#wwdstbl_" + blockid).is(":visible")) {
        $("#wwdstbl_" + blockid).slideUp();
        return;
    }
    //hide last    
    if (lastwwdstbl != 0)
        $("#wwdstbl_" + lastwwdstbl).hide();
    //check current    
    
    $("#wwdstbl_" + blockid).slideDown();
    lastwwdstbl = blockid;
}

function doSendToFriend(blockid) {
    var sEml = document.getElementById("wwdstf_" + blockid).value;
    if (!echeckEML(sEml)) {
        document.getElementById("wwdstf_" + blockid).focus();
        return false;
    }
    //sending
    $.ajax({
        type: "POST",
        url: "/Srvc/main.aspx",
        data: "mn=surl2fr&freml=" + sEml + "&url=" + location.href,
        dataType: "json",
        success: function(msg) {
            $("#wwdstbl_" + blockid).slideUp();
        }
    });
}

//Popup VirtualTour
function doVTPop() {
    window.open('/virtual_tour.htm', "main", "width=700,height=500, top=100, left=100");
}
