/* Created on Nov 14, 2006
   Adds foundational javascript functionality for Lulu.com
 */

//variables for studio pop-up
var studioWindow = null;
var allowNavigation = false;
	

 
 
/* determine which javascript library is available */

library = 'MochiKit';

function toggleHelp(id){
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'toggleHelp',page:document.location} );
	MochiKit.Visual.toggle(id, 'blind', {duration : .2});
	return false;
}

function popup(iUrl, iName, w, h, scroll, titlebar)
{
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'popup',page:document.location} );
	if( !w ) {
		w = 650;
	}
	if( !h ) {
		h = 500;
	}
		if( !scroll ) {
				scroll = "yes";
		}
	if( scroll == "" ) {
		scroll = "yes";
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'

	if (!this.winHandle) {
		this.winHandle=window.open(iUrl, iName, winprops);
	}
 	else {
 		if (this.winHandle && !this.winHandle.closed) {
 			this.winHandle.close();
 		}
 		this.winHandle=window.open(iUrl, iName, winprops);
 		this.winHandle.focus();
 	}
 	this.winHandle.focus();
}

/****************************************************************
 *     Cookie functions grabbed from Quirksmode                 *
 ****************************************************************/
 function createCookie(name,value,days) {
     if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'createCookie',page:document.location} );
	if(days){
		var date =  new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else{
		var expires = "";
	}
		document.cookie = name+"="+value+expires+"; page=/";
}

function readCookie(name) {
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'readCookie',page:document.location} );
	var nameEQ = name+"=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++){
		var c = ca[i];
		while(c.charAt(0)==' '){
			 c=c.substring(1, c.length);
		}
		if(c.indexOf(nameEQ) == 0){
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function eraseCookie(name){
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'eraseCookie',page:document.location} );
	createCookie(name, "", -1);
}



/****************************************************************
JS to launch the Lulu Studio
	We don't really want this here but do to scoping issues
	and the need for a global var to determine whether to 
	spawn a new window we need to put it here.
 ****************************************************************/
/**
 * Launch the studio window
 * @param: url for studio (with/without cid/mid)
 */
function launchStudio(windowLocation){
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'launchStudio',page:document.location} );
	if ((studioWindow != null) && (studioWindow.closed == false) ){
		studioWindow.focus();
	} else {	
		studioWindow = window.open(windowLocation, 'contentBuilder', 'resizable=yes, width='+screen.availWidth+', height='+screen.availHeight);
	}
}


/****************************************************************
JS to redirect page to login/upgrade as alternative to launchStudio

 ****************************************************************/
/**
 * 
 * @param: url for studio (with/without referer)
 */
function redirectPage(windowLocation){
    if (typeof $L != 'undefined') $L.trace( 'deprecatedJsFunctionCall', {file:'lulu_base.js',func:'redirectPage',page:document.location} );
	window.location = windowLocation;
}

