function RTrim(s) {
	if(s == "") return s;
    return s.replace(/\s+$/,"")
}

function LTrim(s) {
	if(s == "") return s;
    return s.replace(/^\s+/,"")
}

function Trim(s) {
	if(s == "") return s;
    return RTrim(LTrim(s))
}


function validEmail(elem) {
    var str = elem;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
//        alert("Wrong email format : "+elem);
        return false;
    } else {
        return true;
    }
}

function open_close(id)
{
	a = document.getElementById(id).style;
	if(a.display == "block") {
		a.display = "none";
		} else {
			a.display="block";
		}

}

function open_close_folder(id, img_obj)
{
	var a = document.getElementById(id).style;
	if(a.display == "block") {
		a.display = "none";
		} else {
			a.display="block";
		}
	var img_type = img_obj.src.split("/");
	var filename = img_type[img_type.length-1];
	var new_path = img_type.slice(0, img_type.length-1);
	var new_img_path = new_path.join("/");

	if(filename == "plus.gif"){
		img_obj.src = new_img_path+"/minus.gif";
	} else {
		img_obj.src = new_img_path+"/plus.gif";
	}
	
}

function open_layer(id) {
	a = document.getElementById(id).style;
	a.display="block";
}

function close_layer(id){
	a = document.getElementById(id).style;
	a.display = "none";
}

function isNumber(elem) {
	var str = elem;
    var re = /^[0-9]+$/;
    if (!str.match(re)) {
        return false;
    } else {
        return true;
    }
}


function isUserName(str) {
    var re = /^[a-zA-Z0-9\-\.\_]+$/;
    if (!str.match(re)) {
        return false;
    } else {
       return true;
    }
}

function changeLocation(loc){
	document.location=loc;
	}


function changeLocationWithConfirm(loc, message) {
	if(Trim(message) != "")
	{
		if(confirm(message)) {
			changeLocation(loc);
		} else {
			return false;
		}
	}
	changeLocation(loc);
}


function set_readonly(texarea_id){
	document.forms[0].myTextArea.readOnly = "true";
	}
	
function alert_focus(message, id){
	if(Trim(message) != "") alert(message);
	document.getElementById(id).focus();
	return false;
	}
	
	
function form_submit(formId, message){
	if(Trim(message) != "") {
		if(confirm(message))
				document.getElementById(formId).submit();
		else 
			return false;
	}
		document.getElementById(formId).submit();
	}

function goBack(){
	window.history.back();
	}
	
function al(pageURL, tm){
	setTimeout("document.location='"+pageURL+"'", tm);
}

var old_border = 0;
var old_bg = 0;

function changeDivStyle(obj, file){
	old_border = obj.style.border;
	old_bg = obj.style.backgroundImage;
	
	obj.style.border = "1px solid aaaaaa";
	obj.style.backgroundImage = "url("+file+")";
}
	
function restoreDivStyle(obj){
	obj.style.border = old_border;
	obj.style.backgroundImage = old_bg;
}

oldBg="";
function changeBgColor(obj, color){
	if(color == null) color = "#f6f6f6";
	curBg=obj.style.backgroundColor;
	if(curBg == oldBg)
		obj.style.backgroundColor=color;
	else
		obj.style.backgroundColor=oldBg;
	oldBg = curBg;
}

function setMusicStatus(mStat){
    var postData = 'musicStat='+mStat;
    sendAsyncRequest("changeMusicStat.php", 'POST', postData, soundResponse, soundError, null);	
}

function soundResponse(responseText, responseXML, callbackParams) {
  if (responseText != 'true') {
    alert(responseText);
  }
}

function soundError(status, statusText, callbackParams) {
  alert(statusText);
}





function getFlashMovieObject(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 SendDataToFlashMovie(movieName, movieVar, dt)
{
     var flashMovie = getFlashMovieObject(movieName);
	if(flashMovie != null) {
     	flashMovie.SetVariable(movieVar, dt);
	} else {
		alert("invalid flash movie");
	}
}

function getDataFromFlashMovie(movieName, movieVar){
	var flashMovie = getFlashMovieObject(movieName);
	if(flashMovie != null) {
		return flashMovie.GetVariable(movieVar);
	}
	return null;
}