function StringUtil()
{
}
StringUtil.format = function( text )
{
    //check if there are two arguments in the arguments list
    if ( arguments.length <= 1 )
    {
        //if there are not 2 or more arguments there¡¦s nothing to replace
        //just return the original text
        return text;
    }
    //decrement to move to the second argument in the array
    var tokenCount = arguments.length - 2;
    for( var token = 0; token <= tokenCount; token++ )
    {
        //iterate through the tokens and replace their placeholders from the original text in order
        text = text.replace( new RegExp( "\\{" + token + "\\}", "gi"), arguments[ token + 1 ] );
    }
    return text;
};


// Onload Manager
function OnLoadMgr()
{
	this.events = new Array();
	this.RegisterOnLoadScript = function (name)
	{
		if (typeof name == 'function')
		{
			this.events.push(name);
		}
	}
	this.RunOnLoadScripts = function ()
	{
		for (var i = 0; i < this.events.length; i++)
		{
			if (this.events[i] != null && typeof this.events[i] == 'function')
			{
				this.events[i]();
			}
		}
	}
}

// Onload Event
var WinOnload = window.onload;
var	onLoadMgr = new OnLoadMgr();

var Window_OnLoad = null;
var siteMapMgr = null;
var langMgr = null;

window.onload = WinOnloadWrapper;
function WinOnloadWrapper() {
	if (WinOnload) {
		WinOnload();
	}
	// Create Manager Objects
	langMgr = new LangMgr();
	siteMapMgr = new SiteMapMgr(langMgr);
	siteMapMgr.init(_tb_sitemap);
	
	
	// Run onload events
	onLoadMgr.RunOnLoadScripts();
	if (Window_OnLoad != null && typeof Window_OnLoad == 'function') {
		Window_OnLoad();
	}

}

// Image preload / swap
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Change page language
function js_changeLang(curLang, targetLang)
{
	var href = new String(window.location);
	var key = "/"+curLang+"/";
	var start = href.indexOf(key);
	if (start >= 0)
	{
		var head = href.substring(0, start);
		var tail = href.substring(start+key.length);
		var newLocation = head + "/" + targetLang + "/" + tail;
		window.location = newLocation;
	}
}

function imgOver(){  
	$(this).attr("src", getContolImg($(this), "overImg"))
}

function getContolImg(controlObj, attrs)
{
	var src = controlObj.attr("src");
	var img = src.split("/");
	var overImg = controlObj.parent().attr(attrs);
	var currentPath = src.split(img[img.length-1]);
	return currentPath[0]+overImg;
}

function imgOut(){
	
	if($(this).attr("on") == "false")
	{
	$(this).attr("src", getContolImg($(this), "orgImg"))
	}
}

function contentSwap()
{
	$('#control_celebrity img').attr("on", "false");
	$(this).attr("on", "true");
	$('#control_celebrity img').attr("src", imgOut);
	$(this).attr("src", getContolImg($(this), "overImg")) 
	var index = $('#control_celebrity img').index(this);
	$('#content_celebrity div').hide(); 
	$('#content_celebrity div:eq('+index+')').show(); 
}

function expertInit(Name)
{
	var controlIndex = 0;

	var controlImg = $("#control_celebrity img:eq(0)");
	if(Name!= "null" && Name!="")
	{
	control = $("#control_celebrity a[cname='"+Name+"']");
	controlIndex = $("#control_celebrity a").index(control);
	controlImg = $("#control_celebrity a[cname='"+Name+"'] img");
	
	if(controlIndex==-1){
		controlIndex =0;
		controlImg = $("#control_celebrity img:eq(0)");;
		}
	}
	controlImg.attr("on","true");
	controlImg.attr("src", imgOver);
	$('#content_celebrity div:eq('+controlIndex+')').show();
}


function checkAll(o) {
changeCheckBoxStatus(o, true)
}

function changeCheckBoxStatus(obj, status)
{
	if(obj.length>1)
   {
	for (i = 0; i< obj.length; i++) {
		obj[i].checked = status;
		}
	}else if(obj.length==1){
	   obj[0].checked = status;
	}
}

function  unCheckAll(o)
{
changeCheckBoxStatus(o, false)
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function setCookie(c_name,value,path,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value) + ((path==null) ? "" : ";path="+path) + 
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}