function hideUnTransparentElements(onoff) {
	if (navigator.appName.indexOf("Microsoft Internet")==-1) { //Not IE
		if(onoff) {
			document.getElementById('htmltop').className = 'popup-open-hide';
		} else {
			document.getElementById('htmltop').className = '';
		}
	} else { //Is IE if (navigator.appName.indexOf("Microsoft Internet")!=-1)		
		//if(document.getElementById('htmltop')!=null){
			if(onoff) {	
				
				document.getElementById('htmltop').className = 'popup-open-reduce';
			} else {
				document.getElementById('htmltop').className = '';
			}
		//}
	}
}

function displayLogin(){
	document.cookie = 'JSESSIONID=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
	overlayDivHeight = 385;
	overlayDivWidth = 415;
	hideUnTransparentElements(true);
	login_url = "/modelwindow/login";
	document.getElementById('creately-popup-content').style.display = 'none';
	document.getElementById('creately-popup-close').style.display = 'block';
	
	document.getElementById('creately-popup-border').style.display = 'block';
	document.getElementById('creately-popup-working').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-working').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-working').innerHTML = '<div id="pContent"><p>Loading Creately login form .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	topleftcorner = viewport_size(overlayDivWidth, overlayDivHeight, 'CENTER');
	document.getElementById('creately-popup').style.top = topleftcorner[0] + 'px'; //top 
	document.getElementById('creately-popup').style.left = topleftcorner[1] + 'px'; //left

	document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-content').innerHTML = '<iframe src="' + login_url + '" width="' + overlayDivWidth + 'px" height="' + overlayDivHeight + 'px" style="height: ' + overlayDivHeight + 'px; width: ' + overlayDivWidth + 'px;" allowtransparency="true" scrolling="no" frameborder="0"><p>Your browser does not support iframes.</p></iframe>';
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-popup-content').style.backgroundColor = '#FFFFFF';
	document.getElementById('creately-popup-content').style.display = 'inline';
	
	document.getElementById('creately-overlay').onclick = '';
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';

}

function cancelOverlay() {
	//var obj = getFlashMovie(swfname);
	hideUnTransparentElements(false);
	document.getElementById('creately-popup').style.display = 'none';
	document.getElementById('creately-overlay').style.display = 'none';
	document.getElementById('creately-popup-content').style.display = 'none';
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-popup-border').style.display = 'none';
	document.getElementById('creately-popup-content').innerHTML = '';
	document.getElementById('creately-popup').style.top = '0px';
	document.getElementById('creately-popup').style.left = '0px';
	document.getElementById('creately-popup-close').style.display = 'block';
	document.getElementById('creately-overlay').style.backgroundColor = '#000000';
	document.getElementById('creately-overlay').style.opacity = '0.7';
	//document.getElementById('creately-overlay').onclick = cancelOverlay;
	
	//obj.demoUserLoginComplete(true, true);
}

function viewport_size(popup_width, popup_height, position) {
	
	topleftcorner = new Array();
	 
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	switch(position) {
		case "NORTH":
			topleftcorner[0] = 12;
			topleftcorner[1] = (viewportwidth / 2) - (popup_width / 2);
			break;
		case "SOUTH":
			topleftcorner[0] = viewportheight - popup_height - 25;
			topleftcorner[1] = (viewportwidth / 2) - (popup_width / 2);
			break;
		case "CENTER":
			topleftcorner[0] = (viewportheight / 2) - (popup_height / 2);
			topleftcorner[1] = (viewportwidth / 2) - (popup_width / 2);
			break;	
	}
	
	return topleftcorner;
}

