/*
 * This library provides the functions to display the overlay DIVs which 
 * provide profile and wait functionality to Creately
 * */

var starsSaved = false;
var topleftcorner = new Array();
var starrating = 0;
var saveid = null;
var userLoggedIn = false;

function displayFeedback() {
	UserVoice.Popin.setup({
		key: 'creately',
		host: 'support.creately.com',
		forum: 'general'
	})
	UserVoice.Popin.show(); return false;
	/*
	GSFN.show();
	return false;
	*/	
}

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(onoff) {
			document.getElementById('htmltop').className = 'popup-open-reduce';
		} else {
			document.getElementById('htmltop').className = '';
		}
	}
	userLoggedIn = false;
}

function displayProfile(){			
	overlayDivHeight = 280;
	overlayDivWidth = 315;
	hideUnTransparentElements(true);
	document.getElementById('creately-popup-content').style.display = 'none';
	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 your Creately profile .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	profile_url = "/jupiter/profileController.jsp";
	
	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
	var displayHTML = "";
	var myAJAX = new ajaxObject(profile_url);
	myAJAX.callback = function(responseText, responseStatus) {
		if (responseStatus == 200) {
			displayHTML = responseText;
		} else {
			displayHTML = '<div id="pContent"><p>There was a problem fetching your profile. Please contact <a href="mailto:support@creately.com">support@creately.com</a></p></div>';
		}
		document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
		document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';
		document.getElementById('creately-popup-content').innerHTML = displayHTML;
		document.getElementById('creately-popup-content').innerHTML = displayHTML;
		document.getElementById('creately-popup-working').style.display = 'none';
		document.getElementById('creately-popup-content').style.display = 'block';
		
	}
	postData = 'cProfile=D';
	myAJAX.update(postData, 'POST');
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';

}

function clearJupiterCookie() {
	deleteCookie('JSESSIONID');
}

