﻿
//using this function on content pages to hide and expand the item
function toggleSwitch(DescID, SwitcherID) 
{
    var DescContent = document.getElementById(DescID);
    var Switcher = document.getElementById(SwitcherID);
    if (DescContent.style.display == "none") 
    {
        DescContent.style.display = "block";
        Switcher.src = "Images/minus.gif";
    }
    else
     {
        DescContent.style.display = "none";
        Switcher.src = "Images/plus.gif";
    }
}
//end.....

//using the function to remove the whte spaces
function RemoveSpaces(elementRef)
 {
    var regEx = /\s/g;
    elementRef.value = elementRef.value.replace(regEx, '');
}
//end...

//custom validator to check the quantity validation
function CheckValid(sender, args)
 {
    var Quant = args.Value;
    if (parseInt(Quant) <= 0)
     {
        args.IsValid = false;
    }
    else
     {
        args.IsValid = true;
    }
}
//end...

//custom validator to check the quantity validation for order project(live page)
function CheckValidOrderQty(sender, args)
 {
    var Quant = args.Value;
    if (parseInt(Quant) < 0) 
    {
        args.IsValid = false;
    }
    else 
    {
        args.IsValid = true;
    }
}
//end...

// to display the large image
function PreviewImage(ProofImage) {
  //debugger;
    var img = document.getElementById("imgPreview");
    img.src = "ProofImages/large_" + ProofImage;
    var lnk = document.getElementById("linkImage");
    lnk.href = "ProofImages/" + ProofImage;
    
}
//end...



//to display the large image
function PreviewImageTeam(ProofImage, folderName) {
   // debugger;
    var img = document.getElementById("imgPreview");
    img.src = folderName + "/large_" + ProofImage;
    var lnk = document.getElementById("linkImage");
    lnk.href = folderName + "/" + ProofImage;
}
//end


// to show the payment method
function checkPayment(val)
 {
     //debugger;
    document.getElementById("ctl00_ContentPlaceHolder1_hdPaymentType").value = val;
    
    document.getElementById("tblcc").style.display = "none";
    document.getElementById("tblbank").style.display = "none";
    document.getElementById("tblother").style.display = "none";
    document.getElementById("tblfirst").style.display = "none";
    document.getElementById("tblcheck").style.display = "none";
    document.getElementById("tblstudent").style.display = "none";
    document.getElementById(val).style.display = "block";
}
//end..



// to check the selected value, at least one item must be selected
function CheckQuantity(studentId, cardNo, CsvNo, BillAddress, BillCity, BillState, BillZip, BankName, BankAccName, AccNo, RotingNo, msg) {
   // debugger;
    try 
    {
        //debugger;
        var flagQuant = false;
        var objQuant = document.getElementsByTagName("input");
        var cntrPackage = document.getElementById('ctl00_ContentPlaceHolder1_dlsPackage');
        var cntrdlsSizes = document.getElementById('ctl00_ContentPlaceHolder1_dlsItems_ctl01_dlsSizes');
        if (cntrPackage == null)
         {
            if (cntrdlsSizes != null) 
            {
                for (var i = 0; i < objQuant.length; i++) 
                {
                    if (objQuant[i].type == "text") 
                    {

                        if (objQuant[i].name.toString().indexOf("dlsSizes") >= 0)
                         {
                            if (objQuant[i].value.length > 0 && objQuant[i].value != "0" && parseInt(objQuant[i].value) > 0)
                             {
                                flagQuant = true;
                            }
                        }
                    }
                }
            }

            if (flagQuant)
             {
                var flag = PaymentValidation(studentId, cardNo, CsvNo, BillAddress, BillCity, BillState, BillZip, BankName, BankAccName, AccNo, RotingNo);
                if (flag)
                 {
                    // Check Page Client Validation e.g. RequiredFieldValidator 
                    if (typeof (Page_ClientValidate) == 'function')
                     {
                        Page_ClientValidate();
                    }
                    // Check Page is valid or not
                    if (Page_IsValid) 
                    {
                        return true;
                    }
                    else
                     {
                        return false;
                    }
                }
                //return flag;
            }
            else
             {
                alert(msg);
                //                 
                return false;
            }
        }
        else 
        {
            var flag = PaymentValidation(studentId, cardNo, CsvNo, BillAddress, BillCity, BillState, BillZip, BankName, BankAccName, AccNo, RotingNo);
            if (flag)
             {
                // Check Page Client Validation e.g. RequiredFieldValidator 
                if (typeof (Page_ClientValidate) == 'function')
                 {
                    Page_ClientValidate();
                }
                // Check Page is valid or not
                if (Page_IsValid)
                 {
                    return true;
                }
                else 
                {
                    return false;
                }
                //return true;
            }
        }
    }
    catch (e)
     {
        //return true;
        alert(e);
    }
}
//end...

