// JavaScript Document
if(navigator.userAgent.indexOf("Safari") > -1) var isSafari = true;

function safariAdjust(){
	if(isSafari){ 
		getObj("content").style.background = "#000000";	
		getObj("content").style.display = "none";	
		getObj("content").style.display = "";	
	}
}

//alert("isSafari = "+isSafari);
function insertFlash(swf, width, height, bgcolor, area, params){
	//if(isSafari && bgcolor==undefined) bgcolor="#000000";
	var flash = '<object ';
	flash += '	classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	flash += '	codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
	flash += '	width="'+width+'" ';
	flash += '	height="'+height+'" ';
	flash += '	align="middle">';
	flash += '	<param name="allowScriptAccess" value="sameDomain" />';
	flash += '	<param name="movie" value="'+swf+'" />';
	flash += '	<param name="quality" value="high" />';
	if(bgcolor) flash += '	<param name="bgcolor" value="'+bgcolor+'" />';
	else {
		flash += '	<param name="wmode" value="transparent" />';
		flash += '	<param name="scale" value="noscale" />';
	}
	if(params){
		paramArray = params.split("&");
		for(key in paramArray){
			paramParts = paramArray[key].split("=");
			flash += '	<param name="'+paramParts[0]+'" value="'+paramParts[1]+'" />';
		}
	}
	//if(isSafari) flash += '<param name="wmode" value="opaque" />';
	flash += '	<embed ';
	flash += '		src="'+swf+'" ';
	flash += '		quality="high" ';
	if(bgcolor) flash += '		bgcolor="'+bgcolor+'" ';
	else {
		flash += '		wmode="transparent" ';
		flash += '		scale="noscale" ';
	}
	if(params){
		for(key in paramArray){
			paramParts = paramArray[key].split("=");
			flash += '		'+paramParts[0]+'="'+paramParts[1]+'" ';
		}
	}
	//if(isSafari) flash += '		wmode="opaque" ';
	flash += '		width="'+width+'" ';
	flash += '		height="'+height+'" ';
	flash += '		align="middle" ';
	flash += '		allowScriptAccess="sameDomain" ';
	flash += '		type="application/x-shockwave-flash" ';
	flash += '		pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	flash += '</object>';	
	//alert(flash);
	if(area) getObj(area).innerHTML = flash;
	else document.write(flash);
}

//alert("new file");
popUpHandles = new Array();
function popUp(url, title, width, height, scrollbars){
	var x = (self.screen.width-width)/2;
	var y = (self.screen.height-height)/2;
	if(scrollbars) var myScroll = scrollbars;
	else var myScroll = "no";
	//alert('left='+x+',top='+y+',screenx='+x+', screeny='+y+',resizable=0, status=0,toolbar=0,scrollbars='+myScroll+',width='+width+',height='+height);
	popUpHandles[popUpHandles.length] = window.open(url,title,'left='+x+',top='+y+',screenx='+x+', screeny='+y+',resizable=0, status=0,toolbar=0,scrollbars='+myScroll+',width='+width+',height='+height);
}

function closeAllPopUps(){
	for(i=0;myPU=popUpHandles[i];i++){
		myPU.close();
	}
}

function getObj(obj){
	return document.getElementById(obj);
}

function swapClass(myID, myClass){
	getObj(myID).className = myClass;	
}

function changeImg(myImg,mySRC){
	getObj(myImg).src=mySRC;
}

function changePage(url){
	location.href = url;
}

function validateForm(formName,respondDiv){
	// This function will cause all form fields of formName that have a title attributes to be required
	var myForm = getObj(formName);
	for(i=0;i<myForm.length;i++){
		if(myForm[i].value == "" && myForm[i].title){ 
			alert("Please provide your "+myForm[i].title);
			return false;
		}
	}
	return true;
}

function setDivPosition(myObj,myX,myY){
	getObj(myObj).style.left = myX+"px";
	getObj(myObj).style.top = myY+"px";
}

function confirmURL(msg,url){
	if(confirm(msg)){
		location.href=url;
	}
}

function getUrlVars(){
	is_input = document.URL.indexOf('?');
	if (is_input != -1)	{ 
		// Create variable from ? in the url to the end of the string
		var_str = document.URL.substring(is_input+1, document.URL.length);
		var_array = var_str.split("&");
		var return_array = new Array();
		for(key in var_array){
			name_val = var_array[key].split("=");
			//alert(name_val[1]);
			return_array[name_val[0]] = name_val[1];
		}
		//for(key in return_array){
			//alert(key+" = "+ return_array[key]);
		//}
		return return_array;
	}	
	// If there is no ? in the url state no values found
	else{
		return false;
	}
}

function noVarUrl(){
	is_input = document.URL.indexOf('?');
	if (is_input != -1)	{
		return document.URL.substring(0,is_input);
	}
	else return document.URL
}

function getImgSize(imgSrc){
	var newImg = new Image();
	newImg.src = imgSrc;
	var height = newImg.height;
	var width = newImg.width;
	//alert ('The image size is '+width+'*'+height);
	return [width,height];
}