function displayLoginAndSignup( diagid , hash ){
	// enable edit feture to the user
	document.cookie = 'JSESSIONID=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
	overlayDivHeight = 540;
	overlayDivWidth = 1000;
	hideUnTransparentElements(true);
	//alert(window.location.search);
	//login_url = "/login/diagram"+window.location.search;
	//alert(diagid);
	//alert(hash);
	//window.location.search = diagid
	login_url = '/viewer/edit?'+window.location.search;
	//login_url = '/viewer/edit?diagid='+diagid+'&diaghash='+hash;
	//login_url = '/viewer/edit?diagid='+diagid+'&diaghash='+hash;
	//alert(login_url);
	document.getElementById('creately-popup-content').style.display = 'none';
	document.getElementById('creately-popup-close').style.display = 'block';
	
	document.getElementById('creately-popup-border').style.display = 'block';
	document.getElementById('creately-popup-working').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-working').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-working').innerHTML = '<div id="pContent"><p>Loading Creately login form .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	topleftcorner = viewport_size(overlayDivWidth, overlayDivHeight, 'CENTER');
	document.getElementById('creately-popup').style.top = topleftcorner[0] + 'px'; //top 
	document.getElementById('creately-popup').style.left = topleftcorner[1] + 'px'; //left

	document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-content').innerHTML = '<iframe src="' + login_url + '" width="' + overlayDivWidth + 'px" height="' + overlayDivHeight + 'px" style="height: ' + overlayDivHeight + 'px; width: ' + overlayDivWidth + 'px;" allowtransparency="true" scrolling="yes" frameborder="0"><p>Your browser does not support iframes.</p></iframe>';
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-popup-content').style.backgroundColor = '#FFFFFF';
	document.getElementById('creately-popup-content').style.display = 'inline';
	
	document.getElementById('creately-overlay').onclick = '';
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';

}

function displayLoginForViewer(){	
	document.cookie = 'JSESSIONID=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
	overlayDivHeight = 540;
	overlayDivWidth = 1000;
	hideUnTransparentElements(true);
	login_url = '/viewer/login'+window.location.search;	
	//alert(window.location.search);
	document.getElementById('creately-popup-content').style.display = 'none';
	document.getElementById('creately-popup-close').style.display = 'block';
	
	document.getElementById('creately-popup-border').style.display = 'block';
	document.getElementById('creately-popup-working').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-working').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-working').innerHTML = '<div id="pContent"><p>Loading Creately login form .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	topleftcorner = viewport_size(overlayDivWidth, overlayDivHeight, 'CENTER');
	document.getElementById('creately-popup').style.top = topleftcorner[0] + 'px'; //top 
	document.getElementById('creately-popup').style.left = topleftcorner[1] + 'px'; //left

	document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-content').innerHTML = '<iframe src="' + login_url + '" width="' + overlayDivWidth + 'px" height="' + overlayDivHeight + 'px" style="height: ' + overlayDivHeight + 'px; width: ' + overlayDivWidth + 'px;" allowtransparency="true" scrolling="no" frameborder="0"><p>Your browser does not support iframes.</p></iframe>';
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-popup-content').style.backgroundColor = '#FFFFFF';
	document.getElementById('creately-popup-content').style.display = 'inline';
	
	document.getElementById('creately-overlay').onclick = '';
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';

}

var reduseWidthForSignUp = [];	// this for purchase page css overriding issue
reduseWidthForSignUp['account/upgrade/personal']= 415;
reduseWidthForSignUp['account/upgrade/teamplan']= 415;
reduseWidthForSignUp['product/desktop/purchase']=415;
reduseWidthForSignUp['help']=415;
reduseWidthForSignUp['plans']=415;
reduseWidthForSignUp['diagram-examples']=415;
reduseWidthForSignUp['tos/eula']=415;
reduseWidthForSignUp['tos']=415;
reduseWidthForSignUp['tour1']=415;
reduseWidthForSignUp['customer-love']=415;
reduseWidthForSignUp['case-studies']=415;
reduseWidthForSignUp['forgotten-password']=415;
reduseWidthForSignUp['diagram-products']=415;
reduseWidthForSignUp['desktop']=415;
reduseWidthForSignUp['desktop2']=415;
reduseWidthForSignUp['diagram-products']=415;
reduseWidthForSignUp['tour']=415;
reduseWidthForSignUp['product/education']=415;
reduseWidthForSignUp['product/google-apps']=415;
reduseWidthForSignUp['plugin/fogbugz']=415;




