﻿//Added By :SJ
//Modified By : AJ
//Purpose : To disable error Icon while validating TextBox Mask Editor for Phone Number Mandatory and Non-Man
//Argument 3:true-Mandatory, false-Non-Mandatory
function getText(sValue, e, isMandatory) {
    if (sValue == "+(___)_________") {
        if (isMandatory) e.isValid = false;
        else e.isValid = true;
    }
}

//**********************Date Validation (Begins)***********************************************

//This script is to return the date to dd/MM/yyyy format
//Author Joyce A.
function GetFormatDate(currentDate) {
    if (currentDate != null) {
        var d = currentDate.getDate();
        var day = (d < 10) ? '0' + d : d;
        var m = currentDate.getMonth() + 1;
        var month = (m < 10) ? '0' + m : m;
        var y = currentDate.getFullYear();
        var Year = (y < 1000) ? y + 1990 : y;
        var rtnDate = new Date();
        rtnDate = (day + "/" + month + "/" + Year);
        return rtnDate;
    }
}

//Function Placed By : Joyce A.
function compareDate(fromDate, toDate) {
    var dtToday = new Date();
    var currentDate = dtToday.getDate() + "/" + (dtToday.getMonth() + 1) + "/" + dtToday.getFullYear();
    var arrayFromDate = fromDate.split("/");
    var arrayToDate = toDate.split("/");

    arrayFromDate[2] = isValidNumber(arrayFromDate[2]) == "0" ? dtToday.getFullYear() : arrayFromDate[2];
    if (arrayFromDate[2] > arrayToDate[2])
        return false;
    else if (arrayFromDate[2] < arrayToDate[2])
        return true;

    arrayFromDate[1] = isValidNumber(arrayFromDate[1]) == "0" ? (dtToday.getMonth() + 1) : arrayFromDate[1];
    if (arrayFromDate[1] > arrayToDate[1])
        return false;
    else if (arrayFromDate[1] < arrayToDate[1])
        return true;

    arrayFromDate[0] = isValidNumber(arrayFromDate[0]) == "0" ? dtToday.getDate() : arrayFromDate[0];
    if (arrayFromDate[0] > arrayToDate[0])
        return false;
    else if (arrayFromDate[0] < arrayToDate[0])
        return true;

    return true;
}


function isValidNumber(value) {
    var reg1 = /^[0-9]+$/;

    if (!reg1.test(value)) {
        return "0";
    }
    return value;
}


//******************************Date Compare Validation (Ends)************************************************

//*********************Script to set Maximum length for ASPXMemo control Begins*******************************
//Function placed by Joyce
function setMaxLength(textAreaElement, length) {
    textAreaElement.maxlength = length;
    ASPxClientUtils.AttachEventToElement(textAreaElement, "keyup", createEventHandler("onKeyUpOrChange"));
    ASPxClientUtils.AttachEventToElement(textAreaElement, "change", createEventHandler("onKeyUpOrChange"));
}
function onKeyUpOrChange(evt) {
    processTextAreaText(ASPxClientUtils.GetEventSource(evt));
}
function processTextAreaText(textAreaElement) {
    var maxLength = textAreaElement.maxlength;
    var text = textAreaElement.value;
    var isAcceptable = (maxLength == 0) || (text.length <= maxLength);
    if (maxLength != 0 && text.length > maxLength)
        textAreaElement.value = text.substr(0, maxLength);
}
function createEventHandler(funcName) {
    return new Function("event", funcName + "(event);");
}
//*******************************Memo Script Region Ends*******************************************************

//***********Validate Email*****************************
//function ValidateEmail(controlInstance) {
//    var rexp = new RegExp("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

//    if (controlID != null) {
//        var txtValue = controlInstance.value;
//        if (txtValue.match(rexp)) {
//            return true;
//        }
//        else alert('Enter valid email ID');
//    }
//}

function ValidateImg(ctrlname, lblctrl) {
    var img = document.getElementById(ctrlname);
    var ctrl = ctrlname;
    var imgCol = new Array();
    var imgName = new Array();
    var lblName = document.getElementById(lblctrl);
    imgCol = img.value.split(':');
    //If user Enter the path rather selecting then need to check
    if (imgCol[0].length > 0) {
        imgName = img.value.split('.');
        var fext = imgName[imgName.length - 1].toLowerCase();
        if (fext == "jpg" || fext == "jpeg" || fext == "png" || fext == "tif") {
            return true;
        }
        else {
            alert('[Select only jpg,jpeg,png,tif Images]');
            //Clearing in the IE browser
            if (navigator.appName.indexOf("Microsoft") != -1) {
                var who = document.getElementById(ctrl);
                var who2 = who.cloneNode(false);
                who2.onchange = who.onchange;
                who.parentNode.replaceChild(who2, who);
            }
            else //Clearing in the FireFox browser
            {
                document.getElementById(ctrl).value = "";
            }
            return false;
        }
    }
    else {
        ImgValidated(lblName.Text);
    }
}

