/*
@@@BUILDINFO@@@ URLHandler.jsx 1.0.1.0  4/16/07
*/

#target bridge

acrobatconnect.connectLinkHandler = new Object;

acrobatconnect.connectLinkHandler.callback = function ( target ) {
	//PopulateMeetingLoginFields?
	//username=<username>
	//url=<url>
	//cs=<shortcut-info>
	if(target.indexOf("PopulateMeetingLoginFields") == 0 )
	{		
		if( acrobatconnect.createConfirmDialog(acrobatconnect.localize("$$$/CS3/AcrobatConnect/URLHandler/confirmText=TBT" ),							
						acrobatconnect.localize("$$$/CS3/AcrobatConnect/URLHandler/confirmTitle=TBT")) )
		{
			var params = acrobatconnect.parseURLParams(target);		
			acrobatconnect.saveLoginInfo(params['url'], params['username'], "", false);
			acrobatconnect.notifyHTML("");  //If its already showing, update screen
			acrobatconnect.startMeeting.open(); 				
		}
	}	
	return undefined; 
}

//Returns the paramers in name value pairs
acrobatconnect.parseURLParams = function(str)
{
	var str = str.split("?")[1];
	str = str.split("&");	
	var params = {};
	var pair ;
	for( var itr = 0; itr < str.length; itr++)
	{	
		pair = str[itr].split("=");
		params[pair[0]] = pair[1];
	}
	return params;
}

acrobatconnect.createConfirmDialog = function( message, title)
{
	var win = new Window ("dialog" , title  );
	var msgLabel = win.add("statictext", undefined, message, {multiline:true, preferredSize: [500, 100], bounds:{width:500,height:200}});	
	var buttonRow = win.add("group");
	buttonRow.orientation = "row";
	buttonRow.alignChildren = "right";

	var okBtn = buttonRow.add("button", undefined, acrobatconnect.localize("$$$/CS3/AcrobatConnect/URLHandler/okButton=TBT"), {name:'ok'} );
	var cancelBtn = buttonRow.add("button", undefined, acrobatconnect.localize("$$$/CS3/AcrobatConnect/URLHandler/cancelButton=TBT"), {name:'cancel'});

	win.cancelElement = cancelBtn;
	okBtn.onClick = function(){ win.close(true); }
	cancelBtn.onClick = function(){ win.close(false); }	
	win.modal = true;	
	win.center();
	var res = win.show();	
	return (res==1);
}
