﻿var _orderCutted;
function ForgotPassword(emVal)
{var from=document.getElementById("txtEmail");if(from.value==""||from.value=="Email")
{ShowProcessing(false);alert("Please fill you email address");return;}
var Url="Sender.aspx?UserName=";Url+=from.value;Url+="&ForgotPass=1";postFile(Url,HandleSending);}
function postFile(pURL,pHandlerFunc)
{pParameters="";if(pURL.split("?").length>1)
pParameters=pURL.split("?")[1];if(window.XMLHttpRequest){xmlhttp=new XMLHttpRequest();xmlhttp.open("POST",pURL,false);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.send(pParameters);return pHandlerFunc(xmlhttp);}
else if(window.ActiveXObject)
{xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');if(xmlhttp)
{xmlhttp.open('POST',pURL,false);xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xmlhttp.send(pParameters);return pHandlerFunc(xmlhttp)}}}
function addScrollers(scrollBox, providedText) {
// code each scroller as follows:
// startScroll('id of scroller div','content of scroller');
startScroll(scrollBox,providedText);}
function ChangeScrollerSpeed(newSpeed) {
// code each scroller as follows:
// startScroll('id of scroller div','content of scroller');
speed = newSpeed;
clearInterval(interval);
if(speed == 0)
    speed = 0.1;
var interTime = 1000/speed;
interval = setInterval(function() {scrF(sTxt.style,sH,eH);}, interTime);}
var speed=15; // scroll speed (bigger = faster)
var dR=false; // reverse direction
var step = 2; 
var sTxt = null;
var sH = null;
var eH = null;
var interval = null;
function objWidth(obj) 
{if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;} 
function objHeight(obj) {if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;} 
function scrF(i,sH,eH){var x=parseInt(i.top)+(dR? step: -step); if(dR && x>sH)x=-eH;else if(x<2-eH)x=sH;i.top = x+'px';} 
function startScroll(sN,txt){var scr=document.getElementById(sN); var sW = objWidth(scr)-6; sH = objHeight(scr); scr.innerHTML = '<div id="'+sN+'in" style="position:absolute; left:3px; width:'+sW+';">'+txt+'<\/div>'; sTxt=document.getElementById(sN+'in'); eH=objHeight(sTxt); sTxt.style.top=(dR? -eH : sH)+'px'; sTxt.style.clip='rect(0,'+sW+'px,'+eH+'px,0)'; 
interval = setInterval(function() {scrF(sTxt.style,sH,eH);},1000/speed);}
function setCookie(c_name,value,expiredays)
{var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());}
function getCookie(c_name)
{if(document.cookie.length>0)
{c_start=document.cookie.indexOf(c_name+"=");if(c_start!=-1)
{c_start=c_start+c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1)c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}
return "";
}
function fixedTo(number, places) {
    var sNumber = number.toString();
    var nDecimalPointIndex = sNumber.indexOf('.');
    if (sNumber.length - nDecimalPointIndex == 3)
        return number;
    else if (number < 0.001)
        number = 0.001;
    var fixed = (number - 0.001).toFixed(2)
    return fixed;
}
function eraseCookie(name) {
    setCookie(name, "", -1);
}
function areCookiesEnabled() {
    var r = false;
    setCookie("testCookie", "test", 1);
    if (getCookie("testCookie") != "") {
        r = true;
        eraseCookie("testCookie");
    }
    return r;
}
function CommonRedirect(path, querryString) {
    if (querryString.length > 0)
    { path = path + "?" + querryString; }
    window.location.href = path;
}
function getQuerystring(key, _default) {
    if (key.length == 0)
       return location.search.substring(1);
    if (_default == null || _default == "undifined") _default = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return _default;
    else
        return qs[1];
}

