

var videomail_rules = {
	'div.flash_message' : function(el) {
		new Effect.Highlight(el, {startcolor:'#4CA0E1', endcolor:'#FFFFFF', duration: 4.0});
	},
	'div.error_message' : function(el) {
		new Effect.Highlight(el, {startcolor:'#EF4A4A', endcolor:'#FFEFEF', duration: 4.0});
	},
	'a.image_description_old' : function(e1) {
		initBox('divoverlay');
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			objectID = 0;
			if (theObject.id.lastIndexOf('_') != -1) {
				objectID = theObject.id.substring(theObject.id.lastIndexOf('_') + 1);
			}
			if (objectID > 0) {
				deldivhtml = '<div class="loading">Loading Photo Caption ...</div>';
				new Ajax.Updater('divoverlay','/images/title/' + objectID, {asynchronous:true, evalScripts:true});
				showBox(e,200,120,deldivhtml);
				return false;
			}
		}
	},
	'img.image_description_icon' : function(e1) {
		initBox('divoverlay');
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			objectID = 0;
			if (theObject.id.lastIndexOf('_') != -1) {
				objectID = theObject.id.substring(theObject.id.lastIndexOf('_') + 1);
			}
			if (objectID > 0) {
				deldivhtml = '<div class="loading">Loading Photo Caption ...</div>';
				new Ajax.Updater('divoverlay','/images/title/' + objectID, {asynchronous:true, evalScripts:true});
				showBox(e,200,120,deldivhtml);
				return false;
			}
		}
	},
	'img.theme_select' : function(e1) {
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			objectID = 0;
			if (theObject.id.lastIndexOf('_') != -1) {
				objectID = theObject.id.substring(theObject.id.lastIndexOf('_') + 1);
			}
			
			var elementList = document.getElementsByClassName("theme_select");
			var elCount = elementList.length;
			for (i = 0; i < elCount; i++) {
				Element.removeClassName(elementList[i], 'selected');
			}
			
			$('current_theme').value = objectID;
			updateSetting('theme_id',objectID);
			//Element.removeClassName(element, className);
			
			theObject.addClassName('selected');
		}
	},
	'img.card_theme_select' : function(e1) {
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			objectID = 0;
			if (theObject.id.lastIndexOf('_') != -1) {
				objectID = theObject.id.substring(theObject.id.lastIndexOf('_') + 1);
			}
			
			var elementList = document.getElementsByClassName("card_theme_select");
			var elCount = elementList.length;
			for (i = 0; i < elCount; i++) {
				Element.removeClassName(elementList[i], 'selected');
			}
			
			$('current_theme').value = objectID;
			//updateSetting('theme_id',objectID);
			//Element.removeClassName(element, className);
			
			theObject.addClassName('selected');
		}
	},
	'span.helptip' : function(e1) {
		initBox('tooltip');
		var theObject = $(e1.id);
		//theObject.onclick = function(e) {
			//var tiphtml = '';
			//tiphtml += '<img src="/img/pop/close.png" class="close_button" onclick="_hideBox(\'tooltip\', 0.3);" alt="Close" title="Close" />';
			//tiphtml += '<img src="/img/helptip_large.gif" class="helptip_icon" alt="Tip" />' + theObject.getAttribute('title');
			//_showBox(e, 300, 'auto', tiphtml, 'tooltip', 0.8, 2, 2);
			
		//}
		new Tooltip(theObject, {mouseFollow: false, backgroundColor: "#FFF", maxWidth: "350", borderColor: "#666", opacity: ".85"} );
		
	}
};

Behaviour.register(videomail_rules);



Event.observe(window, 'load', function() {
	if ($('more_services')) {
		IESelectHack('more_services_list');
		$('more_services_list').setStyle({'zIndex':'5000'});
		$('more_services').setStyle({'display':'block'});
		Event.observe('more_services', 'click', function() {
				$('more_services_list').setStyle({'display':'block'});
			});
		Event.observe('more_services', 'mouseover', function() {
				showMoreServices();
			});
		Event.observe('more_services', 'mouseout', function() {
				hideMoreServices();
			});
		Event.observe('more_services_list', 'mouseover', function() {
				showMoreServices();
			});
		Event.observe('more_services_list', 'mouseout', function() {	
				hideMoreServices();
			});
	}
});

