function js_alert(sAlertText){
	alert(sAlertText)
}

var sUploadedImage;
var sImageToReplace;

function hide_flash_loading(){
	document.getElementById('loading_flash_div').style.display = 'none';
	document.getElementById('flash_div'        ).style.height  = '410px';

	if(document.getElementById('cover_flash_loading')){
		document.getElementById('cover_flash_loading').style.display = 'none';
	}

	//t = setTimeout('do_hide_flash_loading()', 500);
}

function do_hide_flash_loading(){
	document.getElementById('loading_flash_div').style.display = 'none';
	document.getElementById('flash_div'        ).style.height  = '410px';
}

var iLoadingDots = 3;
var iLoadingDotsTimeout = 200;

function update_loading_text(){

	objFlashText = document.getElementById('loading_flash_div')

	if ( parseInt(document.getElementById('loading_flash_text_0').style.top)==0 ){
		iLeftOffset = 355;
		iTopOffset  = 186;

		document.getElementById('loading_flash_text_0').style.top  = findPosY(objFlashText) + iTopOffset;
		document.getElementById('loading_flash_text_0').style.left = findPosX(objFlashText) + iLeftOffset;
		document.getElementById('loading_flash_text_1').style.top  = findPosY(objFlashText) + iTopOffset;
		document.getElementById('loading_flash_text_1').style.left = findPosX(objFlashText) + iLeftOffset;
		document.getElementById('loading_flash_text_2').style.top  = findPosY(objFlashText) + iTopOffset;
		document.getElementById('loading_flash_text_2').style.left = findPosX(objFlashText) + iLeftOffset;
		document.getElementById('loading_flash_text_3').style.top  = findPosY(objFlashText) + iTopOffset;
		document.getElementById('loading_flash_text_3').style.left = findPosX(objFlashText) + iLeftOffset;
	}


	if (document.getElementById('loading_flash_div').style.display==''){
		switch(iLoadingDots){
			case 0:
				document.getElementById('loading_flash_text_0').style.display = 'none';
				document.getElementById('loading_flash_text_1').style.display = '';
				document.getElementById('loading_flash_text_2').style.display = 'none';
				document.getElementById('loading_flash_text_3').style.display = 'none';
				iLoadingDots = 1;
				break;
			case 1:
				document.getElementById('loading_flash_text_0').style.display = 'none';
				document.getElementById('loading_flash_text_1').style.display = 'none';
				document.getElementById('loading_flash_text_2').style.display = '';
				document.getElementById('loading_flash_text_3').style.display = 'none';
				iLoadingDots = 2;
				break;
			case 2:
				document.getElementById('loading_flash_text_0').style.display = 'none';
				document.getElementById('loading_flash_text_1').style.display = 'none';
				document.getElementById('loading_flash_text_2').style.display = 'none';
				document.getElementById('loading_flash_text_3').style.display = '';
				iLoadingDots = 3;
				break;
			case 3:
				document.getElementById('loading_flash_text_0').style.display = '';
				document.getElementById('loading_flash_text_1').style.display = 'none';
				document.getElementById('loading_flash_text_2').style.display = 'none';
				document.getElementById('loading_flash_text_3').style.display = 'none';
				iLoadingDots = 0;
				break;
		}

		iUpdateLoadingText = setTimeout('update_loading_text()', iLoadingDotsTimeout)
	} else {
		document.getElementById('loading_flash_text_0').style.display = 'none';
		document.getElementById('loading_flash_text_1').style.display = 'none';
		document.getElementById('loading_flash_text_2').style.display = 'none';
		document.getElementById('loading_flash_text_3').style.display = 'none';        
	}

}

function update_width_height_x_y_rotation(sPartName, sValue){
	var arrValues = sValue.split("|");
	update_width(      sPartName, arrValues[0] );
	update_height(     sPartName, arrValues[1] );
	update_x_position( sPartName, arrValues[2] );
	update_y_position( sPartName, arrValues[3] );
	update_rotation(   sPartName, arrValues[4] );
}

function update_x_text(sPartName, sValue){
	var arrValues = sValue.split("|");
	update_x_position( sPartName, arrValues[0] );
	update_text(       sPartName, arrValues[1] );
}

function update_rotation(sPartName, sValue){
	document.getElementById(sPartName + '_rotation').value = sValue;
}

function update_alpha(sPartName, sValue){
	document.getElementById(sPartName + '_alpha').value = sValue;
}

function update_font(sPartName, sValue){
	document.getElementById(sPartName + '_font').value = sValue;
}

function update_colour(sPartName, sValue){
	document.getElementById(sPartName + '_colour').value = sValue;
}      

function update_bold(sPartName, sValue){
	document.getElementById(sPartName + '_bold').value = sValue;
}

function update_italic(sPartName, sValue){
	document.getElementById(sPartName + '_italic').value = sValue;
}

function update_align(sPartName, sValue){
	document.getElementById(sPartName + '_align').value = sValue;
}

function update_size(sPartName, sValue){
	document.getElementById(sPartName + '_size').value = sValue;
}

function update_x_position(sPartName, sValue){
	document.getElementById(sPartName + '_x').value = sValue;
}

function update_y_position(sPartName, sValue){
	document.getElementById(sPartName + '_y').value = sValue;
}

