var sessionid = '211053238';
var sitetrack = 'self';
var engineroot = 'http://www.alwaysgoodphonecard.com';
var engineurl = 'http://www.alwaysgoodphonecard.com/include/';
var siteurl = 'http%3A%2F%2Fwww%2Ealwaysgoodphonecard%2Ecom%2F';
var sitename='alwaysgoodphonecard.com';
var cart='http://www.alwaysgoodphonecard.com/Shopping_Cart/';
var users = 1;
var products = 2496;
var version = 'CyberBuild  4.2.61';
//These variables are set in initial.asp codes
//var sessionid = "";
//var sitetrack = "";
//var engineurl = "";
//var engineroot = ""; 
//var siteurl = "";
//var sitename="";
//var cart = "";
//var version = "";
var page;
if (window.sessionid && window.parent && window.parent.sessionid)
{
	window.sessionid = window.parent.sessionid;
}	
var brVer = getversion();

var DEFER_TAG = "DEFER", DEFER_CNT = 0
var regDEFER_EXCL = /((custom10.asp)|(custom13.asp)|(custom17.asp)|(_login_))+/i;
	//This excludes the pages in deferred loading. 
	//Either upldate the dynamic custom10.asp, custom13.asp or exlude them from DEFER.
	//(Must also update config.asp to include DocumentWrite() subroutine)

if (brVer > 0 && document.getElementById && window.version && version.length) DEFER_CNT++;

function getversion()
{
var ua = window.navigator.userAgent;
var msie = ua.indexOf ( "MSIE " );
	if ( msie > 0 )        // is Microsoft Internet Explorer; return version number
		return parseFloat ( ua.substring ( msie+5, ua.indexOf ( ";", msie ) ) );
	else
		return 0;
}

function getinsert(sURL)
{
	sURL = sURL.replace(' ', '');
	sURL = sURL.replace('\t', '');
	sURL = sURL.replace('\r', '');
	sURL = sURL.replace('\n', '');
	
	if (sURL.length == 0) return;
	if (sURL.indexOf("://") < 0)
	{
		if (sURL.charAt(0) == "/")
			sURL = engineroot + sURL;
		else
			sURL = engineurl + sURL;
	}	
	if (sURL.indexOf("?") < 0 )
		sURL += "?";
	else
		sURL += "&";
	sURL += "id=" + sessionid + "&track=" + sitetrack;
	if (siteurl.length > 0)
		sURL += "+" + siteurl;
	return sURL;
}

function insertpage(sURL)
{
	if (sURL != null && sURL.length)
	{
		sURL = getinsert(sURL);
		sURL += "&rnd=" + Math.round(Math.random()*100000);
		deferInsert(sURL);
	}
}

function insertstatic(sURL)
{
	if (sURL != null && sURL.length)
	{
		sURL = getinsert(sURL);
		var sStr = "" + window.location;
		sStr = sStr.toLowerCase();
		if (sStr.indexOf('rnd=') > 0) sURL += "&rnd=" + Math.round(Math.random()*100000);
		deferInsert(sURL);
	}
}

function deferInsert(sURL)
{
	if (!window.DEFER_CNT || regDEFER_EXCL.test(sURL))
	{
		document.write('<' + 'script src="' + sURL + '"></' + 'script>\r\n');
	}
	else
	{
		var def = DEFER_TAG + '_' + DEFER_CNT;
		document.write('<SPAN id="' + def + '"></SPAN>');
		document.write('<' + 'script src="' + sURL + '&defer_id=' + def + '" defer></' + 'script>\r\n');
		DEFER_CNT++;
	}
}

function createpopup(page,s_title)
{
	CreatePopup(page,s_title);
}

function CreatePopup(page,s_title)
{
var sOptions, wnd = null;
	sOptions = "toolbar=no,location=no,directories=no,";
	sOptions += "left=" + (screen.width-550) + 
				",width=500,height=450,scrollbars=yes,resizable=yes,menubar=no,status=yes";
	if (page.length)
	{
		var page1 = page.toLowerCase();
		if (page1.indexOf('.asp') > 0 && page1.indexOf('goback') < 0)
		{
			if (page.indexOf("?") < 0)
				page += ("?GoBack=" + escape(window.location));
			else
				page += ("&GoBack=" + escape(window.location));
		}
	}

	if (!window.myStyle || myStyle.indexOf('&popup=no') < 0)
		wnd = window.open("",s_title,sOptions);

	if (wnd == null) wnd = window;
	if (page.length) wnd.location = page;
	wnd.focus();
}

