/**
 * COOKIE LIBRARY CLASS
 */

var CookieDataStore = function () {

};


CookieDataStore.prototype = {

    save : function (cookie) {
        var cookieData = [];
        cookieData.push(cookie.name + "=" + encodeURIComponent(cookie.value));
        if (cookie.expires) {
            cookieData.push("expires=" + cookie.expires.toGMTString());
        }
        if (cookie.path) {
            cookieData.push("path=" + cookie.path);
        }
        if (cookie.domain) {
            cookieData.push("domain=" + cookie.domain);
        }
        if (cookie.secure) {
            cookieData.push("secure=" + cookie.secure);
        }
        document.cookie = cookie.name+'='+'; '+'expires='+new Date(0).toGMTString();
        document.cookie = cookieData.join("; ");
    },

    clear : function (name) {
        var cookie = {
            name : name,
            value : '',
            expires : new Date(0)
        };
        this.save(cookie);
    },

    fetch : function (name) {
        var regexp = new RegExp("(?:; )?" + name + "=([^;]*);?");
        if (regexp.test(document.cookie)) {
            return decodeURIComponent(RegExp["$1"]);
        } else {
            return null;
        }
    }

};



/**
 * TRACKING TOOLS
 */


// CREATING ISC NAMESPACE
var ISC = new Object();


// GOOGLE ANALYTICS BOOTSTRAP
try {
    ISC.googlePageTracker = _gat._getTracker("UA-9280283-1");
} catch(err) {}


ISC.debugMode = false;


/**
 * Tracks a page view by name and category.
 */
ISC.trackPageview = function (contentName, contentCategory) {
    if (ISC.debugMode) {
        alert('PAGEVIEW: '+contentName+' / '+contentCategory);
    }
    var cmContentName = "PCH ScratchCards: "+contentName;
    cmCreatePageviewTag(cmContentName, contentCategory);
    ISC.googlePageTracker._trackPageview('/'+contentCategory+'/'+ contentName);
}


/**
 * Internal wrapper for core metrics event call.
 *
 * @private
 */
ISC._trackEvent = function (eventName, isEndTag) {
    var eventStateCode = isEndTag ? 2 : 1;
    var eventStateName = isEndTag ? 'end' : 'start';    
    if (ISC.debugMode) {
        alert('EVENT: '+eventName+" - "+eventStateName);
    }
    cmCreateConversionEventTag(eventName, eventStateCode, "MICROSITE:SCRATCHCARDS", "0");
    ISC.googlePageTracker._trackPageview('/_EVENT/'+eventName+'/'+eventStateName);
}


/**
 * Track an event start by event name.
 */
ISC.trackEventStart = function (eventName) {
    ISC._trackEvent(eventName, false);
}


/**
 * Track an event end by event name.
 */
ISC.trackEventEnd = function (eventName) {
    ISC._trackEvent(eventName, true);
}




/**
 * OTHER TOOLS
 */



function forgotPassword(){
	h 	= 230; 		//	height
	w 	= 400; 		// 	width
	l	= 'no';					//	location bar
	m	= 'no';					//	menu bar
	t 	= 'no';					// 	toolbar
	r 	= 'no';					// 	resizeable
	sc 	= 'no'; 				//	scrollbars
	st 	= 'no';					//	status bar 
	x 	= 5; 					// 	y from upper left corner of screen
	y 	= 5;					// 	y from upper left corner of screen
	n 	= 'password';				// 	window name
	u	= '/account/password.php';
	f 	= 'height='+h+',width='+w+',top='+y+',left='+x+',resizable='+r+',scrollbars='+sc+',status='+st+',toolbar='+t+',menubar='+m+',location='+l;
	fs 	= window.open(u,n,f);
}



function handleLinkOut(){
	ISC.trackPageview('Partner Redirect', 'XP');
	var linkout = "sb.pch.com/ptr/08/13-33/1333.html";
	window.location = 'http://'+linkout;
}



function launchPopUnder(){
	var linkout = 'http://sb.pch.com/ops/billme/aq/05/25-03/5kcertbcas.aspx?v=20083190&tc=205CY1578I';
	ISC.googlePageTracker._trackPageview('/POPUNDER/'+linkout);
	popWindow(780, 500, linkout, 'popunder', true);
}


// width, height, url, title
function popWindow(w,h,u,title,popunder){
	l	= 'no';					//	location bar
	m	= 'no';					//	menu bar
	t 	= 'no';					// 	toolbar
	r 	= 'no';					// 	resizeable
	sc 	= 'yes'; 				//	scrollbars
	st 	= 'no';					//	status bar 

	n 	= title;				// 	window name
	f 	= 'height='+h+',width='+w+',resizable='+r+',scrollbars='+sc+',status='+st+',toolbar='+t+',menubar='+m+',location='+l;
	fs 	= window.open(u,n,f);
	
	if(popunder){
		fs.blur();
		window.focus();
	}
}

