var messagePane=0;
var curentuserid;
var historyList=0;
var pageInitialized = false;
var naviloaded = false;
var setPassword = 0;
var invitedLink = "";
var refresh = 0;
var currentBubble = '';
var showCallBubble = true;
var showTakeBubble = true;
var showCallStatusBar = true;
var showRegisterBubble = true;
var startRegisterInterval = true;
var credits = 0;

var login = 0;

function Werteliste (querystring) {
	if (querystring == '') return;
	var wertestring = querystring.slice(1);
	var paare = wertestring.split("&");
	var paar, name, wert;
	for (var i = 0; i < paare.length; i++) {
		paar = paare[i].split("=");
		name = paar[0];
		wert = paar[1];
		name = unescape(name).replace("+", " ");
		wert = unescape(wert).replace("+", " ");
		this[name] = wert;
	}
}

function getFrameUrl() {
	var frameUrl = '/app-c2call/';
	if (location.search == '') {
		return frameUrl;
	}

	if (liste['mode'] && liste['mode'] == 'confirm') {
		frameUrl = frameUrl + 'faces/RegisterConfirm.jsp' + location.search;
	}
		
	return frameUrl;
}

var liste = new Werteliste(location.search);

function popup(obj,w,h,x,y) {
	var options="", popupWin;
	if(typeof(x)=="number") options+=",left="+x;
	if(typeof(y)=="number") options+=",top="+y;
	if(typeof(w)=="number") options+=",width="+w;
	if(typeof(h)=="number") options+=",height="+h;
	lastParam=popup.arguments[popup.arguments.length-1];
	if(typeof(lastParam)=="string") {
		options+=",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=1,resizable=yes"+lastParam;
	} else {
		if(typeof(lastParam)=="boolean" && lastParam) {
			options+=",menubar=no";
		} else if(typeof(lastParam)!="boolean" || (typeof(lastParam)!="boolean" && !lastParam)) {
			options+=",menubar=no,scrollbars=1";
		}
	}
	if(options) options=options.substring(1);
	popupWin=window.open(obj.href,obj.target,options);
	return (popupWin)?false:true;
}

function navi() {
	var site = window.frames['navi1'].document.URL;
	if (site.indexOf("01_navi_home.html") != -1) {
		var ho = "589px"; //755px; mit com und sip  // 820px mit paypal logo | ohne Paypal logo = 755px
		document.getElementById('navi1').style.height = ho;
	}
	
	if (site.indexOf("02_navi_addressbook.html") != -1) {
		var hoe = "645px"; //735px mit com und sip //702px   685px ohne iphone
		document.getElementById('navi1').style.height = hoe;
	}

	if (site.indexOf("01_navi_home_invited.html") != -1) {
		var hoeh = "544px"; //710px mit com und sip //775px mit pp logo | ohne Paypal logo = 710px
		document.getElementById('navi1').style.height = hoeh;
	}

	if (site.indexOf("02_navi_addressbook_invited.html") != -1) {
		var hoehe = "600px"; //690px mit com und sip //640px ohne iphone
		document.getElementById('navi1').style.height = hoehe;
	}
}

function resize_frame(hoehe)
{
	document.getElementById('iframe').style.height = hoehe+'px';
}

function resize_me(n)
{
	d=20;
	if(navigator.appName.indexOf("Explorer") != -1)		//für IE größeren Abstand
	{
		d=250;
	}
	ifObj=document.getElementsByName(n)[0];
	p=(document.all)?'scroll':'offset';
	eval("ifObj.style.height=Math.max(200,window.frames[n].document.getElementsByTagName('body')[0]."+p+"Height+"+d+")+'px'");
}

function resize_jsp() {
	var hoehe = "440px";
	var hoehe2 = "803px";//"653px";


	var site = window.frames['iframe'].document.URL;
	if (site.indexOf("Registration_v2") != -1) {
		document.getElementById('iframe').style.height = hoehe;
	}
	if (site.indexOf("Login_v2") != -1) {

		document.getElementById('iframe').style.height = hoehe;
		if(site.indexOf("Login_v2.jsp?") != -1)
		{
			document.getElementById('iframe').style.height = hoehe;
		}
		if(site.indexOf("Login_v2.jsp;") != -1)
		{
			document.getElementById('iframe').style.height = hoehe2;
		}
	}
	if (site.indexOf("UserAccount_v2.jsp") != -1 || site.indexOf("UserAccount2_v2.jsp") != -1 ||
		site.indexOf("C2ContactManager.jsp") != -1 ||
		site.indexOf("ComRegistration.jsp") != -1 || site.indexOf("CallReport.jsp") != -1 ||
        site.indexOf("NokiaConfig.jsp") != -1 || site.indexOf("InviteConfirmNotRegistered.jsp")) {
		document.getElementById('iframe').style.height = hoehe2;
	//alert("hoehe2 = " + site);
	} if(site.indexOf(".html") != -1) {
		resize_me('iframe');
	//alert("else = " + site);
	}

}