function getcookie(sCookie)
{
var i, sItem, sKey, sValue, sCookies;
	sCookies = document.cookie;
	sValue = "";
	while (sCookies.length)
	{
		i = sCookies.indexOf(";");
		if (i >= 0)
		{
			sItem = sCookies.substring(0,i);
			sCookies = sCookies.substring(i+2,sCookies.length); 
		}
		else
		{
			sItem = sCookies;
			sCookies = "";
		}
		if (sItem.length)
		{
			i = sItem.indexOf("=");
			if(i > 0)
			{
				sKey = sItem.substring(0,i);
				sValue = sItem.substring(i+1,sItem.length);
				if (sKey == sCookie && sValue.length > 0)
				{
					return unescape(sValue);
				}
			}
		}
	}	
	return "";
}

function setcookie(sKey, sValue, iDays)
{
var obDate = new Date();
	obDate.setDate(obDate.getDate() + iDays);
var expire = "expires=" + obDate.toGMTString();
var path = "path=/";
var sCookie;
	sCookie = sKey + "=" + escape(sValue);
	if (iDays != 0) sCookie += ";" + expire;
	sCookie += ";" + path;
	document.cookie = sCookie;
}

function viewshop(sPage, sFrame)
{
	view_shop(sPage, sFrame);
}

function view_shop(sPage, sFrame)
{
var wnd = null;
	if (window.setAffiliate2) setAffiliate2();
	if (sFrame.length > 0)
		wnd = window.top.frames[sFrame];
	if (wnd == null)
		wnd = window;
	sPage =  cart + sPage;
	if (sPage.indexOf("?") < 0)
		sPage += ("?GoBack=" + escape(wnd.location));
	else
		sPage += ("&GoBack=" + escape(wnd.location));
	sPage +=  "&SessionID=" + sessionid;
	sPage +=  "&rnd=" + Math.round(Math.random()*100000);
	wnd.location = sPage;
}

function submitform(sForm, sURL)
{
var sStr, i, bUnicode, wnd;
var frm = null;
	if (window.setAffiliate2) setAffiliate2();

	for (i = 0; i < document.forms.length; i++)
	{
		if (document.forms[i].name == sForm)
		{
			frm = document.forms[i];
			break;
		}
	}
	if (frm == null) 
	{
		alert("Cannot find form: " + sForm + "!");
		return;
	}
	
	if (sURL.length == 0) sURL = frm.action;
	if (sURL.length == 0 || 
		sURL.lastIndexOf("/") == (sURL.length - 1)) sURL = "engine.asp";

	if (sURL.indexOf("://") < 0)
	{
		if (sURL.indexOf("/") == 0)
			sURL = engineroot + sURL;
		else
		{
			if (engineurl.length == 0)
				engineurl = "include/";
			sURL = engineurl + sURL;
		}
	}	
	frm.action = sURL;	
	if (frm.ID != null) frm.ID.value = sessionid;
	if (frm.Rnd != null && 
		(frm.Rnd.value.length == 0 || frm.Rnd.value == '0'))
		frm.Rnd.value = Math.round(Math.random()*100000);

	if (frm.onsubmit && frm.onsubmit() == false) return;
	
	if (frm.Page != null &&
		(frm.method.length == 0 || frm.method.toLowerCase() == "get") && 
		(frm.target.length == 0 || frm.target.toLowerCase() == "_self" 
		|| frm.target.toLowerCase() == "_parent"))

	{
		sURL = frm.action;
		bUnicode = false;		
		for (i = 0; i < frm.elements.length; i++)
		{
		var ctl = frm.elements[i];
		var sType = ctl.type;
		if (ctl.name && ctl.name.length > 0)						
		{
			sStr = "";
			if (sType.indexOf('text') >= 0 || sType.indexOf('hidden') >= 0) 
				sStr = ctl.value;
			else if ((sType.indexOf('radio') >= 0 ||
					sType.indexOf('checkbox') >= 0) && 
					ctl.checked == true) 
			{
				sStr = ctl.value;
			}
			else if (sType.indexOf('select') >= 0 ||
					ctl.options != null)
			{
				sStr = ctl.options[ctl.selectedIndex].value; 
				if (!sStr.length)
					sStr = ctl.options[ctl.selectedIndex].text;
			}
			if (sStr.length > 0 && ctl.name.length > 0)
			{
				if (sURL.indexOf('?') < 0)
					sURL += "?"
				else
					sURL += "&"
				sStr = escape(sStr);
				if (sStr.indexOf('%u') == 0) bUnicode = true;
				sStr = sStr.replace('+', '%2B');
				sURL += frm.elements[i].name + "="  + sStr;
			}
		}
		}
		sURL += "&track=" + sitetrack + "+" + siteurl; 

//		Developer: Use the following popup to determine the URL that 
//		links to a specific category. Comment it out when done.
//		alert(sURL + "; unicode=" + bUnicode);
		if (frm.target.toLowerCase() == "_parent")
			wnd = window.parent;
		else
			wnd = window;
		if (!bUnicode)
			wnd.location = sURL;
		else
			frm.submit();
	}
	else
		frm.submit();
}