function ImgValidated(img) {

    if (img != null) {
        imgName = img.value.split('.');
        var fext = imgName[imgName.length - 1].toLowerCase();

        if (fext != "") {
            if (fext == "jpg" || fext == "jpeg" || fext == "png" || fext == "tif") {
                return true;
            }
            else {
                alert('[Select only jpg,jpeg,png,tif Images]');
                //Clearing in the IE browser
                if (navigator.appName.indexOf("Microsoft") != -1) {
                    var who = document.getElementById(ctrl);
                    var who2 = who.cloneNode(false);
                    who2.onchange = who.onchange;
                    who.parentNode.replaceChild(who2, who);
                }
                else //Clearing in the FireFox browser
                {
                    document.getElementById(ctrl).value = "";
                }
                return false;
            }
        }
    }
}
function ValidateThumbImg(ctrlname) {
    var img = document.getElementById(ctrlname);
    var ctrl = ctrlname;
    var imgCol = new Array();
    var imgName = new Array();
    //var lblName = document.getElementById(lblctrl);
    imgCol = img.value.split(':');
    //If user Enter the path rather selecting then need to check
    if (imgCol[0].length > 0) {
        imgName = img.value.split('.');
        var fext = imgName[imgName.length - 1].toLowerCase();
        if (fext == "jpg" || fext == "jpeg") {
            return true;
        }
        else {
            alert('[Select only jpg,jpeg Images]');
            //Clearing in the IE browser
            if (navigator.appName.indexOf("Microsoft") != -1) {
                var who = document.getElementById(ctrl);
                var who2 = who.cloneNode(false);
                who2.onchange = who.onchange;
                who.parentNode.replaceChild(who2, who);
            }
            else //Clearing in the FireFox browser
            {
                document.getElementById(ctrl).value = "";
            }
            return false;
        }
    }
    else {
        return true;
    }
}
//----------------------------CD-----------------------------------//

/***********************************************************************************************
* Name      : validateImg
* Purpose   : To validate the image and the correct path in the client side
* Created BY: Joyce A
* Created on: 24thMay2011
* Note      : onchange="javascript:return ValidateImg(this,this.id)" to the FileUpload Control.
************************************************************************************************/
function ValidateImg(id, ctrlname) {
    var img = id;
    var ctrl = ctrlname;
    var imgName = new Array();
    var imgCol = new Array();
    imgCol = img.value.split(':');

    //If user Enter the path rather selecting then need to check 
    if (imgCol[0].length > 0) {
        imgName = img.value.split('.');
        var fext = imgName[imgName.length - 1].toLowerCase();
        if (fext == "jpg" || fext == "jpeg" || fext == "png" || fext == "gif") {
            return true;
        }
        else {
            //            var sMessage =window.parent.document.getElementById("ctl00_CphUp_hfAlertImage").value;
            //            alert(sMessage);
            alert('[Select only jpg,jpeg,png,gif Images]');
            //Clearing in the IE browser
            if (navigator.appName.indexOf("Microsoft") != -1) {
                var who = document.getElementById(ctrl);
                var who2 = who.cloneNode(false);
                who2.onchange = who.onchange;
                who.parentNode.replaceChild(who2, who);
            }
            else //Clearing in the FireFox browser
            {
                document.getElementById(ctrl).value = "";
            }
            return false;
        }
    }
    else {
        alert(objMsgs.InvalidAlert);
        //Clearing in the IE browser
        if (navigator.appName.indexOf("Microsoft") != -1) {
            var who = document.getElementById(ctrl);
            var who2 = who.cloneNode(false);
            who2.onchange = who.onchange;
            who.parentNode.replaceChild(who2, who);
        }
        else //Clearing in the FireFox browser
        {
            document.getElementById(ctrl).value = "";
        }
        return false;
    }
    //************************************************Nishar JS Ends******************************************

}





function ShowSurveyAlert() {
    var sMsg = confirm('Do you want to participate in the survey of GIORDANO?');
    if (!sMsg)
        window.location.href = "CustomerDashboard.aspx";
    else
        window.location.href = "Survey.aspx";

}

function HidePolicypopup() {
    window.parent.pcIssue.Hide();
    window.open("http://www.giordano-me.com");
}

function HideSecurePolicyPopup(sitename) {
    window.parent.pcSecure.Hide();
    window.open(sitename);
}

function HideDeliveryPolicyPopup(sitename) {
    window.parent.pcDel.Hide();
    window.open(sitename);
}