function resizeCallMe()
{
	setTimeout('resizeCallMe2()',300);
}

function resizeCallMe2()
{
	document.getElementById('iframe').style.height = "1485px";
}

function resizePricing()
{
	setTimeout('resizePricing2()',300);
}

function resizePricing2()
{
	document.getElementById('iframe').style.height = "750px";
}

function resizeContactImport()
{
	setTimeout('resizeContactImport2()',300);
}

function resizeContactImport2()
{
	document.getElementById('iframe').style.height = "750px";
}

function resizeProfile()
{
	setTimeout('resizeProfile2()',300);
}

function resizeProfile2()
{
	document.getElementById('iframe').style.height = "900px";
}

function accountBtnTimeOut() {
	setTimeout('loadAccountBtn()',500);
}

function loadAccountBtn() {
	window.frames['navi1'].MM_nbGroup('down','group1','Account','images/navi/12_Account/navi_05_2_account.gif',1);
}

function ladeNav2Iframe() {
	naviloaded = false;
	window.frames['navi1'].location.href = "../website/02_navi_addressbook.html";
	document.getElementById('iframe').style.height = "633px"; //633px
	setC2CallLink();
}

function ladeNav2Invited() {
	naviloaded = false;
	window.frames['navi1'].location.href = "../website/02_navi_addressbook_invited.html";
	document.getElementById('iframe').style.height = "633px"; // 633px
}

function ladeNavIframe() {
	naviloaded = false;
	window.frames['navi1'].location.href = "../website/01_navi_home.html";
	//document.getElementById('iframe').style.height = "1800px";
	setTimeout('unloadCallbar()',500);
	unsetC2CallLink();
}

function setContactManager(cm) {
	if (!pageInitialized) {
		pageInit();
	}
    
	c2callManager.setContactManager(cm);
//c2callManager.contactManager.addListener('C2CallManager', c2callManager);
}

function unsetContactManager() {
	c2callManager.unsetContactManager();
}

function setCallbar(callbar) {
	//alert("initLogin()");

	if (!pageInitialized) {
		pageInit();
	}

	c2callManager.setCallbar(callbar);
	c2callManager.callBar.addListener('C2CallManager', c2callManager);
}

function unloadCallbar() {
	window.frames['callbar'].location.href = 'EmptyCallbar.html';
	pageInitialized = false;
}

function unloadCallbar2() {
	parent.frames['navi1'].location.href = "../01_navi_home.html";
	window.frames['callbar'].location.href = '../EmptyCallbar.html';
	pageInitialized = false;
}

function gotoAnker() {
	window.location.href = "#top";
}