// to check the validation of credit card
function PaymentValidation(studentId, cardNo, CsvNo, BillAddress, BillCity, BillState, BillZip, BankName, BankAccName, AccNo, RotingNo)
 {

    if (document.getElementById("tblcc").style.display == "block")
     {
        var CCNo = document.getElementById(cardNo);
        var CsvNo = document.getElementById(CsvNo);
        var Address = document.getElementById(BillAddress);
        var City = document.getElementById(BillCity);
        var State = document.getElementById(BillState);
        var Zip = document.getElementById(BillZip);
        if (CCNo.value.length <= 0)
         {
            alert("Please enter credit card no.");
            CCNo.focus();
            return false;
        }
        else if (isNaN(CCNo.value))
         {
            alert("Please enter valid credit card no.");
            CCNo.focus();
            return false;
        }
        else if (CsvNo.value.length <= 0)
         {
            alert("Please enter csv no.");
            CsvNo.focus();
            return false;
        }
        else if (isNaN(CsvNo.value))
         {
            alert("Please enter valid csv no.");
            CsvNo.focus();
            return false;
        }
        else if (Address.value.length <= 0)
         {
            alert("Please enter your billing address.");
            Address.focus();
            return false;
        }
        else if (City.value.length <= 0)
         {
            alert("Please enter your city name.");
            City.focus();
            return false;
        }
        else if (State.value.length <= 0)
         {
            alert("Please enter your state name.");
            State.focus();
            return false;
        }
        else if (Zip.value.length <= 0)
         {
            alert("Please enter zip code.");
            Zip.focus();
            return false;
        }
        else 
        {
            return CheckSpecialCharOnSubmit();
        }
    }
    else if (document.getElementById("tblbank").style.display == "block")
     {
        var BankName = document.getElementById(BankName);
        var NameonAcc = document.getElementById(BankAccName);
        var AccNo = document.getElementById(AccNo);
        var RoutingNo = document.getElementById(RotingNo);

        if (BankName.value.length <= 0)
         {
            alert("Please enter bank name.");
            BankName.focus();
            return false;
        }
        else if (NameonAcc.value.length <= 0)
         {
            alert("Please enter the name on account.");
            NameonAcc.focus();
            return false;
        }
        else if (AccNo.value.length <= 0) 
        {
            alert("Please enter the account no.");
            AccNo.focus();
            return false;
        }
        else if (RoutingNo.value.length <= 0)
         {
            alert("Please enter the routing no.");
            RoutingNo.focus();
            return false;
        }
        else
         {
            return CheckSpecialCharOnSubmit();
        }

    }
    else if (document.getElementById("tblstudent").style.display == "block") 
    {
        var StudentID = document.getElementById(studentId);
        if (StudentID.value.length <= 0)
         {
            alert("Please enter student id.");
            StudentID.focus();
            return false;
        }
        else if (isNaN(StudentID.value))
         {
            alert("Please enter valid student id.");
            StudentID.focus();
            return false;
        }
        else
         {
            return CheckSpecialCharOnSubmit();
        }
    }

    else 
    {
        return CheckSpecialCharOnSubmit();
    }
   
}
//end...

//to check special char validation
function CheckSpecialCharOnSubmit()
 {
//debugger
    var flag = true;
    var objQuant = document.getElementsByTagName("input");
    for (var i = 0; i < objQuant.length; i++)
     {
         if (objQuant[i].type == "text")
         {
            var ctValue = objQuant[i].value;
            if (ctValue.indexOf("<") >= 0 || ctValue.indexOf(">") >= 0)
             {
                flag = false;
                objQuant[i].focus();
                break;
            }
        }
    }

    if (flag)
     {
        objQuant = document.getElementsByTagName("textarea");
        for (var i = 0; i < objQuant.length; i++)
         {
            var ctValue = objQuant[i].value;
            if (ctValue.indexOf("<") >= 0 || ctValue.indexOf(">") >= 0) 
            {
                flag = false;
                objQuant[i].focus();
                break;
            }
        }
    }

    if (flag)
     {
        return true;
    }

    else
     {
        alert("Invalid characters!");
        return false;
    }
}
//end..

