var onLoadFunctions = [];
var callbacks = [];

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } //trim func
String.prototype.isEmpty = function(){
	return (this.trim()==null ||this.trim() ==''||this.trim()=='undefined'||this.length == 0 );	
}
Array.prototype.isEmpty = function(){
	return (this.length==0)
}
function addOnLoadFunction(func) {
   onLoadFunctions.push(func);
}

function insertOnLoadFunction(func) {
   onLoadFunctions.unshift(func);
}

function processOnLoad(func) {
   while ((func = onLoadFunctions.shift())) {
      eval(func);
   }
}

window.onload = processOnLoad;

function showDef(keyword) {
	var win = window.open(contextPath + 'keywords.html?type=def&keyword=' + keyword, 'definitions', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=515,height=300');
	win.focus();
}

function showQuestion(keyword) {
	var win = window.open(contextPath + 'keywords.html?type=que&keyword=' + keyword, 'definitions', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=515,height=300');
	win.focus();
}

function showTermsAndConditions(brandDelegateId) {
	var win = window.open(contextPath + 'keywords.html?type=tnc&keyword=tnc_' + brandDelegateId, 'termsAndConditions', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=550,height=500');
	win.focus();
}

function newWindow(url, w, h) {
	var win = window.open( url, '', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=1,width=' + w + ',height=' + h);
	win.focus();
}

function toggleRecurringLineItemPricing(classStr, arrowImgStr) {
	arrowImg = $(arrowImgStr);
	
	$$(classStr).each(function(elem) {
		elem.toggle();
		elemVisible = elem.visible();
	});
	
	if (arrowImg && typeof elemVisible != "undefined") {
		if (elemVisible) {
			arrowImg.writeAttribute('src', '/shared/img/icons/arows/down_arrow.jpg');
		} else {
			arrowImg.writeAttribute('src', '/shared/img/icons/arows/right_arrow.jpg');
		}
	}
}

function addLibrary(path, type){	
	var x = 0;
	var elem = null;
	if (type=="js"){ 
		elem = document.createElement("script");
		elem.setAttribute("type","text/javascript");
		elem.setAttribute("src", path);
	}
	else if (type=="css"){ 
		elem = document.createElement("link");
		elem.setAttribute("rel", "stylesheet");
		elem.setAttribute("type", "text/css");
		elem.setAttribute("href", path);
	}	
	if(elem != null && (typeof elem!='undefined')){
		document.getElementsByTagName("head")[0].appendChild(elem);
	}
	
	return elem;
}

function setCookie(cName,cValue,cDays){
	var exp = "";
	if (cDays) {
		var date = new Date();
		date.setTime(date.getTime()+(cDays*24*60*60*1000));
		var exp = "; expires="+date.toGMTString();
	}	 
	document.cookie = cName+"="+(cValue+"")+exp+"; path=/";
}

function getCookie(cName){
	var tmp = cName+"=";
	var x = 0;
	var cookies = document.cookie.split(';');
	for(x = 0;x < cookies.length;x++) {
		var cookie = cookies[x].trim();	
		if (cookie.indexOf(tmp) == 0){
			return cookie.substring(tmp.length,cookie.length);
		}		
	}
	return null;
}
function removeCookie(cName) {
	setCookie(cName,"",-1);
}

function JSONRequest(url, options) {
	index = callbacks.length;
	if (url.indexOf('?') < 0) {
		url += '?callback=' + index;
	} else {
		url += '&callback=' + index;
	}
	if (options) {
		var params = Object.clone(options.parameters);
		if (params = Object.toQueryString(params)) {
			url += '&' + params;
		}
	}
	url += '&timecode=' + (new Date()).getTime();
	elem = document.createElement("script");
	elem.setAttribute("type","text/javascript");
	elem.setAttribute("src", url);
	
	options.scriptTag = elem;
	callbacks[index] = options;
	
	document.getElementsByTagName("body")[0].appendChild(elem);
}

function executeCallback(index) {
	Element.remove(callbacks[index].scriptTag);
	callbacks[index].onSuccess(eval('jsonResponse' + index));
}

var DynamicUrls = Class.create({
	initialize: function(options) {
	    this.options = {}
	    Object.extend(this.options, options || { });
	},

	resolveUrl: function(url) {
		if (this.options.data.urls[url]) {
			dUrl = this.options.data.urls[url];
			result = '';
			if (dUrl.secure) {
				if (dUrl.secure == 'HTTPS') {
					result += 'https://';
				} else if (dUrl.secure == 'HTTP') {
					result += 'http://';
				} else {
					result += urlScheme;
				}
			} else {
				result += urlScheme;
			}
	
			if (dUrl.hostname) {
				result += dUrl.hostname;
			} else {
				result += urlHostname;
			}
	
			if (dUrl.port) {
				result += ":" + dUrl.port;
			} else if (!dUrl.hostname) {
				if (urlPort) {
					result += ":" + urlPort;
				}
			}
	
			result += url;
	
			return result;	
		}

		return url;
	}
});

function csc_f(){
	 var url = '/features/clearSessionReferrer.html';
	    new Ajax.Request(dynamicUrls.resolveUrl(url), {
	    	 parameters: "",
	         method: 'POST',
	         onSuccess: function(transport){
	    	 var r = transport.responseText;
	    	 	eval(r);
	    	 }
	    });
}

function cHsa_fx(){	
	if(location.href.indexOf("/shopping/") >0||location.href.indexOf("/checkout/")>0){
		if(window['ac_i_hsa']){
			document.getElementById("container").style.width="795px";
			if(document.getElementById("hsa_splash_menu_bar")){
				document.getElementById("hsa_splash_menu_bar").style.display = "none";
			}
			if(document.getElementById("progress-bar")){
				document.getElementById("progress-bar").style.margin="0px -9px 0px -9px";
			}
			initCanvases();
		}
		if($('menu')){
			var elems = $('menu').getElementsByClassName("menuItem ");		
			for(var x=0; x<elems.length;x++){
				var children = null;
				if(elems[x].childElements().length>0){
					var c = elems[x].onclick;
					children = elems[x].childElements();
					if(typeof children[0].href == 'string' && children[0].href.indexOf('referringdomain=')>-1){					
					//	children[0].href = 'javascript:void(0);';				
					}
				}
			}			
		}
	}
	if(window['ac_i_hsa']){	
		if($('expressSplashHome')){
			$('expressSplashHome').remove();
		}
		if($('localProvidersHead_canvas')){
			document.getElementById('localProvidersHead_canvas').display = 'none';
		}		
		if($('localProviders')){
			document.getElementById('localProviders').style.marginBottom = '10px';
		}
		if($('leftModule_a')){
			//document.getElementById('leftModule_a').style.marginLeft = '16px';
			document.getElementById('leftModule_a').style.width = '670px';
		}
		if($('contentMain')){
			document.getElementById('contentMain').style.width = '970px';
		}
		if($('outter_left')){
			document.getElementById('outter_left').style.width = '670px';
			document.getElementById('outter_left').style.marginBottom = '10px';
		}
		if($('LocationModule')){
			$('LocationModule').remove();
		}
		if($('splashLocationModuleContainer')){
			$('splashLocationModuleContainer').remove();
		}
		if($('TopPlanPanel')){
			$('TopPlanPanel').remove();
		}
		initCanvases();
	}
	if($('definitionBody')){		
		document.getElementsByTagName("body")[0].style.backgroundImage = "none";
		document.getElementsByTagName("body")[0].style.backgroundColor = "white";
	}
	
}
function trackSimplxLink(v1,v2,u){		
	if(typeof window["s"] == 'object'){		
		var args = $A(arguments);		
		var s=s_gi(s_account);		
		var ev = 0,m="";
//		var v1 = (typeof args[0]!=undefined)?args[0]:0, 
//				v2 = (typeof args[1]!=undefined)?args[1]:'0',
//					u =args[2];
		
		if(typeof v1=='number' && typeof v2=='string'){
			switch (v1){
				case 1:
					ev=43;m='Allconnect:SimplexityMobileInternet';
					break;
				case 2:
					ev=42;m='Allconnect:SimplexityMobilePhone';
					break;
				default:
					ev=0;
			}
			if(ev!=0){
				s.linkTrackEvents=("event"+ev+":"+v2);
				s.events=("event"+ev+":"+v2);
				s.tl(true,'o',m);		
			//	setTimeout(("window.location='"+ u+"'"),600);
			
			}
		}		
	}	

	return false;
}
if($('acSimplxPhone')){
	Event.observe($('acSimplxPhone'), 'click', trackSimplxLink.bindAsEventListener());
}
addOnLoadFunction("cHsa_fx();");

//3-13-11