function displayLogin(){
	document.cookie = 'JSESSIONID=0; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
	overlayDivHeight = 240;
	overlayDivWidth = 315;
	hideUnTransparentElements(true);
	
	if (true) {
		displaySleepScreen(515, 265);
	} else {
	
		document.getElementById('creately-overlay').style.backgroundColor = '#4C4C4C';
		document.getElementById('creately-overlay').style.opacity = '1';
		login_url = "/session_expired";
		document.getElementById('creately-popup-content').style.display = 'none';
		document.getElementById('creately-popup-close').style.display = 'none';
		
		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 displaySleepScreen(overlayDivWidth, overlayDivHeight){

	overlayDivHeight = 250;
	overlayDivWidth = 500;
	hideUnTransparentElements(true);
	
	document.getElementById('creately-overlay').onclick = '';
	document.getElementById('creately-popup-content').style.display = 'none';
	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>Creately is going to sleep .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	//document.getElementById('creately-overlay').style.backgroundColor = '#4C4C4C';
	//document.getElementById('creately-overlay').style.opacity = '1';
	//document.getElementById('creately-popup-content').style.display = 'none';
	sleeping_url = "/session_sleeping";
	document.getElementById('creately-popup-close').style.display = 'none';
	
	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-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>Creately is going to sleep .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	//document.getElementById('creately-popup-working').style.display = 'block';

	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="' + sleeping_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-content').style.backgroundColor = '#FFFFFF';
	document.getElementById('creately-popup-content').style.display = 'inline';
	
	document.getElementById('creately-popup-working').style.display = 'none';
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';

}

function displayNotification(){
	overlayDivHeight = 250;
	overlayDivWidth = 500;

	var usersname = 'Creately User';
	planapi_url = '/browser/userplan';
	var myAJAX = new ajaxObject(planapi_url);
	//alert(myAJAX);
	myAJAX.callback = function(responseText, responseStatus, responseXML) {
		//alert(responseText);
		//alert(responseStatus);
		//alert(responseXML);
		if (responseStatus == 200) {
			//alert(responseXML.getElementsByTagName("userplantype")[0].childNodes[0].nodeValue);
			if(responseXML.getElementsByTagName("userplantype")[0]) {
				if(responseXML.getElementsByTagName("userplantype")[0].childNodes[0].nodeValue == 'free') {
		
					usersname = responseXML.getElementsByTagName("realname")[0].childNodes[0].nodeValue;
					hideUnTransparentElements(true);
					document.getElementById('creately-overlay').style.backgroundColor = '#4C4C4C';
					document.getElementById('creately-overlay').style.opacity = '1';
					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 = '<div id="pContent"><div id="reminder-popup-wrapper"><h3>Hi ' + usersname + ',</h3><p>We\'ve noticed that you\'re on the <strong>Creately Free plan</strong> with<br />limited functionality &amp; Public-only diagrams. Would you like to<br />see our <strong>Premium plans</strong> with <strong>Full Team Collaboration</strong> features<br/> and <strong>Unlimited Private Diagrams</strong>?\n<p>\n<div id="reminder-buttons"><a href="#" onclick="launchPlans();"><img src="/images/view_plans.png" alt="View Creately plans and pricing"></a><a href="#" onclick="cancelOverlay();"><img src="/images/remindme_later.png" alt="Remind me later" ></a></div></div></div>';;
					document.getElementById('creately-popup-working').style.display = 'none';
					document.getElementById('creately-popup-content').style.backgroundColor = '#FFFFFF';
					document.getElementById('creately-popup-content').style.display = 'block';
					
					document.getElementById('creately-overlay').onclick = 'cancelOverlay';
					document.getElementById('creately-overlay').style.display = 'block';
					document.getElementById('creately-popup').style.display = 'block';
				}
			}
		}
	}
	myAJAX.update('');

}

function launchPlans() {
	
	window.open("/plans?inappsignup=1", "signupplans", "menubar=yes, toolbar=yes, scrollbars=yes");
}

function displayLoginSignupWidget(){
	overlayDivHeight = 325;
	overlayDivWidth = 600;
	hideUnTransparentElements(true);
	login_signup_url = "/creately_no_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 name="signuppopup" id="signuppopup" src="' + login_signup_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 saveProfile(){
	overlayDivHeight = 260;
	overlayDivWidth = 315;
	document.getElementById('creately-popup-working').innerHTML = '<div id="pContent"><p>Saving your Creately profile .... <img src="/custom_inc/images/loading.gif" /></p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	document.getElementById('creately-popup-content').style.display = 'none';
	profile_url = "/jupiter/profileController.jsp";
	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
	var displayHTML = "";
	var myAJAX = new ajaxObject(profile_url);
	myAJAX.callback = function(responseText, responseStatus) {
		if (responseStatus == 200) {
			displayHTML = responseText;
		} else {
			displayHTML = '<div id="pContent"><p>There was a problem fetching your profile. Please contact <a href="mailto:support@creately.com">support@creately.com</a></p></div>';
		}
		document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
		document.getElementById('creately-popup-content').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-content').innerHTML = displayHTML;
		document.getElementById('creately-popup-working').style.display = 'none';
		document.getElementById('creately-popup-content').style.display = 'block';
	}
	postData = 'cProfile=S';
	postData += '&p_firstname=' + document.getElementById('p_firstname').value;
	postData += '&p_lastname=' + document.getElementById('p_lastname').value;
	postData += '&p_curpassword=' + document.getElementById('p_curpassword').value;
	postData += '&p_newpassword=' + document.getElementById('p_newpassword').value;
	postData += '&p_newpassword_confirm=' + document.getElementById('p_newpassword_confirm').value;
	myAJAX.update(postData, 'POST');
}

function displayWait(state) {
	if(state) {
		document.getElementById('creately-popup').style.display = 'block';
		document.getElementById('creately-overlay').style.display = 'block';
	} else {
		document.getElementById('creately-popup').style.display = 'none';
		document.getElementById('creately-overlay').style.display = 'none';
	}
}

/*
function debugObject(obj) {
	var str;
	for(prop in obj) {
		str+=prop + ' value :'+ obj[prop]+'<br />\n';//Concat prop and its value from object
	}
	
	//document.getElementById('creately-popup').innerHTML = str
	//alert(str);
	
}
*/

function getFlashMovie(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName]; 
		}
	} else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
	}
}

function notifyLoginDone() {
	var obj = getFlashMovie("creately");
	if (obj && typeof obj.internalLoginComplete != "undefined") {
		obj.internalLoginComplete(true);
		/*
		if (navigator.appName.indexOf("Microsoft Internet")==-1) {
			obj.internalLoginComplete(true);
		} else { //For IE don't do anything.
			obj.internalLoginComplete(true);
		}
		*/
	} else {
		alert('There was a problem re-activating your Creately session. This could be because your browser doesn\'t support Javascript to Flash communication. We\'ll now send you back to Creately, if it doesn\'t start working as expected please refresh the web page with the app in it to make sure you don\'t loose work.');
	}
	cancelOverlay();
}

function notifyDemoLoginRegisterDone() {
	var obj = getFlashMovie(swfname);
	if (obj && typeof obj.demoUserLoginComplete != "undefined") {
		obj.demoUserLoginComplete(true, false);
		/*
		if (navigator.appName.indexOf("Microsoft Internet")==-1) {
			obj.demoUserLoginComplete(true);
		} else { //For IE don't do anything.
			obj.demoUserLoginComplete(true);
		}
		*/
	} else {
		alert('There was a problem granting you access to Creately. This could be because your browser doesn\'t support Javascript to Flash communication. We\'ll now send you back to Creately, if it doesn\'t start working as expected please refresh the web page by pressing F5.');
	}
	userLoggedIn = false;
	cancelOverlay();
}

//Use demoUserLoginComplete call even if the user just closes the sign up widget.
//If failed login does it go back to the demo user.