function pageInit() {
	//alert("initPage() : c2callManager");
	c2callManager = new C2CallManager();
	c2callManager.setAppletInfo('callbar', 'sipapplet');

	var cmd = liste['cmd'];
	var email = liste['email'];
	var id = liste['id'];
	var type = liste['type'];
    var affiliate = liste['affiliate'];
	var externalBDRID = liste['externalBDRID'];
	var result = liste['result'];
	var reason = liste['reason'];
	var pptransaction = liste['transaction'];
	var data = liste['DATA'];
	var signature = liste['SIGNATURE'];

	if(login == 0) {
		if (typeof(cmd) == 'undefined') {
			// Normaler Login
			//window.frames['iframe'].location.href = "texte/text_01_home.html";
			//window.frames['navi1'].MM_nbGroup('down','group1','home','images/navi/01_Home/navi_01_home.gif',1);
		} else if (cmd == 'newpassword') {
			if (email && id) {
				window.frames['iframe'].location.href = "../faces/login/PasswordNew_v2.jsp?email=" + email + "&id=" + id;
				window.frames['navi1'].MM_nbGroup('down','group1','login','images/navi/03_Login/navi_03__1_login.gif',1);
			}
		} else if (cmd == 'payment') {
			if (result && result == 'success') {
				if (externalBDRID) {
					window.frames['iframe'].location.href = "../faces/account/Cab_v2.jsp?result=success&externalBDRID=" + externalBDRID;
				}
			} else {
				if (typeof(reason) == 'undefined') {
					reason = "0";
				}
				window.frames['iframe'].location.href = "../faces/account/Cab_v2.jsp?result=error&reason=" + reason;
			}
		} else if (cmd == 'saferpay') {
			if (data && signature && id && result && result == 'success')
			{
				window.frames['iframe'].location.href = "../faces/account/SaferPaySucErrorPage_v2.jsp?result=success&id=" + id + "&data=" + data + "&signature=" + signature;
			}
			else if (id && result == 'error')
			{
				window.frames['iframe'].location.href = "../faces/account/SaferPaySucErrorPage_v2.jsp?result=error&id=" + id;
			}
			else
			{
				window.frames['iframe'].location.href = "../faces/account/SaferPaySucErrorPage_v2.jsp?result=error";
			}
			ladeNav2Iframe();
		} else if (cmd == 'paypal') {
			if (result && result == 'success') {
				if (pptransaction) {
					window.frames['iframe'].location.href = "../faces/account/PpSucErrPage_v2.jsp?result=" + result + "&transaction=" + pptransaction;
				}
				if (!pptransaction) {
					if (typeof(reason) == 'undefined') {
						reason = "0";
					}
					window.frames['iframe'].location.href = "../faces/account/PpSucErrPage_v2.jsp?result=error&reason=" + reason;
				}
			}
			if (result && result == 'account') {
				window.frames['iframe'].location.href = "../faces/account/UserAccount_v2.jsp";
			}
            if (result && result == 'nokiaconfig') {
				window.frames['iframe'].location.href = "../faces/account/NokiaConfig.jsp";
			}
			if (result && result == 'address') {
				window.frames['iframe'].location.href = "../faces/contacts/C2ContactManager.jsp";
			}
			if (result && result == 'error') {
				if (typeof(reason) == 'undefined') {
					reason = "0";
				}
				window.frames['iframe'].location.href = "../faces/account/PpSucErrPage_v2.jsp?result=" + result + "&reason=" + reason;
			}
			if (typeof(result) == 'undefined') {
				if (typeof(reason) == 'undefined') {
					reason = "0";
				}
				window.frames['iframe'].location.href = "../faces/account/PpSucErrPage_v2.jsp?result=error&reason=" + reason;
			}
			ladeNav2Iframe();
			accountBtnTimeOut();
			
		} else if (cmd == 'register') {
			if (email && id && type) {
				if (type == '0') {
					window.frames['navi1'].MM_nbGroup('down','group1','register','images/navi/14_Register/navi_14_register_02.gif',1);
					window.frames['iframe'].location.href = "../faces/login/RegistrationConfirm_v2.jsp?email=" + email + "&id=" + id + "&type=" + type;

				}
                //if (!isiPhone) {
                    if (type == '1') {
                        //invitedLink = "../faces/login/InviteConfirmNotRegistered.jsp?email=" + email + "&id=" + id + "&type=" + type;
                        //window.frames['navi1'].location.href = "EmptyNavi.html";
                        //document.getElementById('loading').style.display = 'inline';
                        //window.frames['navi1'].MM_nbGroup('down','group1','register','images/navi/14_Register/navi_14_register_02.gif',1);
                        //window.frames['iframe'].location.href = "../faces/login/InviteConfirmNotRegistered.jsp?email=" + email + "&id=" + id + "&type=" + type;
//						var link = "../faces/InviteConfirm?email=" + email + "&id=" + id + "&type=" + type;
//						var fenster = window.open(link,'Call', 'left=300px, width=577px, height=389px, status=no, scrollbars=yes, resizable=yes');
//						fenster.focus();
						window.location.href = "../faces/InviteConfirm?email=" + email + "&id=" + id + "&type=" + type;
						//window.location.href = "../faces/JFX?email=" + email + "&id=" + id + "&type=" + type;
						//window.frames['iframe'].location.href = "../faces/InviteConfirm?email=" + email + "&id=" + id + "&type=" + type;
                    }
                    if (type == '2') {
                        window.frames['navi1'].MM_nbGroup('down','group1','login','images/navi/03_Login/navi_03__1_login.gif',1);

                        if(typeof(affiliate) == 'undefined' || affiliate == "")
                        {
                            window.frames['iframe'].location.href = "../faces/login/InviteConfirm.jsp?email=" + email + "&id=" + id + "&type=" + type;
                        }
                        else
                        {
                            window.frames['iframe'].location.href = "../faces/login/InviteConfirm.jsp?email=" + email + "&id=" + id + "&type=" + type + "&affiliate="+affiliate;
                        }
                    }
//                } else {
//                    if (type == '1') {
//                        window.location.href = "../faces/login/InviteConfirm_iPhone.jsp?email=" + email + "&id=" + id + "&type=" + type;
//                    }
//                    if (type == '2') {
//                        window.location.href = "../faces/login/InviteConfirm_iPhone.jsp?email=" + email + "&id=" + id + "&type=" + type;
//                    }
//                }
			}
		} else if (cmd == 'callback') {
			if (email && id) {
				window.frames['navi1'].MM_nbGroup('down','group1','login','images/navi/03_Login/navi_03__1_login.gif',1);
				window.frames['iframe'].location.href = "../faces/login/Login_v2.jsp?email="+email+"&id="+id;
			}
		} else if (cmd == 'startCalling') {
			window.frames['navi1'].MM_nbGroup('down','group1','home','images/navi/01_Home/navi_01_home.gif',1);
			window.frames['iframe'].location.href = "texte/text_01_home.html?cmd=startCalling&email="+email+"&id="+id;
		} else if (cmd == 'cancelNews') {
			if (email && id) {
				window.frames['iframe'].location.href = "../faces/newsletter/CancelNewsletter.jsp?cmd=cancelNews&email="+email+"&id="+id;
			}
		} else if (cmd == 'faq') {
			window.frames['iframe'].location.href = "texte/text_02_faq.html";
			window.frames['navi1'].MM_nbGroup('down','group1','faqs','images/navi/02_FAQ/navi_02_2_FAQ.gif',1);
			
		} else if (cmd == 'registration') {
			window.frames['iframe'].location.href = "../faces/login/Registration_v2.jsp";
			
		} else if (cmd == 'registrierung') {
			window.frames['iframe'].location.href = "../faces/login/Registration_de_v2.jsp";

		} else if (cmd == 'login') {
			window.frames['iframe'].location.href = "../faces/login/Login_v2.jsp";
			
		} else if (cmd == 'einloggen') {
			window.frames['iframe'].location.href = "../faces/login/Login_de_v2.jsp";

		} else if (cmd == 'getstarted') {
			window.frames['iframe'].location.href = "texte/text_04_getstarted.html";
			window.frames['navi1'].MM_nbGroup('down','group1','getstarted','images/navi/05_Getstarted/navi_05_getstarted02.gif',1);
			
		} else if (cmd == 'takeatour') {
			window.frames['iframe'].location.href = "texte/text_05_takeatour.html";
			window.frames['navi1'].MM_nbGroup('down','group1','takeatour','images/navi/06_TakeaTour/navi_06_tale_a_tour_02.gif',1);
			
		} else if (cmd == 'pricing') {
			window.frames['iframe'].location.href = "../faces/pricing/Pricing.jsp";
			
		} else if (cmd == 'preise') {
			window.frames['iframe'].location.href = "../faces/pricing/Pricing_de.jsp";

		} else if (cmd == 'iphone') {
			window.frames['iframe'].location.href = "texte/text_18_iphone.html";
			window.frames['navi1'].MM_nbGroup('down','group1','iphone','images/navi/16_Iphone/navi_16_iphone_01.gif',1);
			
		} else if (cmd == 'communities') {
			window.frames['iframe'].location.href = "texte/text_15_communities.html";
			window.frames['navi1'].MM_nbGroup('down','group1','communities','images/navi/15_Communities/navi_15_for_communities_01.gif',1);
			
		} else if (cmd == 'sip') {
			window.frames['iframe'].location.href = "texte/text_17_sip_providers.html";
			window.frames['navi1'].MM_nbGroup('down','group1','sipprovider','images/navi/17_SIP_Providers/navi_17_sip_providers_01.gif',1);
			
		} else if (cmd == 'terms') {
			window.frames['iframe'].location.href = "texte/text_09_terms_en.html";
			
		} else if (cmd == 'agbs') {
			window.frames['iframe'].location.href = "texte/text_09_terms_de.html";
			
		} else if (cmd == 'privacy') {
			window.frames['iframe'].location.href = "texte/text_10_privacy_en.html";
			
		} else if (cmd == 'imprint') {
			window.frames['iframe'].location.href = "texte/text_11_imprint_de.html";
			
		} else if (cmd == 'troubleshooting') {
			window.frames['iframe'].location.href = "texte/text_12_troubleshooting_en.html";
			
		} else if (cmd == 'about') {
			window.frames['iframe'].location.href = "texte/text_13_about_en.html";
			
		} else if (cmd == 'jobs') {
			window.frames['iframe'].location.href = "texte/text_20_jobs.html";
			
		} else if (cmd == 'support') {
			window.frames['iframe'].location.href = "../faces/SupportForm.jsp";
			
		} else if (cmd == 'kontakt') {
			window.frames['iframe'].location.href = "../faces/SupportForm_de.jsp";

		} else if (cmd == 'contatto') {
			window.frames['iframe'].location.href = "../faces/SupportForm_it.jsp";

		} else if (cmd == 'contact') {
			window.frames['iframe'].location.href = "../faces/SupportForm_fr.jsp";

		} else if (cmd == 'help') {
			window.frames['iframe'].location.href = "texte/text_22_help.html";
			
		} else if (cmd == 'addressbook') {
			window.frames['iframe'].location.href = "../faces/contacts/C2ContactManager.jsp";
			
		} else if (cmd == 'notregistered') {
			window.frames['navi1'].location.href = "../website/01_navi_home_invited.html";
			window.frames['iframe'].location.href = "../faces/login/Registration_v2_1.jsp";
			
		} else if (cmd == 'widget') {
			window.frames['iframe'].location.href = "texte/text_21_fxcaller.html";
            window.frames['navi1'].MM_nbGroup('down','group1','widget','images/navi/20_Widget/navi_widget_02.gif',1);

		} else if (cmd == 'android') {
			window.frames['iframe'].location.href = "texte/text_23_android.html";
            window.frames['navi1'].MM_nbGroup('down','group1','android','images/navi/22_Android/navi_android_02.gif',1);

		} else if (cmd == '404') {
			window.frames['iframe'].location.href = "texte/404.html";
		
		} else if (cmd == 'unsubscribeMail') {
			if (email && id) {
				window.frames['iframe'].location.href = "../faces/unsubscribeEmails/UnsubscribeEmails.jsp?cmd=unsubscribeMail&email="+email+"&id="+id;
			}
		}
	}
	pageInitialized = true;
}