/**********************Predefined Gallery Script*****************************/

function ValidateHex(event) {
    var key;
    if (window.event)
        key = window.event.keyCode;
    else if (event)
        key = event.which;
    else
        return true;
    if ((key == null) || (key == 0) || (key == 8) ||
	        (key == 9) || (key == 13) || (key == 27))
        return true;

    if ((key >= 65 && key <= 70) || (key == 8) ||
            (key >= 97 && key <= 102) || (key == 35) || (key >= 48 && key <= 57))
        return true;
    else
        return false;
}
/**********************Predefined Gallery Script*****************************/

//------------------------Marking Script---------------------------
//Added by Joyce A.
//Added on 14th Feb 2011

var regionNum = 0;
var rName = 0;
var rNum = 0;

//This function is to send axis for new region,name region and number region from flash
function sendAxis(regionName) {
    var sSendValue = "";
    if (regionName == "Name") {
        regionName += rName;
        rName++;
        sSendValue = "0xff9966";
    }
    else if (regionName == "Number") {
        regionName += rNum;
        rNum++;
        sSendValue = "0x66ccff";
    }
    else
        sSendValue = "0xdcdcdc";

    if (navigator.appName.indexOf("Microsoft") != -1)
        document.getElementById('IEflash').sendRegions(sSendValue, regionName);
    else
        document.getElementById('flash').sendRegions(sSendValue, regionName);
}
//This function is to create new region
function btnNewAxis_onclick() {
    if (window.frames['frmMrk'] != null)
        window.frames["frmMrk"].ClrMsg();

    var RegionName = 'Region' + regionNum;
    sendAxis(RegionName);
    regionNum = (parseInt(regionNum) + 1);

}

//This function is to create new name region
function btnName_onclick() {
    //Name
    if (window.frames['frmMrk'] != null)
        window.frames["frmMrk"].ClrMsg();

    sendAxis('Name');
}

//This function is to create new number region
function btnNumber_onclick() {
    //Number
    if (window.frames['frmMrk'] != null)
        window.frames["frmMrk"].ClrMsg();

    sendAxis('Number');
}
function EnableSave() {
    btnSave.SetEnabled(true);
}

function btnSave_onclick() {
    if (window.frames['frmMrk'] != null)
        window.frames["frmMrk"].ClrMsg();
    btnSave.SetEnabled(false);
    var curleft = 0;
    var objDiv = document.getElementById("FlashDiv") //if the message is hidden by flash move to the right side
    if (objDiv.offsetParent) {
        curleft = objDiv.offsetLeft
        while (objDiv = objDiv.offsetParent) {
            curleft += objDiv.offsetLeft
        }
    }
    if ($find('programmaticModalPopupBehavior').get_X() < (curleft + 325))
        $find('programmaticModalPopupBehavior').set_X(curleft + 325);
    $find('programmaticModalPopupBehavior').set_Y((screen.availHeight / 2) - 100);
    $find('programmaticModalPopupBehavior').show();

    var ProductId = 0;
    var PhaseName = "";

    var service = document.getElementById("ctl00_cnt1_hfSer").value;
    var ProductId = document.getElementById("ctl00_cnt1_hidProductId").value;
    PhaseName = document.getElementById("ctl00_cnt1_hfFaceValue").value;

    var description = txtDes.GetText();  //document.getElementById("txtDes").value;
    if (navigator.appName.indexOf("Microsoft") != -1) {
        document.getElementById('IEflash').SaveObjects("$$$" + service + "$$$" + ProductId + "$$$" + PhaseName, description);
    }
    else {
        document.getElementById('flash').SaveObjects("$$$" + service + "$$$" + ProductId + "$$$" + PhaseName, description);
        //alert('over');
    }
}

//This function is to change the face accordingly when the user changes the face
//Modified by  : Nishar A.
// Modified on : 2008-11-08
function ShiftFace(sFace, id, iFaceCount) {

    //id = id.replace("ImgPhase","divface"); 
    var iCount = parseInt(iFaceCount);
    var iRow = 0;
    var ctrlID = "";

    var arrPhases = sFace.split("$$$");
    if (arrPhases[1] != document.getElementById("ctl00_cnt1_hfFaceValue").value) {
        if (arrPhases != null || arrPhases.length > 0) {
            document.getElementById("ctl00_cnt1_hfFaceValue").value = arrPhases[1];
            //alert(document.getElementById("ctl00_cnt1_hfFaceValue").value);
            getFlashObject().sendTShirt(arrPhases[0]);
        }
        for (iRow = 0; iRow < iCount; iRow++) {
            if (iRow < 10) {
                ctrlID = "ctl00_cnt1_rpnlFace_dlstProductFace_ctl0" + iRow + "_ImgFace";
            }
            else
                ctrlID = "ctl00_cnt1_rpnlFace_dlstProductFace_ctl" + iRow + "_ImgFace";
            if (ctrlID == id)
                document.getElementById(id).className = "phaseborder";
            else {
                if (document.getElementById(id) != null)
                    document.getElementById(ctrlID).className = "phaseborder1";
            }
        }
        //document.getElementById("txtDes").value = "";
        txtDes.SetText("");
    }
}
//This function is to load the marked image
function getImgName(status) {//added by sagayaraj on 02:38 pM 7/18/2008

    if (status != "error") {
        document.getElementById("frmMrk1").src = "Marking.aspx?test=" + Math.random();
        txtDes.SetText("");
    }
    $find('programmaticModalPopupBehavior').hide();
    //---------------------------------------
}

