var regulardomain = '';
var prodomain = 'pro/';

var proshowlink = prodomain + 'Meetings/Join/';
var promoderator = prodomain + 'Moderator/';
var proapi = prodomain + 'Api/';
var propanel = prodomain + 'Moderator/Panel/';

var regularshow = regulardomain + 'show/';
var regularpanel = regulardomain + 'member/';


var baseURL = "";
indx = location.href.indexOf("moc");    
baseURL = location.href.substr(0,indx);
var url=location.href;
if(url&&url.length>0&&url.indexOf('/moc')!=-1)
	baseURL=url.substr(0,url.indexOf('/moc')+1);
else if(url&&url.length>0&&url.indexOf('\\moc')!=-1)
	baseURL=url.substr(0,url.indexOf('\\moc')+1);
else if(url&&url.length>0&&url.indexOf('\\index.php')!=-1)
	baseURL=url.substr(0,url.indexOf('\\index.php')+1);
else if(url&&url.length>0&&url.indexOf('/index.php')!=-1)
	baseURL=url.substr(0,url.indexOf('/index.php')+1);
else if(url&&url.length>0&&url.lastIndexOf('/')!=-1)
	baseURL=url.substr(0,url.lastIndexOf('/')+1);
else if(url&&url.length>0&&url.lastIndexOf('\\')!=-1)
	baseURL=url.substr(0,url.lastIndexOf('\\')+1);

var isReady = false;
var homePageReadyCalled = false;

function GetBaseURL()
{
	return baseURL;
}


/* some precaching for the registration button */
pre_register_on = new Image();
pre_register_on.src = GetBaseURL() + 'images/home/register.jpg';
pre_register_off = new Image();
pre_register_off.src = GetBaseURL() +'images/home/disregister.jpg';

function watchitoo_OnLogin(username, nickname, certificate, accountType) 
{
	//alert("watchitoo_OnLogin. accountType="+accountType);
	if (accountType == 'Member') {
		
		
		//var u = username; /* for scope*/
		//var n = nickname;
		//var c = certificate;
		
		//if (document.getElementById("welcomeMessage")) {
		//	SetNickname(nickname);
		//}
		// redirect to member page
		
		//Check if the user have hase
		if(window.location['hash'].length) {
			//Check if the user try to see anything on #MyStuff - we should redirect him to #HomPage
			var reg = '^#MyStuff(.*)$';
			var MyStuffmatchs = window.location['hash'].match(reg);

			if(MyStuffmatchs && MyStuffmatchs[1] && MyStuffmatchs[1].length>0) {
				var pathname = window.location['pathname'];
				
				//Check if the users look on /X/index.php, if so, remove the index.php from the path
				var reg = '^(.*)index.php$';
				indexMatchs = pathname.match(reg);
				if( indexMatchs && indexMatchs[1] && indexMatchs[1].length>0) //set the new path without index.php
					pathname = indexMatchs[1];
				
				var newUrl = window.location['protocol'] + '//' + window.location['hostname'] + pathname + 'member/#HomePage' + MyStuffmatchs[1];
				window.location = newUrl;
			}
		} else {
			window.location=GetBaseURL()+ regularpanel;
			
			//window.location="member/";
		}
	}
		

	//getSWF("HomePage").SetUsername(username,certificate,nickname,accountType);
	
}

function watchitoo_OnLogout() {
	//alert("watchitoo_OnLogout");
	self.parent.clearWelcome();
	//getSWF("HomePage").Signout();
}

function watchitoo_OnLoginFailed(errorCode, description) {
	//alert("watchitoo_OnLoginFailed");
	//getSWF("HomePage").onLoginFailed(errorCode,description);
	/*$('#signinError').css( {'display': 'block'} );
	$('#signinError').html(description);*/
	$('#loginLoader').hide();
	$('#singInError').show().attr("innerHTML", description ); 
}

function watchitoo_OnStateChange(state) {
	//alert("state="+state);
	if(state=="loggedOut")
	{
		// added these lines to ensure logout gets processed
		self.parent.clearWelcome();
		//getSWF("HomePage").Signout();
	
		// added this line to create a guest account if not logged in
		//setTimeout("CreateGuestAccount()",100);
	}
}
function watchitoo_OnRegisterError( type, description, options ) {
	//alert(msg);
	$('#registerError').show().attr("innerHTML", description );
}
function watchitoo_OnResetFailed( description ) {
	//$('#loginLoader').hide();
	$('#resetError').show().attr("innerHTML", description ); 
}
function watchitoo_OnResetSucess(description) {
	alert(description);
	var email =  $('#resetPassEmail').val();
	$('#username').val(email);
	
	$('#loginForm').css( { 'display':''});
	$('#resetFrom').css( { 'display':'none'});
}
function watchitoo_OnRegister(params) {
	//getSWF("HomePage").onRegisterResult('success','', params);
	// redirect to member page
	window.location="member/";
}

function watchitoo_OnError(text) {
	alert(text);
}