var serviceMenuTimeout = {};
var showMoreServices = function() {
	clearTimeout(serviceMenuTimeout);
	serviceMenuTimeout = setTimeout(function() { $('more_services_list').setStyle({'display':'block'});  }, 500);
}
var hideMoreServices = function() {
	clearTimeout(serviceMenuTimeout);
	serviceMenuTimeout = setTimeout(function() { $('more_services_list').setStyle({'display':'none'}); }, 800);
}

function IESelectHack(elmStr) {
	var userAgent = navigator.userAgent.toLowerCase();
	if (/msie 6.0/.test( userAgent ) && !/opera/.test( userAgent ) ) {
		$(elmStr).insert({'after': '<iframe style="display:block;position:absolute;top:0;left:0;z-index:-1;filter:mask();width:expression(this.parentNode.offsetWidth);height:expression(this.parentNode.offsetHeight)"/>' });
	}
}



var changeSearch = function(elmSelected,likeClass,siteInput,siteValue) {
	$$(likeClass).invoke('removeClassName','selected');
	$(elmSelected).addClassName('selected');
	$(siteInput).value = siteValue;
}



function showTab(tab_selected, panel_selected) {
	var panelList = document.getElementsByClassName("panel");
	var tabList = document.getElementsByClassName("tab");
	var panelCount = panelList.length;
	for(i=0;i<panelCount;i++) {
		$(panelList[i]).style.display = 'none';
		$(tabList[i]).style.fontWeight = 'normal';
	}
	$(panel_selected).style.display = 'block';
	$(tab_selected).style.fontWeight = 'bold';
}

function show_controls(the_div) {
	var queue = Effect.Queues.get('control_scope');
	queue.each(function(e) { e.cancel() });
	new Effect.Appear(the_div, { duration: 1, queue: {position:'end', scope: 'control_scope'} });
}
function hide_controls(the_div) {
	var queue = Effect.Queues.get('control_scope');
	queue.each(function(e) { e.cancel() });
	new Effect.Fade(the_div, { duration: 1, queue: {position:'end', scope: 'control_scope'} });
}

function checkPasswordEnable(checkbox, passinput) {
	if (passinput.value != '') {
		checkbox.checked = true;
	}
}




function initBox(divname) {
		// 'divoverlay'
	if (!document.getElementById(divname)) {
		var objBody = document.getElementsByTagName("body").item(0);
		
		var divOverlay = document.createElement("div");
		divOverlay.setAttribute('id',divname);
		divOverlay.style.display = 'none';
		divOverlay.style.position = 'absolute';
		divOverlay.style.top = '0';
		divOverlay.style.left = '0';
		divOverlay.style.zIndex = '4220';
		//divOverlay.style.width = '140px';
		//divOverlay.style.height = '90px';
		objBody.insertBefore(divOverlay, objBody.firstChild);
	}
}

function showBoxAbs(divY, divWidth, divHeight, theInnerHtml) {
	_showBoxAbs(divY, divWidth, divHeight, theInnerHtml, 'divoverlay', 0.5);
}
function _showBoxAbs(divY, divWidth, divHeight, theInnerHtml, whichDiv, dur) {
	initBox('divoverlay');
	
	var objDivOverlay = $(whichDiv);

	if (typeof window.innerWidth!='undefined') {
			windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0) {
				windowWidth = document.documentElement.clientWidth;
		} 
		else {
			if (document.body && typeof document.body.clientWidth!='undefined') {
				windowWidth = document.body.clientWidth;
			}
		}	
	}
	

	divX = ((windowWidth - divWidth) / 2);

	objDivOverlay.style.top = divY + 'px';
	objDivOverlay.style.left = divX + 'px';
	objDivOverlay.style.width = divWidth + 'px';
	if (divHeight != 'auto') {
		objDivOverlay.style.height = divHeight + 'px';
	}
	//objDivOverlay.style.zIndex = 3000;

	objDivOverlay.innerHTML = theInnerHtml;
	objDivOverlay.style.display = '';
	//Effect.Appear(objDivOverlay, { duration: dur,  queue: {position:'front', scope: 'floating_div', limit:1}  });
	
}

function showBox(e, divWidth, divHeight, theInnerHtml) {
	_showBox(e, divWidth, divHeight, theInnerHtml, 'divoverlay', 0.5, 0, 0);
}