function addtocart(sProd)
{
var sURL = "";
	if (window.setAffiliate2) setAffiliate2();
	if (sProd.length == 0) return;
	sProd = escape(sProd);
	sURL = engineurl + "engine.asp?action=shop" + "&prod=" 
			+ sProd + "&catno=" + sProd + "&id=" + sessionid;
	sURL += "&track=" + sitetrack + "+" + siteurl; 
	sURL += "&back=" + escape(window.location);
	sURL += "&rnd=" + Math.round(Math.random()*100000);
	window.location = sURL;
}

function viewdetail(sProd)
{
	showdetail(sProd);
}

function showdetail(sProd)
{
var sURL = "";
	if (window.setAffiliate2) setAffiliate2();
	if (sProd.length == 0) return;
	sProd = escape(sProd);
	sURL = engineurl + "engine.asp?action=detail" + "&prod=" 
			+ sProd + "&catno=" + sProd + "&id=" + sessionid;

	if (window.my_detail != null)
		sURL += "&page=" + escape(my_detail); 

	sURL += "&track=" + sitetrack + "+" + siteurl; 
	sURL += "&rnd=" + Math.round(Math.random()*100000);
	window.location = sURL;
}

function list(sPage)
{
	linkpage(sPage, "list");
}

function linkpage(sPage, sAction)
{
var sURL = "";
	if (window.setAffiliate2) setAffiliate2();
	if (sPage.indexOf(siteurl) < 0 && sPage.indexOf("://") < 0
		&& sPage.charAt(0) != "/")
		sPage = siteurl + sPage;

	sURL = engineurl + "engine.asp?action=" + sAction + "&" + "page=" 
		+ sPage + "&id=" + sessionid;
	sURL += "&track=" + sitetrack + "+" + siteurl; 
	sURL += "&rnd=" + Math.round(Math.random()*100000);
	window.location = sURL;
}

function quickcart(sParams)
{
var sURL = "", sCurrURL;
	if (sParams.length == 0) return;
	sURL = cart + "view_stock.asp?" + sParams;
	sCurrURL = "" + window.location;
	sCurrURL = sCurrURL.toLowerCase();
	if (sCurrURL.indexOf('.asp') < 0 || sCurrURL.indexOf('view_cart.asp') >= 0)
		sURL += "&SessionID=" + sessionid;
	if (sParams.indexOf('login') < 0) 
		sURL += "&rnd=" + Math.round(Math.random()*100000);
	//document.write('<' + 'script src="' + sURL + '"></' + 'script>\r\n');
	deferInsert(sURL);
}
function hideTEXT(sTagID) 
{
var sHide = "hidden", ctrl = null;
	if (document.getElementById)
	{
		ctrl = document.getElementById(sTagID);
		if (ctrl) ctrl = ctrl.style;
	}
	else
	{
		if (document.layers)
		{ //NS4
			eval("ctrl = document." + sTagID);
		}
		else 
		{ //IE4
			ctrl = document.all.item(sTagID);
			if (ctrl) ctrl = ctrl.style;
		}
	}
	if (ctrl) ctrl.visibility = sHide;
}
var page = "";
window.top.focus();

var sitebanner = "assets/logo1.gif";

