﻿// JScript File
function removeSpaces(string) 
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	
	return tstring;
}

// used in registration 
function SetAmmount(val) 
{
    var objName = "" + "lblChosenSubscription"; 
    var obj = document.getElementById(objName); 
    if (obj == null )
        return; 
    obj.innerHtml = val; 
}
function humanSpoofing(sender, validator)
{       
        validator.IsValid = true;
        if (gebid('txtHV').value == "")
        {
            validator.IsValid = false;   
        }
        else    
        {
            validator.IsValid = gebid('hdIsCaptchaValid').value;
        }
}

function checkTermsAndCond(val, args) 
{
    args.IsValid = true;
    if (gebid('chkTerms') != null)
    {
        if (gebid('chkTerms').checked != true)
        {
            args.IsValid = false;
        }
    }
    else
    {//in case chk is inside a control then a variable chkTerms needs to be inserted into client script with the full name of the control.
        if (gebid(chkTerms).checked != true)
        {
            args.IsValid = false;
        }
    }
}

function checkSelectSubscription(val, args) 
{
    args.IsValid = true;
    if ( gebid(chkSubscriptions) != null && gebid(chkSubscriptionForEducators) != null 
        && gebid(chkSubscriptionForCompanies) != null && gebid(chkSelectCoursesSubscription) != null )
    {
        if (gebid(chkSubscriptions).checked != true)
        {
            if (gebid(chkSubscriptionForEducators).checked != true )
            {
                if (gebid(chkSubscriptionForCompanies).checked != true )
                {
                    if (gebid(chkSelectCoursesSubscription).checked != true )
                    {
                        args.IsValid = false;
                    }
                }
            }
        }
    }
}


function checkAccept(val, args) 
{
    args.IsValid = true;
    if (gebid('cbxAccept').checked != true)
    {
           args.IsValid = false;   
    }             
}

function tour_goto(menutour)
{

    selecteditem = menutour.ddlNewtour.selectedIndex ;
    ddlNewtour = menutour.ddlNewtour.options[ selecteditem ].value ;
    if (ddlNewtour.length != 0) {
        window.name = "ldc";
        window.open(ddlNewtour, 'tours', 'width=480, height=320')
    }
}

function video_goto( menuvid )
{
    selecteditem = menuvid.ddlVideoTours.selectedIndex ;
    ddlVideoTours = menuvid.ddlVideoTours.options[ selecteditem ].value ;
    if (ddlVideoTours.length != 0) {
        window.name = "ldc";
        window.open(ddlVideoTours, 'testimonials', 'width=480, height=318')
    }
}

 function joinNow()
{
    window.open('../home/registration/RegistrationStep1.aspx', 'ldc')
    window.close();
}

function setToIPValue(fromIPId, toIPId)
{
    document.getElementById(toIPId).focus();
    document.getElementById(toIPId).value = document.getElementById(fromIPId).value;
}

function showwindow_nonmember(url,width,height){
    var left = (screen.width/2)-(width/2);
    objMovieWindow=window.open(url, "trailers", "width=" + width + ", height=" + height + ", top=0, left="+left+", scrollbars=false"); 
    objMovieWindow.focus();
};

/* Client-side access to querystring name=value pairs Version 1.3 28 May 2008 License (Simplified BSD): http://adamv.com/dev/javascript/qslicense.txt */
function Querystring(qs)
{
	this.params = {};
	if(qs == null)
		qs = location.search.substring(1, location.search.length);
	if(qs.length == 0)
		return;
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&');
	for (var i = 0; i < args.length; i++) {
		var pair = args[i].split('=');
		var name = decodeURIComponent(pair[0]);

		var value = (pair.length==2)
			? decodeURIComponent(pair[1])
			: name;

		this.params[name] = value;
	}
}
Querystring.prototype.get = function(key, default_)
{
	var value = this.params[key];
	return (value != null) ? value : default_;
}
Querystring.prototype.contains = function(key)
{
	var value = this.params[key];
	return (value != null);
}

var external = {};
// methods dealing with adding the DirectTrack tracking pixels into the DOM.
external.directTrack = function()
{
	var baseUrl = "http://affiliates.lynda.com";
	return {
		click:function(bannerId) { var qs = new Querystring(); external.directTrack.addImage(baseUrl + "/tracking/js.html?aid=" + escape(qs.get("aid")) + "&bid=" + escape(qs.get("bid")) + "&bbid=" + bannerId + "&ref=" + escape(document.referrer)); },
		lead:function(bannerId, opt) { external.directTrack.addImage(baseUrl + "/lead/lynda/" + bannerId + "/" + opt); },
		sale:function(bannerId, products, documentId, opt) { external.directTrack.addImage(baseUrl + "/i_prod/lynda/" + products + "/" + documentId + "/" + opt + "&sale_status=a"); },
		//  + bannerId + "/"

		//addImage:function(url) { document.write('<img src="' + url + '" />'); }
		addImage:function(url) { var tag = document.createElement('img'); tag.src = url; var bd = document.getElementsByTagName("body")[0]; bd.appendChild(tag); }
	};
}();

function showDialog(control, visible)
{
    if (control)
        control.style.display = visible ? 'block' : 'none';
}

// Utilities
String.type = typeof String();
String.empty = new String();
String.replace = function()
{
	var _string = arguments[0];
	if(typeof _string !== String.type)
		return _string;
	if(arguments.length != 0)
		for(var i = 1, n = arguments.length; i !== n; i++)
			while(_string.indexOf(arguments[i]) !== -1){ _string = _string.replace(arguments[i],String.empty) };
	return _string;
};
String.format = function()
{
	if(arguments.length == 0)
		return null;
	var input = arguments[0];
	for(var a = 1, cnt = arguments.length; a < cnt; a++)
		input = input.replace(RegExp("\\{" + (a - 1) + "\\}", "gi"), arguments[a]);
	return input;
};

var utilities = {};
utilities.redirect = function(href)
{
	document.location.href = href;
};