function update_width(sPartName, sValue){
	document.getElementById(sPartName + '_width').value = sValue;
}

function update_height(sPartName, sValue){
	document.getElementById(sPartName + '_height').value = sValue;
}

function update_text(sPartName, sValue){
	document.getElementById(sPartName + '_text').value = sValue;
}

function replace_image(sPartName){
	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		document.getElementById('flash_div'      ).style.height = 0;
	} else {
		document.getElementById('flash_div'      ).style.display = 'none';
	}
	document.getElementById('replace_image_div').style.display = '';
	
	get_clipart('');
	
	sImageToReplace = sPartName
}

function hide_image_form(){
	document.getElementById('replace_image_div').style.display = 'none';
	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		document.getElementById('flash_div'      ).style.height = '410px';
	} else {
		document.getElementById('flash_div'      ).style.display = '';
	}
}

function image_uploading(){
	// i could use this function to maybe display a loading thing, or disable the save button
}

function image_uploaded(sImageFile){
	sImageFile = 'uploaded_images/user_uploaded/' + sImageFile; 

	document.getElementById('replace_image_div').innerHTML = '&nbsp;';

	document.getElementById(sImageToReplace + '_src').value = sImageFile;
	document.getElementById('new_image_number').value = sImageToReplace;
	document.getElementById('save_form').submit();
}

function findPosX(obj) {
	// returns the x position of an object

	var curleft = 0;
	if(obj.offsetParent)
		while(1)
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	// returns the y position of an object

	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}         

function are_you_sure(sWarningText){
	doyou = confirm(sWarningText);

	if (doyou == true) {
		return true;
	} else {
		return false;
	}
}      

function stretch_to_page(objDivToStrech){
	var arrayPageSize = getPageSize();
	objDivToStrech.style.width  = arrayPageSize[0];
	objDivToStrech.style.height = arrayPageSize[1];
}

function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

function home_email_focus(){
	document.getElementById('div_email_label').style.display = 'none';
	document.getElementById('login_email').focus();
}
function home_email_lostfocus(){
	if ( document.getElementById('login_email').value=='' ) {
		document.getElementById('div_email_label').style.display = '';
	}
}
function home_password_focus(){
	document.getElementById('div_password_label').style.display = 'none';
	document.getElementById('login_password').focus();
}
function home_password_lostfocus(){
	if ( document.getElementById('login_password').value=='' ) {
		document.getElementById('div_password_label').style.display = '';
	}
}

function set_opacity(objTarget, iOpacity){
	objTarget.style.filter       = "alpha(opacity="+Math.round(iOpacity)+")"; // IE/
	objTarget.style.KHTMLOpacity = iOpacity/100;                              // safari<1.2, Konqueror
	objTarget.style.MozOpacity   = iOpacity/100;                              // Older Mozilla and Firefox
	objTarget.style.opacity      = iOpacity/100;                              // Safari 1.2, newer Firefox and Mozilla, CSS3 
}

iHomepageLabelCurrentLabel = 1;
iHomepageLabelCurrentOpacity = 100;
iHomepageLabelOpacityChange = -5;
iHomepageLabelLongPause = 3000;
iHomepageLabelShortPause = 20;

function start_fade_homepage_label(){
	t = setTimeout('fade_homepage_label()', iHomepageLabelLongPause);
}
function fade_homepage_label(){
	var iPause = iHomepageLabelShortPause;

	iHomepageLabelCurrentOpacity += iHomepageLabelOpacityChange;
	
	set_opacity( document.getElementById('sample_label_' + iHomepageLabelCurrentLabel), iHomepageLabelCurrentOpacity );
	
	if (iHomepageLabelCurrentOpacity==0){
		if (iHomepageLabelCurrentLabel == 1) {
			iHomepageLabelCurrentLabel = 2;
			iHomepageLabelOpacityChange = -5;
			iHomepageLabelCurrentOpacity = 100;
		} else {
			iHomepageLabelCurrentLabel = 1;
			iHomepageLabelOpacityChange = 5;
			iHomepageLabelCurrentOpacity = 0;
		}
		iPause = iHomepageLabelLongPause;
	} else {
		if (iHomepageLabelCurrentOpacity==100){
			if (iHomepageLabelCurrentLabel == 1) {
				iHomepageLabelCurrentLabel = 2;
				iHomepageLabelOpacityChange = 5;
				iHomepageLabelCurrentOpacity = 0;
			} else {
				iHomepageLabelCurrentLabel = 1;
				iHomepageLabelOpacityChange = -5;
				iHomepageLabelCurrentOpacity = 100;
			}
			iPause = iHomepageLabelLongPause;
		}
	}
	
	t = setTimeout('fade_homepage_label()', iPause);
}

function c_over( sColour, sColourPickerID ) {
	document.getElementById('csl-colour-picker-preview-' + sColourPickerID).style.background = '#' + sColour;
}

function c_click( sColour, sColourPickerID ) {
	document.getElementById('csl-colour-picker-colour-' + sColourPickerID).style.background = '#' + sColour;
	document.getElementById('textbox_colour_' + sColourPickerID).value = sColour;
}

function c_out( sColourPickerID ) {
	document.getElementById('csl-colour-picker-preview-' + sColourPickerID).style.background = '#' + document.getElementById('textbox_colour_' + sColourPickerID).value;
}