//to check the term and condition of product for project revision
function CheckRevision(msg, proofMsg)
 {
    var flagCheck = true;
    var objQuant = document.getElementsByTagName("input");
    for (var i = 0; i < objQuant.length; i++)
     {
         if (objQuant[i].type == "checkbox")
         {
             if (objQuant[i].name.toString().indexOf("chkSubmitRevision") >= 0)
             {
                 if (!objQuant[i].checked)
                 {
                    flagCheck = false;
                    break;
                }
            }
        }
    }

    if (!flagCheck)
     {
        alert(msg);
        return flagCheck;
    }
    else
     {
        return flagCheck;
    }
}
//end..



//custom validator to check the valid image format
function checkImageType(sender, args) {

    var file = args.Value;
    var array = file.split(".");
    var filetype = array[array.length - 1].toLowerCase();
    //if (filetype == "" || filetype == "jpg" || filetype == "jpeg" || filetype == "gif" || filetype == "png") {
    if (filetype == "" || filetype == "jpg" || filetype == "jpeg" || filetype == "gif" || filetype == "png" || filetype == "psd" || filetype == "pdf") {

        args.IsValid = true;
    }
    else {
        args.IsValid = false;
    }
}

//end..

//to replace the all value
function replaceAll(str, from, to) {
    var idx = str.indexOf(from);


    while (idx > -1) {
        str = str.replace(from, to);
        idx = str.indexOf(from);
    }

    return str;
}
//end..

//to set the description help for web dialog window
function SetDesc(Artdes, cntDesc) {
    var Desc = Artdes;
    var ArtCnt = window.document.getElementById(cntDesc);
    Desc = replaceAll(Desc, "|", "'");
    Desc = replaceAll(Desc, '*', '"');
    Desc = replaceAll(Desc, '<br/>', '\r\n');
    ArtCnt.value = Desc;

}

function ShowWebDialWind(CntID) {
    var dialog = $find(CntID);
    dialog.show();
}

function HideWebDialWind(CntID) {
    var dialog = $find(CntID);
    dialog.hide();
}
//end...

//custom validation to check the phone length
function CheckLength(sender, args) 
{
    var phone = args.Value;
    if (phone.length != 10)
     {
        args.IsValid = false;
    }
    else
     {
        args.IsValid = true;
    }
}
//end...

//to put the text in web dialog window
function ShowInWebDialWind(CntWeb, CntContent, Desc) {
    var label = window.document.getElementById(CntContent);
    Desc = replaceAll(Desc, "|", "'");
    Desc = replaceAll(Desc, '~', '"');
    label.innerHTML = Desc;
    var dialog = $find(CntWeb);
    dialog.show();
}
//end..

//to check the no of organization to create a team
function CheckOrgStatus(msg)
 {
    var count = 0;
    var objQuant = document.getElementsByTagName("input");
    for (var i = 0; i < objQuant.length; i++)
     {
         if (objQuant[i].type == "checkbox") 
        {
            if (objQuant[i].name.toString().indexOf("chkSororities") >= 0 || objQuant[i].name.toString().indexOf("chkFraternities") >= 0)
             {
                 if (objQuant[i].checked)
                 {
                    count = count + 1;
                }
            }
        }
    }

    if (count >= 2) 
    {
        return true;
    }
    else 
    {
        alert(msg);
        return false;
    }
}
//end...

//custom validator to check the date with current date time
function CheckDate(sender, args) {
    var eventDate = Date.parse(args.Value.replace("-", "/"));
    var currentDate = new Date();
    if (eventDate < currentDate) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}
//end..


// to put the help functionality on edit product
var CntDisplay;

function SetDescEdit(Artdes) {
    var ArtCnt = window.document.getElementById(CntDisplay);
    var Desc = Artdes;
    Desc = replaceAll(Desc, "|", "'");
    Desc = replaceAll(Desc, '*', '"');
    Desc = replaceAll(Desc, '<br/>', '\r\n');
    ArtCnt.value = Desc;
}
function ShowWebDialWindEdit(CntID, DisplayID) {
    CntDisplay = DisplayID;
    var dialog = $find(CntID);
    dialog.show();
}

function HideWebDialWindEdit(CntID) {
    var dialog = $find(CntID);
    dialog.hide();
}
//end..

//custom validator to check the percent value
function CheckPercentValid(sender, args) {
    var price = args.Value;
    if (parseFloat(price) < 0) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}
//end...

//Using to validate the Delete buttons        
function confirm_delete(msg) {
    if (confirm(msg) == true)
        return true;
    else
        return false;
}
//end

//to open the new page
function OpenPage(pageurl) {
    window.open(pageurl);
}

//Using to validate the buttons        
function confirm_message(msg) {
    if (confirm(msg) == true)
        return true;
    else
        return false;
}
//end