function _showBox(e, divWidth, divHeight, theInnerHtml, whichDiv, dur, x_offset, y_offset) {
	
	initBox('divoverlay');
	
	var objDivOverlay = $(whichDiv);
	
	if (!e) var e = window.event;
	var left = Event.pointerX(e);
	var top = Event.pointerY(e);
		// Check to be sure it doesn't run off the page
	var windowWidth = 99999999;
	if (typeof window.innerWidth!='undefined') {
			windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0) {
				windowWidth = document.documentElement.clientWidth;
		} 
		else {
			if (document.body && typeof document.body.clientWidth!='undefined') {
				windowWidth = document.body.clientWidth;
			}
		}	
	}
	if ((left + parseInt(divWidth) + 10) > windowWidth) {
		left = left - parseInt(divWidth);
	}
	
	left = left + x_offset;
	top = top + y_offset;
	
	objDivOverlay.style.top = top + 'px';
	objDivOverlay.style.left = left + 'px';
	objDivOverlay.style.width = divWidth + 'px';
	if (divHeight != 'auto') {
		objDivOverlay.style.height = divHeight + 'px';
	}
	//objDivOverlay.style.zIndex = 3000;
	
//	objDivOverlay.style.background = '#FFFFFF';
//	objDivOverlay.style.border = '1px black solid';
//	objDivOverlay.style.color = '#000000';
//	objDivOverlay.style.textAlign = 'center';
//	objDivOverlay.style.margin = 'auto';
	
	objDivOverlay.innerHTML = theInnerHtml;
	objDivOverlay.style.display = '';
	//Effect.Appear(objDivOverlay, { duration: dur,  queue: {position:'front', scope: 'floating_div', limit:1} });
}

function changeBoxLength(divHeight) {
	var objDivOverlay = $('divoverlay');
	objDivOverlay.style.height = divHeight + 'px';
}

function hideBox() {
	modalWindow.hide();
}

	
function _hideBox(whichDiv, dur) {
	var objDivOverlay = $(whichDiv);
	//Effect.Fade(objDivOverlay, { duration: dur,  queue: {position:'end', scope: 'floating_div', limit:1} });
	objDivOverlay.style.display = 'none';
}


//var updateOrder = function() {
//	new Ajax.Request('/users/updateorder/?' + Sortable.serialize('image_list') , {asynchronous:true, onSuccess:saveSuccess});
//}
//var saveSuccess = function(t) {
//	$('list_update').innerHTML = "You image order has been updated.";
//	$('list_update').style.padding = "2px";
//	$('list_update').style.margin = "5px";
//	$('list_update').style.textAlign = "center";
//	$('list_update').style.fontWeight = "bold";
//	new Effect.Highlight('list_update', {startcolor:'#4CA0E1', endcolor:'#FFFFFF', duration: 2.0});			
//}

function rotateImage(imageID, direction) {
	new Ajax.Updater('image_' + imageID, '/images/rotate/' + imageID + '/' + direction , {asynchronous:true, evalScripts:true});
	return false;
}
function rotateImage2(imageID, direction) {
	new Ajax.Updater('preview_image_' + imageID, '/images/rotate/' + imageID + '/' + direction + '/preview/' , {asynchronous:true, evalScripts:true});
	return false;
}


function removeImage(imageID) {
	new Ajax.Updater('list_update', '/images/remove/' + imageID + '/' , {asynchronous:true, evalScripts:true});
	return false;
}

function editImage(messageID, imageID) {
	Modalbox.show('/users/editimage/' + messageID + '/' + imageID + '/?_cc=' + Math.random(), {title: 'Edit Image', width: 740, height: 540, afterLoad: function() {   } });
	return false;
}
function makeInPlaceEditor(in_id, url) {
	alert($(in_id).innerHTML);
	new Ajax.InPlaceEditor(in_id, url);
}
	

function attachImage(imageID) {
	new Ajax.Updater('library_update', '/images/attach/' + imageID + '/?cc=' + Math.random() , {asynchronous:true, evalScripts:true});
	return false;
}

function changeMessage(selectObject, messageType, code) {	
	var message_id = $F(selectObject);
	//deldivhtml = '<div class="loading"><center>Loading Image Library ...</center></div>';
	//showBoxAbs(200,600,415,deldivhtml);
	//new Ajax.Updater('divoverlay',"/users/imagelibrary/" + messageType + "/1/15/" + message_id + "/", {asynchronous:true, evalScripts:true});
	Modalbox.show('/users/imagelibrary/' + messageType + '/1/15/' + message_id + '/', {title: 'Add Photos', width: 640, height: 460, afterHide: function() { document.location.href='/' + messageType + '/add/' + code + '/?cc=' + Math.random(); } });
	return false;
}

