﻿
var bInitHpSlider = false;


$(document).ready(function($) {

  
   
    // load hp slider only if flag set to true (in HPSLIDER ascx)
    if (bInitHpSlider) {
        initHomepageSliders();
    }

    // popup lisght box for gallery show of albums
    $("a.product-preview").fancybox({});

    // popup lisght box for gallery show of albums
    $("a.product-preview").fancybox({});


    $("a.downloadApp").fancybox({
        'width': 350,
        'height': 250,
        'autoScale': true,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'type': 'iframe'

    });

    $("a.showTerms").fancybox({
        'width': 550,
        'height': 450                     
    });





});


function somefunction() {
        alert($this);
    };


function initHomepageSliders() {
   
    $('#slider').cycle({
        fx: 'scrollVert',
        speed: 1000,
        pause: 1,
        timeout: 10000,
        cleartypeNoBg: true,
        delay: 500,
        prev: '#slider_next',
        next: '#slider_prev'
    });


    $('#gallery-slider').cycle({
        fx: 'scrollHorz',
        speed: 500,
        pause: 1,
        timeout: 7000,
        cleartypeNoBg: true,
        delay: 500,
        prev: '#gallery-sliderNavLeft',
        next: '#gallery-sliderNavRight'
    });

}


function calculateprice(oSelctbox, iAlbumID, iPrecentageDiscount) {
   
    if (oSelctbox.length == 0) {
        return;
    }

    var iSelectedIndex = oSelctbox.selectedIndex;
    var iPages = oSelctbox[iSelectedIndex].text;
    var iPrice = oSelctbox.options[iSelectedIndex].value;
    var iTotal;

    if (iPrecentageDiscount > 0) {
        iTotalDiscount = (parseInt(iPrice) * parseInt(iPrecentageDiscount)) / 100;
        iTotal = Math.round(parseInt(iPrice) - iTotalDiscount);
    }

    $('#spnPages' + iAlbumID).html(iPages);
    $('#spnPrice' + iAlbumID).html(iPrice);
    $('#spnOldPrice' + iAlbumID).html(iPrice);
    $('#spnafterDiscountPrice' + iAlbumID).html(iTotal);

}

function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}


function ReplaceQueryString(url, param, strValue) {


    

    var preURL = "";
    var postURL = "";
    var newURL = "";

    var iStart_case_1 = url.indexOf("?" + param + "=");
    var iStart_case_2 = url.indexOf("&" + param + "=");


    if (url.indexOf("?") == -1) {
        postURL = "?" + param + "=" + strValue;
    }
    else {

        if (iStart_case_1 == -1 && iStart_case_2 == -1) {
            preURL = url;
            postURL = "&" + param + "=" + strValue;
        }
        else {
            var iStart;
            if (iStart_case_1 > -1) {
                iStart = iStart_case_1 + 1;
            }
            else {
                iStart = iStart_case_2 + 1;
            }

            var iEnd = url.indexOf("=", iStart);
            preURL = url.substring(0, iEnd) + "=" + strValue;

            var iStartRest = url.indexOf("&", iStart);
            postURL = "";
            if (iStartRest > -1) {
                postURL = url.substring(iStartRest);
            }
        }
            
    }

    

    newURL = preURL + postURL;

    return newURL;
}