// Show modal popup
function ShowModalPopup(strTitle, htmlBodyContent) {
    //Set message title, body and fade in the Popup
    $('.formTitle').html(strTitle);
    $('.msgBoxBody').html(htmlBodyContent);    
    $('.msgBoxContainer').fadeIn();

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('[id$=fade]').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
}
// Hide modal popup
function HideModalPopup() {
    $('.msgBoxContainer').fadeOut(function () {
        $('[id$=fade]').remove();
    });
    return false;
}
// Show Progress bar modal popup and run input function
function ShowProgressBarAndRunFunc(func) {
    $(".loading").show();    
    setTimeout(func, 1000);
    return true;
}
/*
function InitEmptyOrder() {
    strEncryptCookieVal = "";
    var parameters = '{strEncryptCookieVal: "' + strEncryptCookieVal + '"}';
    var webMethod = 'FunnelWebService.asmx/GenerateOrderFromEncryptCookie';
    $.ajax(
    { type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: webMethod,
        data: parameters,
        dataType: 'json',
        async: false,
        success: function (data) {
            _orderCutted = data.d;
        }
    });
}
*/
function EmailAlphaNumericValidatorWithCorrection(sender)
{
    if (sender.value.match(/[^a-zA-Z0-9_!@#$%&*+-=? ]/g)) {
        sender.value = sender.value.replace(/[^a-zA-Z0-9_!@#$%&*+-=? ]/g, '');
    }
}

function AlphaNumericValidatorWithCorrection(sender) {
    if (sender.value.match(/[^a-zA-Z0-9 ]/g)) {
        sender.value = sender.value.replace(/[^a-zA-Z0-9 ]/g, '');
    }
}

function EmailAlphaNumericValidator(currentValue) {
    if (currentValue.match(/[^a-zA-Z0-9_!@#$%&*+-=? ]/g)) {
        return false;
    }
    return true;
}

function AlphaNumericValidator(currentValue) {
    if (currentValue.match(/[^a-zA-Z0-9 ]/g)) {
        return false;
    }
    return true;
}

function GetCurrencySymbolByName(strCurrencyCode) {
    var strCurrencySymbol = "";
    switch (strCurrencyCode) {
        case "USD": strCurrencySymbol = "$"; break;
        case "EUR": strCurrencySymbol = "&euro;"; break;
        case "GBP": strCurrencySymbol = "&pound;"; break;
        default: strCurrencySymbol = strCurrencyCode; break;
    }
    return strCurrencySymbol;
}
function FormatPrice(num, strCurrencyCode) {
    var strCurrencySymbol = GetCurrencySymbolByName(strCurrencyCode);
    //num = parseFloat(Math.abs(num)).toFixed(2);
    if (strCurrencyCode == strCurrencySymbol)
        return (num < 0 ? "-" : "") + parseFloat(Math.abs(num)).toFixed(2) + '&nbsp;' + strCurrencySymbol;
    else
        return (num < 0 ? "-" : "") + strCurrencySymbol + parseFloat(Math.abs(num)).toFixed(2);
}

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{
		    string: navigator.userAgent,
		    subString: "Chrome",
		    identity: "Chrome"
		},
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari",
		    versionSearch: "Version"
		},
		{
		    prop: window.opera,
		    identity: "Opera",
		    versionSearch: "Version"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "Explorer",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.userAgent,
		    subString: "iPhone",
		    identity: "iPhone/iPod"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();

function RedirectToFunnel(nPackID, nPlanID, nPayPeriod) {    
    $.ajax(
    { type: 'POST',
        contentType: 'application/json; charset=utf-8',
        url: "http://" + location.hostname + '/WIServices.asmx/BuildPackPurchaseOrder',
        data: '{nPackID: "' + nPackID + '", nPlanID: "' + nPlanID + '", nPayPeriod: "' + nPayPeriod + '"}',
        dataType: 'json',
        success: function (data) {            
            window.location = "https://" + location.hostname + "/check_out.aspx?dbOrder=" + data.d;
        },
        error: function (request, status, error) {
            alert(request.responseText);
        } 
    });
}





                  

