﻿// JScript File
///<reference>scripts/pages/wwwreg/landing.js</reference>
var WWWLanding = function(BART, locale, offerCode, packageidClientId, offergroupidClientId){
	this.BART = BART;
	this.Locale = locale;
	this.OfferCode = offerCode;
    this.PackageidClientId = packageidClientId;
    this.OffergroupidClientId = offergroupidClientId;
	this.AspNetPrefix = String(packageidClientId).replace('packageid', '');
	$(this.PackageidClientId).name = 'packageid';
    $(this.AspNetPrefix+"offercode").name = 'offercode';
    $(this.OffergroupidClientId).name = 'offergroupid';
    this.UrlPrefix = 'https://www.peoplepc.com/newsignup/pages/';
    //this.UrlPrefix = 'http://spanish.peoplepc.com:3837/pages/';
}

WWWLanding.prototype.Init = function(){
	this.StopProgressBar();
    this.MakeCookie("MS", (this.OfferCode + "|" + this.OfferCode), 30);
}

WWWLanding.prototype.StartProgressBar = function() {
	try {
		if (this.BART && parent.startProgressBar) {
			parent.startProgressBar();
		}
	} catch (ignore) {}
}

WWWLanding.prototype.StopProgressBar = function() {
	try {
		if (this.BART && parent.stopProgressBar) {
			parent.stopProgressBar();
		}
	} catch (ignore) {}
}

WWWLanding.prototype.ReadCookie = function(Name) {
	var cookies = " " + document.cookie;
	if (cookies.indexOf(" " + Name + "=") == -1) return null;
	var start = cookies.indexOf(" " + Name + '=') + (Name.length + 2);
	var finish = cookies.substring(start,cookies.length);
	finish = (finish.indexOf(";") == -1) ? cookies.length : start + finish.indexOf(";");
	return unescape(cookies.substring(start,finish));
}

WWWLanding.prototype.DeleteCookie = function(Name) {
	var datenow = new Date();
	datenow.setTime(datenow.getTime() - Math.round(86400000));
	Expiry = datenow.toGMTString();
	document.cookie = Name + "=; expires=" + Expiry;
}

WWWLanding.prototype.MakeCookie = function(Name,Value,Expiry,Path,Domain) {
	if (Expiry != null && !isNaN(Expiry)) {
		var datenow = new Date();
		datenow.setTime(datenow.getTime() + Math.round(86400000*Expiry));
		Expiry = datenow.toGMTString();
	}
	Path = "; path=/";
	Domain = "; domain=.peoplepc.com";
	Expiry = (Expiry) ? "; expires=" + Expiry : "";
	document.cookie = Name + "=" + escape(Value) + Expiry + Path + Domain;
}

WWWLanding.prototype.HasCookies = function() {
	var bHasCookies = false;
	var sCookieName = 'HasCookies';
	this.MakeCookie(sCookieName, "true");
	if (this.ReadCookie(sCookieName) == 'true') {
		bHasCookies = true;
	}
	this.DeleteCookie(sCookieName);
	return bHasCookies;
}

//
// UI Functions
//

WWWLanding.prototype.TabClicked = function(tabName){
	var tabs = new Array('tab_offer','tab_compare','tab_features');
	for (var i=0; i<tabs.length; i++) {
		_setVisibility(this.AspNetPrefix + tabs[i], false);
	}
	_setVisibility(this.AspNetPrefix + tabName, true);
	function _setVisibility(aspNetTabName, visible) {
		var elem = $(aspNetTabName);
		if (elem) {
			var img = $(aspNetTabName+'_image');
			visible ? DOM.show(elem) : DOM.hide(elem);
			if (visible) {
				img.src = img.getAttribute("srcon");
			} else {
				img.src = img.getAttribute("srcoff");
			}
		}
	}
}

WWWLanding.prototype.SubmitPackage = function(packageid, offercode, offergroupid, locale) {
	if (!this.HasCookies()) {
		window.location.href = "Error.aspx";
		return false;
	}
	this.Locale = locale;
	this.StartProgressBar();
	if (packageid) {
		$(this.PackageidClientId).value = packageid;
	} else {
		packageid = $(this.PackageidClientId).value;
	}
	if (offergroupid) {
		$(this.OffergroupidClientId).value = offergroupid;
	} else {
		offergroupid = $(this.OffergroupidClientId).value;
	}
	return true;
}

WWWLanding.prototype.ComparePlans = function() {
	this.StartProgressBar();
	var pkg = $('ctl00_offers_packageid').value;
	if (this.Locale == "es-es") {
		window.location.href = 'Product/Details_es.aspx?lang=es-es&pkg='+pkg+'&pop=compare';
	} else {
		window.location.href = 'Product/Details.aspx?pkg='+pkg+'&pop=compare';
	}
}

WWWLanding.prototype.LearnMore = function() {
	this.StartProgressBar();
	var pkg = $('ctl00_offers_packageid').value;
	if (this.Locale == "es-es") {
		window.location.href = 'Product/Details_es.aspx?lang=es-es&pkg='+pkg;
	} else {
		window.location.href = 'Product/Details.aspx?pkg='+pkg;
	}
}

WWWLanding.prototype.ShowGetStartedPromo = function(spanId, promoText) {
	var totalOffset = 0;
	var s = $(spanId);
	var p = $('getstarted_promo');
	var pt = $('getstarted_promo_text');
	if (s && p && pt) {
		try { // align window with span
			while (s.tagName != 'BODY') {
				s = s.offsetParent;
				totalOffset += s.offsetTop;
			}
			p.style.left = 150;
			p.style.top = totalOffset;
			pt.innerHTML = promoText;
			DOM.show(p);
		} catch (ignore) {}
	}
}
		
WWWLanding.prototype.HideGetStartedPromo = function() {
	DOM.hide($('getstarted_promo'));
}

WWWLanding.prototype.ShowEspanol = function() {
	DOM.show($('div-espanol'));
}

WWWLanding.prototype.HideEspanol = function() {
	DOM.hide($('div-espanol'));
}