//To check the school abbrevation length
function CheckSchoolAbbLength(sender, args) {
    var SchoolAbb = args.Value;
    if (SchoolAbb.length > 15) {
        args.IsValid = false;
    }
    else {
        args.IsValid = true;
    }
}

//To validate for enter numric value only 
function CheckIntOnly(CntName) {
    if (CntName.value.length > 0) {
        CntName.value = CntName.value.replace(/[^\d]+/g, '');
    }
}

//to open new window on button click (Server side)
function openNewWin(url) {
    var NewPage = window.open(url);
    NewPage.focus();
}


function SelectMeOnly(objRadioButton, grdName)
 {
    var i, obj;
    //example of radio button id inside the grid (grdAddress): grdAddress__ctl2_radioSelect
    for (i = 0; i < document.all.length; i++) 
    {
        obj = document.all(i);
        if (obj.type == "radio")
         {
            obj.checked = false;
        }
    }
    objRadioButton.checked = true; /* Finally making the clicked radio button CHECKED */
}

//to show/hide the proof detail on prospective page.
function ShowProof(RowClientId, ProofLinkId, VersionNo, ShowProof, HideProof) {
    if (document.getElementById(RowClientId + "0").style.display == "none") {
        document.getElementById(RowClientId + "0").style.display = "block";
        document.getElementById(RowClientId + "1").style.display = "block";
        document.getElementById(ProofLinkId).innerHTML = HideProof + VersionNo;
    }
    else {
        document.getElementById(RowClientId + "0").style.display = "none";
        document.getElementById(RowClientId + "1").style.display = "none";
        document.getElementById(ProofLinkId).innerHTML = ShowProof + VersionNo;
    }
}
//end..

//to blink the rows...
function doBlink() {
    var blink = document.all.tags("BLINK")
    for (var i = 0; i < blink.length; i++)
        blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
}

function startBlink() {
    if (document.all)
        setInterval("doBlink()", 500)
}
//end...

// to check that al least two organization should be selected for multigroup event
function OrgValidation(msg) 
{
    var count = 0;
    var objQuant = document.getElementsByTagName("input");

    for (var i = 0; i < objQuant.length; i++)
     {
        if (objQuant[i].type == "text")
         {
             if ((objQuant[i].name.toString().indexOf("txtChairPersonName") >= 0) && (objQuant[i].name.toString().indexOf("grdSororities") >= 0 || objQuant[i].name.toString().indexOf("grdFrarentites") >= 0))
             {

                count = count + 1;
            }
        }
    }

    if (count >= 2)
     {
        return true;
    }
    else
     {
        alert(msg);
        return false;
    }
}
//end...


//to check the email content
function CheckEmailContent(ControlId, Msg)
 {
    var ContentValue = document.getElementById(ControlId).value;
    if (ContentValue.length <= 0)
     {
        alert(Msg);
        return false;
    }
    else
     {
        return true;
    }
}


