//This file contains JavaScript functions which could potentially be used by any partner -- i.e. they are not partner specific

//Get Daily Scope - From Drop Down Menus

function SubmitDailyScope()
{
	var form = document.dailyscope
	if(form.MM.options[form.MM.selectedIndex].value != "" && form.DD.options[form.DD.selectedIndex].value != "")
	{
		document.dailyscope.submit()
		return 1
	}
	return 0
}

//POP UP WINDOW FUNCTIONS

//Regular Pop Up

function popup(theURL,winName,features)
{
	remote=window.open(theURL,winName,features);
	if (remote.opener == null) remote.opener = window; 
	remote.opener.name = "opener";
	remote.focus();
}

//Delayed Pop Up

var theURL,winName,features  //These variables are required for setTimout to work

function delaypopup(delay,target,winTitle,parameters)
{
	theURL=target
	winName=winTitle
	features=parameters
	waitTime = delay * 1000
	setTimeout("popupglobalvars()",waitTime)
}

function popupglobalvars()
{
	remote=window.open(theURL,winName,features);
	if (remote.opener == null) remote.opener = window; 
	remote.opener.name = "opener";
	remote.focus();
}

//Random Pop Up Window

function randompopup(QueryStringArg)
{
	var NumberOfAds = 7;
	var now = new Date()
	var sec = now.getSeconds()
	var AdNumber = sec % NumberOfAds;
	AdNumber +=1;
	remote=window.open('/horoscopes/documents/popup_ad_0'+AdNumber+'.asp?ref='+QueryStringArg,'Ad','width=250,height=250');
	remote.opener = window; 
	remote.opener.name = "opener";
	remote.focus();
}

//LINKS IN POPUP WINDOWS

//The function handles all links inside popup. It targets the window "opener".
//If the "opener" window is closed, it creates it in the open call.
//If the "opener" window is open, it simply outputs the code there.

function gotoHref(szLink)
{
	win = window.open(szLink,"opener");
	window.close();
}

//Exit Popups

//Following default is defined outside function so it is global
var bExitFlow = true

function ExitPopup()
{	
	if (bExitFlow == true) {
		var ExitCount = GetExitCount();
		var nExitCount = new Number(ExitCount)
		//alert("count="+nExitCount);
		if (nExitCount < 3) { //i.e. user has seen popup less than 3 times
			if (nExitCount == 0) {
				setCookie('ACExitPopCount','1','/','November 23, 2010');
			} else {
				nExitCount++;
				setCookie('ACExitPopCount',nExitCount,'/','November 23, 2010');
			}
			popup('/horoscopes/SAF/signup.asp?ctc=1','DailyScopePopup','width=424,height=473,top=20,left=200,scrollbars=yes');
		}
		//readCookie();
	}
}

function GetExitCount()
{
	if (document.cookie == '') {
		return 0;
	} else {
		var curCookie = document.cookie;
		var cookie_location = curCookie.indexOf("ACExitPopCount");
		if (cookie_location == -1) {
			return 0;
		} else {
			return curCookie.charAt(cookie_location+15); //to get past "ACExitPopCount="
		}
	}
}

function SuppressExitPop() {
//Supresses Exit Popup when user clicks on upsell link in popup ad
	if (!opener.closed) {
		window.opener.bExitFlow=false;
	}
}

//Cookie Functions

function setCookie(name,value,path,expdate)
//required: name and value
//optional: path and expiration date (month dd, yyyy)
//          pass as null if not specifying a value
{
	var gmtexpdate = "";
	if (expdate != null) {
		gmtexpdate = new Date(expdate).toGMTString();
		gmtexpdate = ";expires=" + gmtexpdate;
	}
	var curCookie = name + "=" + escape(value) + ((path)?";path="+path:"") + gmtexpdate;
	document.cookie = curCookie;
}

function readCookie()
{
	var curCookie = document.cookie;
	alert("Cookie: " + curCookie)
}