function showLibrary(messageType) {
	deldivhtml = '<div class="loading"><center>Loading Image Library ...</center></div>';
	showBoxAbs(200,600,415,deldivhtml);
	new Ajax.Updater('divoverlay','/users/imagelibrary/' + messageType + '/?cc=' + Math.random(), {asynchronous:true, evalScripts:true});
	return false;
}

function showUpload(messageType, code) {
	windowHeight = 400;
	try {
		if (screen.height > 600) {
			windowHeight = 550;
		}
		else {
			windowHeight = 400;
		}
	}
	catch(err) { }
	
	Modalbox.show('/users/imageuploader/' + messageType + '/?cc=' + Math.random(), {title: 'Photo Uploader', width: 700, height: windowHeight, afterHide: function() { document.location.href='/' + messageType + '/add/' + code + '/?cc=' + Math.random(); } });
	
	return false;
}
function showUploadOS(messageType, code) {
	
	Modalbox.show('/users/imageuploader/' + messageType + '/single/?cc=' + Math.random(), {title: 'Photo Uploader', width: 500, height: 170, afterHide: function() { document.location.href='/' + messageType + '/add/' + code + '/'; } });
	
	return false;	
}
function showUploadMU(messageType, code) {
	
	Modalbox.show('/users/imageuploader/' + messageType + '/multi/?cc=' + Math.random(), {title: 'Photo Uploader', width: 500, height: 370, afterHide: function() { document.location.href='/' + messageType + '/add/' + code + '/'; } });

	return false;	
}
function showUploadAU(messageType, code) {
	windowHeight = 400;
	try {
		if (screen.height > 600) {
			windowHeight = 550;
		}
		else {
			windowHeight = 400;
		}
	}
	catch(err) { }
	
	Modalbox.show('/users/imageuploader/' + messageType + '/aurigma/?cc=' + Math.random(), {title: 'Photo Uploader', width: 700, height: windowHeight, afterHide: function() { document.location.href='/' + messageType + '/add/' + code + '/'; } });
	
	return false;

}



function showOrder(messageType, code) {
	Modalbox.show('/users/imageorder/' + messageType + '/', {title: 'Photo Order', width: 760, height: 400, afterHide: function() { document.location.href='/' + messageType + '/edit/' + code + '/?cc=' + Math.random(); } });
	return false;
}
function showMusicUpload() {
	//deldivhtml = '<div class="loading"><center>Loading Music Uploader ...</center></div>';
	//showBoxAbs(360,500,240,deldivhtml);
	//new Ajax.Updater('divoverlay','/users/musicuploader/', {asynchronous:true, evalScripts:true});
	Modalbox.show('/users/musicuploader/?cc=' + Math.random(), {title: 'Soundtrack Uploader', width: 500, height: 150 });
	return false;
}
function displayUploading() {
	$('uploaderFormDiv').style.height = '1px';
	$('uploaderFormDiv').style.width = '1px';
	$('uploaderFormDiv').style.overflow = 'hidden';
	$('uploaderMessageDiv').style.height = '90px';
	$('uploaderMessageDiv').style.width = '400px';
	$('uploaderMessageDiv').innerHTML = "<b>Please wait while your file is uploaded and converted.  This may take a few minutes.</b>";
	
	checkUploading('uploaderMessageDiv');	
}
function checkUploading(updateDiv) {
	new Ajax.PeriodicalUpdater(updateDiv, '/users/check_upload/', {asynchronous:true, frequency:4});
}
function showPreview(code) {
	Modalbox.show('/users/showpreview/', {title: 'Slide Show Preview', width: 750, height: 580, afterHide: function() { document.location.href='/photoshare/theme/'+code+'/'; } });
	return false;
}

