var BASE_URL="";

//-------------------------------------------------------------------------------------- common function

function site_url(path){
  return BASE_URL + path;
}

function image_url(path){
  return BASE_URL + "assets/images/" + path;
}

function href(u){
  document.location.href = site_url(u);
}

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


//-------------------------------------------------------------------------------------- PROTOTYPE

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }

//--------------------------------------------------------------------------------------tab
var tab_selection = {};
function tab_sel(id,tab,count,ajax_path){
  for(i=0;i<count;i++){
    try{
      $(id + "-tab-" + i).className = "none";
      $(id + "-div-" + i).style.display = "none";
    }catch(e){}
  }
  try{
    $(id + "-tab-" + tab).className = "selected";
    $(id + "-div-" + tab).style.display = "block";
    if(ajax_path){
			//ajax thing~
			if($(id + "-div-" + tab).innerHTML.trim()==""){
				tab_refresh(id,tab,ajax_path);
			}
		}
		tab_selection[id] = tab;
		popup_action_close();
  }catch(e){}
}

function tab_refresh(id,tab,ajax_path){
	/*new Ajax.Updater(id + "-div-" + tab,BASE_URL + ajax_path + tab,
				{parameters:{AJAX:true},evalScripts:true});
				tab_refresh(id,tab,count,ajax_path);*/
	//new Ajax.Updater(id + "-div-" + tab,BASE_URL + ajax_path + tab,
	//{parameters:{AJAX:true},evalScripts:true});
	act(ajax_path + tab,id + "-div-" + tab);
}
//-------------------------------------------------------------------------------------- initialize
var _init_script="";

function init_script_add(s){
    if (s != null)
        _init_script += s + ";\n";
}

function init(){
  try{
    eval(_init_script);
  }catch(e){
    alert(e + "\n" + _init_script);
  }
}

Event.observe(window, 'load', init, false);
