window.onbeforeunload=confirmExit;
var dirty = false;
var userguid;

function confirmExit(){
	var closedTime = new Date();
	try{

	var difference = closedTime.getTime() - launchedTime.getTime();
    icoviaTracker("/tracking/closed?sessionLength=" + difference + "&userGuid=" + userguid);
	}
	catch(e){}
	if (dirty) {
		return "You have unsaved changes to your plan.";
	
	}

}
function setDirty(status){
	dirty = status;
}
function setUserGuid(loggedInUserGuid){
	userguid = loggedInUserGuid;
}
function openCenteredWindow(URLtoOpen,windowName,windowW,windowH){
	if(windowW == undefined) windowW = screen.width - 100;
	if(windowH == undefined) windowH = screen.height - 100;
	var topPos = (screen.height-windowH)/2;
	var lftPos = (screen.width-windowW)/2;
	var newWindow = window.open(URLtoOpen,windowName,'height='+windowH+',width='+windowW+',top='+topPos+',left='+lftPos+',toolbar=0,scrollbars=1,resizable=1,menubar=0,location=no,address=no');
	var popUpMsg = "You appear to have a pop-up blocker that prevents a window from opening. Please enable pop-ups for this site and try again. Thank you.";
	if(!newWindow){
		alert(popUpMsg);
	}
};
function _icoviaVoid() { return; }

function icoviaTracker(page)
{
	var i=new Image(1,1);
	i.src=page;
	i.onload=function() {_icoviaVoid();}
}
function setTitle(title)
{
	document.title = title;
}
function extRegInit (registerUrl){

	var height='680px';	
	registerUrl = registerUrl;
	$('#extreg').css('margin', '0');
	$('#extreg').css('padding', '0');	
	$('#extreg').css('height', '620px');
	$('#extreg').html('<iframe id="extregiframe" src ="' + registerUrl + '" scrolling="no" frameborder="0"  height="' + height + '" width="100%" />');
	
 }
function registerUser (){
	if (jQuery.browser.msie) {
		$('#extreg').dialog({ height: 700, width: 810 ,title: "Login and Registration", buttons: { "Close": function() { verifyReg();}}});
	}
	else
	{
	 	$('#extreg').dialog({ height: 800, width: 810 ,title: "Login and Registration", buttons: { "Close": function() { verifyReg();}}});
	}

	$('#extreg').dialog('open');
	$('#extreg').bind('dialogbeforeclose', function(event, ui) { verifyReg();});
    $('#extreg').dialog('moveToTop');
}
function verifyReg()
{
	$('#extreg').dialog('destroy');

}
var as_swf_name ='icovia';
function flashCallBack ( func ) {
 
  try
  {
		var arguments = flashCallBack.arguments
		if( arguments.length > 1 ){
			try
			{
			  
			  document[as_swf_name][func]( arguments[1], arguments[2]);
			}
			catch(e)
			{
				document.getElementById(as_swf_name)[func]( arguments[1], arguments[2]);
		  
			}
			  
  }	  else{
		var flash = document[as_swf_name];
		try
		{
			flash[func]();
		}
		catch(e)
		{
			var embed = document.getElementById(as_swf_name);
			embed[func]();
		}
			
	  }
  }
  catch(e)
  {
	 alert (e.message);
  }
}

function registerRemoteUser(userID, emailAddress)
{    
    flashCallBack("onRegistered",userID, emailAddress);
    verifyReg();
}