var imageListClass = "even";
function setUploaderStatus(theMessage) {
	$('uploaderStatus').innerHTML = theMessage;
	return "Update: " + theMessage;
}
function addImage(newImageName, image_id) {
	if (imageListClass == "odd") {
		imageListClass = "even";
	}
	else {
		imageListClass = "odd";
	}
	$('uploaderImageList').innerHTML = $('uploaderImageList').innerHTML + '<div id="' + image_id + '" class="upload_list ' + imageListClass + '">' + newImageName + ' <a href="#" onclick="removeImageFlash(\'' + image_id + '\'); return false;">remove</a></div>';
	
	if ($('uploaderImageList').innerHTML != "") {
		$('add_button').disabled = false;	
	}
	
	return newImageName;
}
function removeImageFlash(removal_id) {
	$(removal_id).style.display = 'none';
	$('flash_uploader').removeImage(removal_id);
}
function startUploading() {
	$('uploaderImageList').style.display = "none";
	$('uploaderButtons').style.display = "none";
	return "Updated";						
}
function addVideo(newVideoName, video_id) {
	imageListClass = "odd";
	$('uploaderImageList').innerHTML = '<div id="' + video_id + '" class="upload_list ' + imageListClass + '">' + newVideoName + '</div>';
	if ($('uploaderImageList').innerHTML != "") {
		$('add_button').disabled = false;	
	}
	return newImageName;
}

function oldFlashVersion() {
	alert('Adobe Flash Player version 8 is required to upload multiple images at a time.  You may upload images one at a time, or visit adobe.com and download the latest Flash player.');
	showUploadOS();
}

var donotdisplay = false;
function showOrderPreview(e, imageURL) {
	initBox('image_preview');
	$('image_preview').style.zIndex = 500;
	theInnerHtml = '<img src="' + imageURL + '" ALT="Preview" />';
	_showBox(e, 120, 120, theInnerHtml, 'image_preview', 0.1, 30, -70);
}
function hideOrderPreview() {
	//_hideBox('image_preview', 0);
	var objDivOverlay = $('image_preview');
	objDivOverlay.style.display = 'none';
	//Effect.Fade(objDivOverlay, { duration: dur });
}

function deleteMessage(flash, code) {
		if (confirm("Are you sure you would like to delete this?")) {
			document.location.href = "/users/delete/" + flash + "/" + code + "/?confirm=1";
			return false;
		}
		return false;
}
function updateSetting(param, value) {
	if (param != '') {
		//alert('save_param=' + param + '&data_value=' + encodeURIComponent(value));
		new Ajax.Request('/users/saveMessageSetting/?save_param=' + param + '&data_value=' + encodeURIComponent(value), {asynchronous:true, method:'get' });
	}
}

function size_popup() {
	var height = parseInt($('content_div').offsetHeight);
	
	height = height;
	$('popleft').style.height = height + "px";
	$('popcenter').style.height = height + "px";
	$('popright').style.height = height + "px";
	
	height = height + 40;
	//alert("height: " + height);
	
	$('popdiv').style.height = height + "px";


	var width = parseInt($('content_div').offsetWidth);
	
	width = width;
	$('poptop').style.width = width + "px";
	$('popcenter').style.width = width + "px";
	$('popbottom').style.width = width + "px";
	
	width = width + 40;
	//alert("width: " + width);
	
	$('popdiv').style.width = width + "px";
	
}



function session_saver() {
	new PeriodicalExecuter(function(pe) {
		new Ajax.Request('/users/sessionsave/?', {asynchronous:true});
	}, 114);
}




function expandShow() {
	$('flashDiv').style.display = 'block';
	$('flashDiv').style.width = '640px';
	$('flashDiv').style.height = '480px';
	$('flash_show').width = '640';
	$('flash_show').height = '480';

	return 'resized';
}
		
function checkValidPassword(passwordInput, errorDiv) {
	var badChar = new Array("`","~","!","@","#","$","%","^","&","*","(",")","_","-","=","+","{","}","[","]",":",";","'",'"',"/","?","|","\\","<",">",",","."," ");
	var charCount = badChar.length;
	var passText = $F(passwordInput);
	for (i = 0; i < charCount; i++) {
		if (passText.indexOf(badChar[i]) > -1) {
			$(passwordInput).style.backgroundColor = "#EFC3C3";
			var error_char = badChar[i];
			if (error_char == ' ') {
				error_char = 'space';
			}
			$(errorDiv).innerHTML = "There is an invalid character in your password (" + error_char + ").<br />Please use letters or numbers.";
			$(errorDiv).style.display = '';
			$(errorDiv).style.marginLeft = '20px';
			$(errorDiv).style.color = '#CF1010';
			$(errorDiv).style.fontStyle = 'italic';
			return false;
		}
	}
	
	$(passwordInput).style.backgroundColor = "#FFFFFF";
	$(errorDiv).innerHTML = "";
	$(errorDiv).style.display = 'none';
	return true;
}