function cancelOverlay() {

	if ( userLoggedIn ) {
		userLoggedIn = false;
		notifyDemoLoginRegisterDone();
	} else {
		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 displayStarRating() {
	overlayDivHeight = 278;
	overlayDivWidth = 435;
	hideUnTransparentElements(true);
	starsSaved = false;
	loadStars(true);
	document.getElementById('creately-popup-content').style.display = 'none';
	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 feedback widget .... <img src="/custom_inc/images/loading.gif" /></p><p>Stay on this page by closing the browser popup above to display the star rating widget.</p></div>';
	document.getElementById('creately-popup-working').style.display = 'block';
	
	profile_url = "/creately_interact/star_rating_content.php";
	topleftcorner = viewport_size(overlayDivWidth, overlayDivHeight, 'SOUTH');
	document.getElementById('creately-popup').style.top = topleftcorner[0] + 'px'; //top 
	document.getElementById('creately-popup').style.left = topleftcorner[1] + 'px'; //left
	var displayHTML = "";
	var myAJAX = new ajaxObject(profile_url);
	myAJAX.callback = function(responseText, responseStatus) {
		if (responseStatus == 200) {
			displayHTML = responseText;
		} else {
			displayHTML = '<div id="pContent"><p>There was a problem fetching the star rating page. Please contact <a href="mailto:support@creately.com">support@creately.com</a></p></div>';
		}
		document.getElementById('creately-popup-content').style.width = overlayDivWidth + 'px';
		document.getElementById('creately-popup-content').style.height = overlayDivHeight + 'px';
		document.getElementById('creately-popup-content').innerHTML = displayHTML;
		document.getElementById('creately-popup-working').style.display = 'none';
		document.getElementById('creately-popup-content').style.display = 'block';
		document.getElementById('creately-popup-border').style.display = 'block';
		
	}
	myAJAX.update();
	document.getElementById('creately-overlay').style.display = 'block';
	document.getElementById('creately-popup').style.display = 'block';
	
}

function toggleFeedbackWidget() {
	if(document.getElementById('hideoneweek').checked) {
		setCookie('disableFW', '0', 7);
	} else {
		deleteCookie('disableFW');
	}
}

/*Set a cookie name, value and expiry - omit expiredays for a session cookie*/
function setCookie(c_name, value, expiredays) {
	if(expiredays) {
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		var expires = "; expires=" + exdate.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = c_name + "=" + escape(value) + expires + "; path=/";
}

/*Get a cookie by name*/
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		} else {
			return false;
		}
	}
	return false;
}

/*Check is a cookie is set - returns true or false*/
function checkCookie(c_name) {
	cookie=getCookie(c_name);
	if (!cookie) {
		return false;
	} else {
		return true;
	}
}

/*Remove a cookie by setting the expiry one day in the past*/
function deleteCookie(c_name) {
	setCookie(c_name, 'null', -1);
}

function saveStars(numStars) {
	saveURL = '/creately_interact/star_rating_save_ajax.php';
	if(!starsSaved) {
		starrating = numStars;
		var myAJAX = new ajaxObject(saveURL);
		myAJAX.callback = function(responseText, responseStatus, responseXML) {
			if (responseStatus == 200) {
				var result_status = responseXML.getElementsByTagName("status")[0].childNodes[0].nodeValue;
				if(result_status == "saved") {
					if(saveid == null) {
						saveid = responseXML.getElementsByTagName("saveid")[0].childNodes[0].nodeValue;
					}
					document.getElementById("vote").innerHTML = "Thank you. <a onclick=\"resetStars();\" style=\"cursor:pointer;text-decoration:underline;\">Click here</a> to select a new star rating.";
				}
			}
		}
		postdata = 'savestar=1&uid=' + encodeURIComponent(createlyUsersId) + '&starrating=' + encodeURIComponent(starrating);
		if(saveid != null) {
			postdata += '&saveid=' + saveid;
		}
		myAJAX.update(postdata, 'POST');
		starsSaved = true;
	}
}

function sendStarComments() {
	saveURL = '/creately_interact/star_rating_save_ajax.php';
	SRText = document.getElementById('f_SRContent').value;
	var myAJAX = new ajaxObject(saveURL);
	myAJAX.callback = function(responseText, responseStatus, responseXML) {
		if (responseStatus == 200) {
			var result_status = responseXML.getElementsByTagName("status")[0].childNodes[0].nodeValue;
			if(result_status == "saved") {
				feedback_given = true;
				cancelOverlay();
			}
		}
	}
	postdata = 'savestarcomment=1&uid=' + encodeURIComponent(createlyUsersId) + '&starrating=' + starrating + '&comments=' + encodeURIComponent(SRText);
	if(saveid != null) {
		postdata += '&saveid=' + saveid;
	}
	myAJAX.update(postdata, 'POST');
	
}

function noStarRating() {
	//feedback_given = true;
	cancelOverlay();
}

function resetStars() {
	set = false;
	starsSaved = false;
	document.getElementById('vote').innerHTML= "&nbsp;";
	//document.getElementById("votereset").innerHTML = "&nbsp;";
	for (i=1;i<6;i++) {
		document.getElementById(i).src= starempty.src;
	}
}

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;
}