// To check the Package Quantity  for the Each Item
function QuantityCheck(Packgqty)
 {
    //debugger;
    try 
    {
        var qunt = 0;
        var ObjItemQty = document.getElementById(Packgqty); //.value;

        var cntrPackage = document.getElementById('ctl00_ContentPlaceHolder1_dlsPackage');        
        
            var cntrPackageSizes = document.getElementById('ctl00_ContentPlaceHolder1_dlsPackage_ctl01_dlsPackageSizes');
            if (cntrPackageSizes != null)
            {
                var id = 'ctl00_ContentPlaceHolder1_dlsPackage_ctl0';           
                var retVal = false;
                var ContList = document.getElementById('ctl00_ContentPlaceHolder1_ListCount');
                var c = 1;
                for (var j = 1; j <= ContList.value; j++)
                 {
                     if (c.toString().length == 1)
                      {
                            id = 'ctl00_ContentPlaceHolder1_dlsPackage_ctl0' + c + '_dlsPackageSizes';
                      }
                     else
                     {
                           id = 'ctl00_ContentPlaceHolder1_dlsPackage_ctl' + c + '_dlsPackageSizes';
                     }
                    var cntrId = document.getElementById(id);
                    c = c + 2;                
                    qunt = 0;
                    if (cntrId != null) 
                     {
                        var cells = cntrId.getElementsByTagName("input");
                        var ctlr;
                        for (var i = 0; i < cells.length; i++) 
                         {
                            if (cells[i].type == "text")
                              qunt += Number(cells[i].value);
                         }                   
                       if (parseInt(ObjItemQty.value) != parseInt(qunt))
                        {
                           alert("Total Package Sizes Entered quantity should be same as package quantity.");
                           return false;
                        }
                    }
                }
            }

        

        // To check the Package Quantity  is not manadatory
           if (cntrPackage != null)
              {
                  if (parseInt(ObjItemQty.value) == 0)
                   {
                      var cntrExtraSizes = document.getElementById('ctl00_ContentPlaceHolder1_dlsItems_ctl01_dlsSizes');
                      if (cntrExtraSizes != null)
                        {
                          var id = 'ctl00_ContentPlaceHolder1_dlsSizes_ctl0';
                          var retVal = false;
                          var ContList = document.getElementById('ctl00_ContentPlaceHolder1_ListCount');
                          var c = 1;
                          qunt = 0;

                          //for loop starts
                          for (var j = 1; j <= ContList.value; j++)
                            {
                                if (c.toString().length == 1) 
                                 {
                                     id = 'ctl00_ContentPlaceHolder1_dlsItems_ctl0' + c + '_dlsSizes';
                                 }
                                 else
                                 {
                                     id = 'ctl00_ContentPlaceHolder1_dlsItems_ctl' + c + '_dlsSizes';
                                 }

                                  var cntrId = document.getElementById(id);
                                  c = c + 2;
                                 
                                  if (cntrId != null) 
                                    {
                                       var cells = cntrId.getElementsByTagName("input");
                                       var ctlr;
                                       for (var i = 0; i < cells.length; i++)
                                        {
                                           if (cells[i].type == "text")
                                           qunt += Number(cells[i].value);
                                        }
                                     }
                               }
                               // for loop end

                               if (parseInt(qunt) == 0)
                                {
                                    alert("Please Enter the Package Item or Extra Item Quantity.");
                                    return false;
                                }
                         }
                        else
                         {
                             alert("Please Enter the Package Item Quantity.");
                             return false;
                        }                
                }
        }

        
        
        
        // Check Page Client Validation e.g. RequiredFieldValidator 
                 if (typeof (Page_ClientValidate) == 'function')
                 {
                   Page_ClientValidate();
                 }
        // Check Page is valid or not
               if (Page_IsValid)
               {
                 return true;
               }
             else 
              {
                 return false;
              }
    }
catch (ex)
     {
        
    }
}
//end...



/*
// To check the Package Quantity  for the Each Item
function QuantityCheckToUpdate(Packgqty) {
    try {
        var qunt = 0;
        var ObjItemQty = document.getElementById(Packgqty).value;

        var cntrPackageSizes = document.getElementById('ctl00_ContentPlaceHolder1_WebDialogWindowEditQuantity_Package_tmpl_dlsItems1');
        if (cntrPackageSizes != null) {
            var ContList = document.getElementById('ctl00_ContentPlaceHolder1_WebDialogWindowEditQuantity_Package_tmpl_ListCount');
            var c = 1;
            for (var j = 1; j <= ContList.value; j++) {
                id = 'ctl00_ContentPlaceHolder1_WebDialogWindowEditQuantity_Package_tmpl_dlsItems1_ctl0'+c+'_txtQty1';                
                var cntrId = document.getElementById(id);
                c = c + 1;
                qunt = 0;
                if (cntrId != null) {
                    var cells = cntrId.getElementsByTagName("input");
                    var ctlr;
                    for (var i = 0; i < cells.length; i++) {
                    if (cells[i].type == "text")
                            qunt += Number(cells[i].value);
                    }
//                    if (parseInt(ObjItemQty) != parseInt(qunt)) {
//                        alert("Total Package Sizes Entered quantity should be same as package quantity.");
//                        return false;
//                    }
                }
            }
        }      


        // Check Page Client Validation e.g. RequiredFieldValidator 
        if (typeof (Page_ClientValidate) == 'function') {
            Page_ClientValidate();
        }
        // Check Page is valid or not
        if (Page_IsValid) {
            return true;
        }
        else {
            return false;
        }
    }
    catch (ex) {

    }
}
//end...

*/


// Function to check digits after decimal point(.)
// This function puts only two digits after the decimal point
// Created By Satyendra Kumar on 03/10/2011

function CheckUnit(id) {
   // debugger;
    if (document.getElementById(id).value != "") {
        var a = parseFloat(document.getElementById(id).value);
        document.getElementById(id).value = a.toFixed(2);
    }
        
}

// This function alters the user about his or her Order end Date
// It only fires when current date is greater than order end date
// Create By Satyendra Kumar on 04/10/2011

function CheckOrderEndDate() {
    
    alert("Your Order End Date is over!");
}