//This function is to create flash object
function getFlashObject() {
    if (navigator.appName.indexOf("Microsoft") != -1)
        return document.getElementById('IEflash');
    else
        return document.getElementById('flash');
}
var _AbsoluteURI = "";
function LoadSocialNetwork(id) {
    EnableFrame(id);
}
//This function helps in redirecting to opted site requested for.. to framework. But it will not work for few sites which is designed not to be loaded in frame
// ex,. gmail, google, yahoo mail etc.,
function EnableFrame(id) {
    var link = "";
    switch (id) {
        case 1: //FaceBook
            link = "http://www.facebook.com/giordanomiddleeast";
            break;
        case 2: //Twitter
            link = "http://twitter.com/GIORDANO_ME#";
            break;
        case 3: //BlogSpot
            link = "http://giordanomiddleeast.blogspot.com/";
            break;
        case 4: //LinkedIn
            link = "http://www.linkedin.com/company/1857221";
            break;
        case 5: //You Tube
            link = "http://www.youtube.com/giordanomiddleeast";
            break;
        default:
            break;
    }
    window.open(link);
}
function LoadPromotion(id) {
    window.location.href = "../StaticPages/Promotions.aspx?id=" + id;
}


// to Zoom personal gallery Image
function ZoomPersonalImg(ImgUrl, id) {
    sZoomId = id;
    document.getElementById("divImg1").innerHTML = "<img id='PersonalImage' onclick='hideImage();' src='" + ImgUrl + "' />";
    return false;
}
//Purpose    : Predefiend Gallery Move an element directly on top of another element (and optionally
// make it the same size)
function CoverPre(bottom, top, ignoreSize) {

    MovePanel(bottom, top, ignoreSize);
}
//Purpose    : Personal Gallery Move an element directly on top of another element (and optionally
// make it the same size)
function CoverPersonal(bottom, top, ignoreSize) {

    MovePanel(bottom, top, ignoreSize);
}

//to Move the panel 
function MovePanel(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation($get(sZoomId));
    top.style.position = 'absolute';
    top.style.top = 130 + 'px';
    top.style.left = 10 + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

//Purpose : to hide the image
function hideImage() {

    if (document.getElementById("info") != null)
        document.getElementById("info").style.display = "none";
    if (document.getElementById("info1") != null)
        document.getElementById("info1").style.display = "none";
}
// Click outside the box to hide it.
document.onclick = function(e) {
    if (document.getElementById("info") != null)
        document.getElementById("info").style.display = "none";
    if (document.getElementById("info1") != null)
        document.getElementById("info1").style.display = "none";
}



function CopyRightDialog() {
    tb_show("Copyright", "../User/Copyright.aspx?keepThis=false&TB_iframe=false&height=450&width=700", "");
}
function showuploadmsg(stitle) {
    tb_show(stitle, "../User/PictureUpload.aspx?keepThis=true&TB_iframe=false&height=90&width=270", "");
}
function hideuploadmsg() {
    tb_remove();
}
function ShowPreview(imageName, flag) {
    var imgNew = new Image();
    imgNew.src = (flag == 1 ? "../images/PersonalGallery/" : "../images/PredefinedGallery") + imageName;
    var imgWidth = imgNew.width + "px";
    var imgHeight = imgNew.height + "px";
    tb_show("Preview", "../User/ImagePreview.aspx?flag=" + flag + "&img=" + imageName + "&keepThis=false&TB_iframe=false&height=" + imgHeight + "&width=" + imgWidth + "", "");

}


function showDialog(message) {
    alert(message);
    location.href = "index.aspx";
    ShowDialog(true, message);
}


function ShowDialog(modal, message) {
    $("#overlay").show();
    $("#spMessage").html(message);
    $("#dialog").fadeIn(300);
    if (modal) {
        $("#overlay").unbind("click");
    }
    else {
        $("#overlay").click(function(e) {
            HideDialog();
        });
    }
}