function displayLoginWidjets(){		
	overlayDivHeight = 310;
	//overlayDivHeight = 432;
	overlayDivWidth = 760;
	scorolling = 'auto';	
	hideUnTransparentElements(true);
	//content = '/login/widget'+window.location.search;
	var content = 'signin-mainbox';	

	loadThisWidjets( overlayDivHeight, overlayDivWidth, content,scorolling);
	
	// grt remember me from cookie
	var remember = $.cookie("remember");
	if ( remember == "true" ) {	
		var username = $.cookie("username");
		var password = $.cookie("password");		
		// autofill the fields
		$("#usr_lg_mail").attr("value", username);
		$("#usr_lg_pass").attr("value", password);
		$('#remember').attr('checked',1);
	}

}

function displaySignUpWidjets(){		
	overlayDivHeight = 445;
	//overlayDivHeight = 557;
	//overlayDivHeight = 370;
	overlayDivWidth = 800;
	scorolling = 'auto';
	hideUnTransparentElements(true);
	//content = '/signup/widget'+window.location.search;
	var content = 'overlay-sign-up-content';
	
	var currentUrl = parent.location;	
	var parentPage = trim(currentUrl.pathname.substring(1));	
	if( typeof reduseWidthForSignUp[parentPage]!="undefined" && reduseWidthForSignUp[parentPage] ){		
		overlayDivHeight = reduseWidthForSignUp[parentPage];
	}	
	loadThisWidjets( overlayDivHeight, overlayDivWidth, content,scorolling);

}

function loadThisWidjets( overlayDivHeight, overlayDivWidth, content,scorolling){
	
	document.cookie = 'JSESSIONID=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
	document.getElementById('creately-popup-content').style.display = 'none';
	document.getElementById('creately-popup-close').style.display = 'block';
	
	document.getElementById('creately-popup-border').style.display = 'block';
	//document.getElementById('creately-popup-border').style.overflow= 'auto';
	//document.getElementById('creately-popup-border').style.overflow-y= 'auto';
	//document.getElementById('creately-popup-border').style.overflow-x= 'hidden';
	//overflow-y: auto; overflow-x:hidden
	document.getElementById('creately-popup-border').style.width = overlayDivWidth + 'px';
	document.getElementById('creately-popup-border').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-working').style.width = overlayDivWidth + 'px';
	//document.getElementById('creately-popup-working').style.height = overlayDivHeight + 'px';
	document.getElementById('creately-popup-working').innerHTML = '<div id="pContent"><p>Loading Creately login form .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	topleftcorner = viewport_size(overlayDivWidth, overlayDivHeight, 'CENTER');
	document.getElementById('creately-popup').style.top = topleftcorner[0] + 'px'; //top 
	document.getElementById('creately-popup').style.left = topleftcorner[1] + 'px'; //left

	document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
	//document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';	
	document.getElementById('creately-popup-content').innerHTML = document.getElementById(content).innerHTML;
	
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-popup-content').style.backgroundColor = '#FFFFFF';
	document.getElementById('creately-popup-content').style.display = 'inline';
	
	document.getElementById('creately-overlay').onclick = '';
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';
	
}

function displaySignupLightBox(){
	$(document).ready(function() {
		$('.test-a').attr('href', '/signup/widget');
		$('.test-a').attr('rel', 'lightframe[search|width:900px; height:560px; scrolling: auto;]');
		$( '.test-a' ).trigger ( 'click' );
		$('.test-a').attr('href', '/login/widget');
		$('.test-a').attr('rel', 'lightframe[search|width:777px; height:381px; scrolling: auto;]');
	});
}

function displayLoginLightBox(){
	$(document).ready(function() {
		$('.test-a').attr('href', '/login/widget');
		$('.test-a').attr('rel', 'lightframe[search|width:777px; height:381px; scrolling: auto;]');
		$( '.test-a' ).trigger ( 'click' );
	});
}

function refresh(){
	//cancelOverlay();
	window.location.reload();
}