// Applet Notifications
function processMessageIn(userid, username, msgkey) {
	//alert('New Message : ' + username + ' / ' + msgkey);
	c2callManager.phoneManager.processIM(userid, username, msgkey);
}

function notifyDataUpdate(dataType) {
	c2callManager.phoneManager.notifyDataUpdate(dataType);
}

function notifyCall(caller, ntype, displayName) {
	c2callManager.phoneManager.notifyCall(caller, ntype, displayName);
}

function notifyOnlineStatus(status) {
	c2callManager.phoneManager.notifyOnlineStatus(status);
}

function notifyCallInfo(ntype, status) {
	c2callManager.phoneManager.notifyCallInfo(ntype, status);
}

function doPresence() {
	c2callManager.phoneManager.doPresence();
}

function setRegistered()
{
	c2callManager.setRegistered(true);
}

function refreshCallbar(vorname, nachname) {
	c2callManager.refreshCallbarStatus(vorname, nachname);
}

function preloadImages() { //v3.0
	var d=document; if(d.images){
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
			}
			}
}

function hideinfodiv()
{
	document.getElementById('infodiv').style.display='none';
}

function changeButtons()
{
	if(parent.naviloaded == true)
	{
		parent.navi1.MM_nbGroup('down','group1','profile','images/navi/11_Profile/navi_04_2_profile.gif',1);
	}
	else
	{
		setTimeout('changeButtons()',500);
	}
}

function hideRegisterBubble()
{
	document.getElementById('registerBubble').style.display='none';
	parent.showRegisterBubble = false;
}

function setC2CallLink()
{
	document.getElementById('c2callLink').setAttribute('href', 'texte/text_01_home_1.html');
}

function unsetC2CallLink()
{
	document.getElementById('c2callLink').setAttribute('href', 'texte/text_01_home.html');
}

function handleCallStatusBarButtons(btnName, formId)
{
	c2callManager.handleCallStatusBarButtons(btnName, formId);
}

function refresCallbarCredits() {
	c2callManager.refresCallbarCredits();
}