function showVideoPreview(code) {
	Modalbox.show('/view/' + code + '/ajax/', {title: 'Preview', width: 740, height: 540 });
	return false;
}
function showContestPreview(code) {
	Modalbox.show('/contest/view/' + code + '/ajax/', {title: 'Preview', width: 740, height: 540 });
	return false;
}

function enterContest(contest, code) {
	Modalbox.show('/contest/entercontest/' + contest + '/' + code + '/ajax/', {title: 'Preview', width: 700, height: 500 });
	return false;
}

function vote(contest, video_id, update_div) {
	new Ajax.Updater(update_div, '/contest/vote/' + contest + '/' + video_id, {evalScripts: true });
}

function promote(video_code, update_div) {
	new Ajax.Updater(update_div, '/contest/promote/' + video_code + '/', {evalScripts: true });
}
function sendPromote(video_code, update_div, name, friendemail, message) {
	name_string = $F(name);
	friendemail_string = $F(friendemail);
	message_string = $F(message);
	if(name_string.blank()) {
		alert('You must enter your name.');
		$(name).focus();
		return false;
	}
	if(friendemail_string.blank()) {
		alert('You must a valid email address to send to.');
		$(friendemail).focus();
		return false;
	}
	
	new Ajax.Updater(update_div, '/contest/promote/' + video_code + '/?name=' + name_string.escapeHTML() + '&friendemail=' + friendemail_string.escapeHTML() + '&message=' + message_string.escapeHTML(), {evalScripts: true });

}


function voteEmail(contest, video_id, email, dest, update_div, optin) {
	if (typeof optin == 'undefined' ) optin = '0';
	
	email = email.strip().toLowerCase();
	if (email.empty()) {
		alert('Please enter your email address to vote.');
		return false;
	}
	if (email.endsWith('@shaw.ca')) {
		alert('You must sign in to vote.  After sign in you will be directed back to this page for voting');
		document.location.href = '/users/login/?location=' + dest;
	}
	else {
		new Ajax.Updater(update_div, '/contest/vote/' + contest + '/' + video_id, {evalScripts: true, parameters: 'email=' + email + '&optin=' + optin });
	}
	
}

var checkContestSubmit = function() {
	if ($('agree').checked == false) { 
		alert('You must agree to the rules and regulations before you can enter.');
		return false;
	}
	var name = $F('displayname').strip();
	if (name.empty() || name == '') {
		alert('Enter a display name.  This name will be displayed with your entry.');
		return false;				
	}
	return true;
}


var validateEmail = function(email) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(email)) {
		return true;
	}
	else {
		return false;
	}
}

var showLoading = function(msg) {
	if (Object.inspect($('LoadingStatus')) == 'null') {
		StatusOverlay = Builder.node("div", { id: "StatusOverlay", opacity: "0" });
		LoadingStatus = Builder.node("div", { id: "LoadingStatus", opacity: "0" });
		
		document.body.insertBefore(LoadingStatus, document.body.childNodes[0]);
		document.body.insertBefore(StatusOverlay, document.body.childNodes[0]);
		
		Element.setOpacity('StatusOverlay',0.4);
	}
	
	Element.update(LoadingStatus, msg);
	
	SL_height = LoadingStatus.getHeight();
	SL_width = LoadingStatus.getWidth();
	
	SL_window = clientDims();
	
	LoadingStatus.setStyle({
      left: Math.round(SL_window[0] / 2 - SL_width / 2) + 'px',
      top:  Math.round(SL_window[1] / 2 - SL_height / 2)  + 'px'
    });
	
	LoadingStatus.show();
	StatusOverlay.show();
	
	
}
var hideLoading = function() {
	StatusOverlay.hide();
	LoadingStatus.hide();
}
var toggleSelects = function() {
	if (navigator.appVersion.match(/\bMSIE\b/))
		$$("select").each( function(select) { 
			select.style.visibility = (select.style.visibility == "") ? "hidden" : "";
		});	
}

var clientDims = function() {
	frameWidth = 0;
	frameHeight = 0;
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	return new Array(frameWidth, frameHeight);
}



function RTeSurvey(guid, hguid){
	var wOpen;
	theWidth  = 720;
	theHeight = 540;
	theTop=(screen.availHeight/2)-(theHeight/2);
	theLeft=(screen.availWidth/2)-(theWidth/2);
	features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	wOpen = window.open('http://ecollector.responsetek.com/collection/collection.aspx?cguid=' + guid +  '&hguid1='  + hguid + '&cType=1', 'eSurvey', features);
	wOpen.focus();

}


