var g_dest_thread = new Array();
var g_dest_timeout = 1200;
var g_dest_timer = 40;
var g_dest_search = false;
var g_menu_width = 220;
var g_related_width = 380;

function setEffectOpacity(elementToChange,newval) {
	if(!newval)
		var newval = 65;
 	elementToChange.style.MozOpacity = '0.'+newval;
 	elementToChange.style.opacity = '0.'+newval;
 	elementToChange.style.KhtmlOpacity = '0.'+newval;
	elementToChange.style.filter = "alpha(opacity='"+newval+"');";
}

function removeEffectOpacity(elementToChange) {
 	elementToChange.style.MozOpacity = 1;
 	elementToChange.style.opacity = 1;
 	elementToChange.style.KhtmlOpacity = 1;
	elementToChange.style.filter = "alpha(opacity='100');";
}

function effIMG(eleidIMG,opac){
	if(isString(eleidIMG)) var ele = document.getElementById(eleidIMG);
 	else var ele = eleidIMG;
 	ele.style.MozOpacity = opac;
 	ele.style.opacity = opac;
 	ele.style.KhtmlOpacity = opac;	
 	ele.style.filter = "alpha(opacity='"+parseInt(opac*100)+"');";
}

function isString(a) {
    return typeof a == 'string';
}

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
 } 
 
 function doSearch() {
  var search = document.getElementById("inputSearch");
  if(search.value!='')
    searchRedirector(search.value);
  else
  	return false;
}

function dosearchwithkeyboard(e) { 
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	if(keycode==13)
		  dosearch();
	return;
}

function searchRedirector(stringDatas) {
	window.location.replace("/search/index.lbl?search="+encodeURIComponent(stringDatas));
}

function toggleSearchOut(domEle){
	if(g_dest_search==true) return;
	if(domEle.getAttribute('class')=='tdtopmenSearchOut') return;
	if(domEle.getAttribute('className')=='tdtopmenSearchOut') return;	
	domEle.setAttribute('class','tdtopmenSearchOut');
	domEle.setAttribute('className','tdtopmenSearchOut');	
	document.getElementById('searchText').style.color='#000000';		
}

function toggleSearchOver(domEle){
	if(domEle.getAttribute('class')=='tdtopmenSearch') return;
	if(domEle.getAttribute('className')=='tdtopmenSearch') return;		
	domEle.setAttribute('class','tdtopmenSearch');
	domEle.setAttribute('className','tdtopmenSearch');			
	document.getElementById('searchText').style.color='#ffffff';		
}

function doClickSearch(){
	g_dest_search = true;
}

function doBlurSearch(){
	if(document.getElementById('inputSearch').value=='') g_dest_search = false;
	toggleSearchOut(document.getElementById('searchContainer'));
}

function changePreview(change,totalInput){
	var tabDisplay = new Array();
	var indexTab = 0;
	for(i=0;i<totalInput;i++){
		if(document.getElementById("video"+i).style.display == "block"){
			tabDisplay[indexTab] = i;
			indexTab++;}}
	if(change == '+' && document.getElementById("video"+(tabDisplay[tabDisplay.length-1]+1)) != undefined){
		document.getElementById("leftArrow").style.visibility = "visible";
		if(document.getElementById("video"+(tabDisplay[tabDisplay.length-1]+2)) == undefined)
			document.getElementById("rightArrow").style.visibility = "hidden";
		document.getElementById("video"+tabDisplay[0]).style.display = "none";
		document.getElementById("video"+(tabDisplay[tabDisplay.length-1]+1)).style.display = "block";}
	if(change == '-'  && document.getElementById("video"+(tabDisplay[0]-1)) != undefined){
		document.getElementById("rightArrow").style.visibility = "visible";
		if(document.getElementById("video"+(tabDisplay[0]-2)) == undefined)
			document.getElementById("leftArrow").style.visibility = "hidden";
		document.getElementById("video"+(tabDisplay[0]-1)).style.display = "block";
		document.getElementById("video"+tabDisplay[tabDisplay.length-1]).style.display = "none";}
}

function sendToAFriend(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}

function MM_findObj(n, d) {
  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_validateForm() {
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function clearform(){
	document.getElementById('firstname').value="";
	document.getElementById('lastname').value="";
	document.getElementById('email2').value="";
	document.getElementById('comments').value="";
	document.getElementById('firstname').style.backgroundColor="#FFFFFF";
	document.getElementById('lastname').style.backgroundColor="#FFFFFF";
	document.getElementById('email2').style.backgroundColor="#FFFFFF";
	document.getElementById('comments').style.backgroundColor="#FFFFFF";
}

function submitform(){
	var sendmail = true;
	if(document.getElementById('firstname').value==''){
		sendmail = false;
		document.getElementById('firstname').style.backgroundColor="#aa014c";}
	if(document.getElementById('lastname').value==''){
		sendmail = false;
		document.getElementById('lastname').style.backgroundColor="#aa014c";}	
	if(document.getElementById('email2').value==''){
		sendmail = false;
		document.getElementById('email2').style.backgroundColor="#aa014c";}
	if(document.getElementById('comments').value==''){
		sendmail = false;
		document.getElementById('comments').style.backgroundColor="#aa014c";}
	if(sendmail)
		document.etform.submit();
}

function resizeMe(){
	var mainContent = document.getElementById('mainContent');
		var maxWidth = parseInt(document.documentElement.clientWidth);
		if(maxWidth > 1280) mainContent.style.width = 1210+'px';
		else if(maxWidth<1050) mainContent.style.width = 980+'px';
		else mainContent.style.width = (maxWidth-70)+'px';
	if(g_flash_id){
		var domEle = document.getElementById(g_flash_id);
		var relatedBlock = document.getElementById('relatedBlock');
		var offW;
		if(relatedBlock) offW = parseInt(parseInt(mainContent.style.width)-g_related_width-g_menu_width);
		else offW = parseInt(parseInt(mainContent.style.width)-g_menu_width);
		domEle.style.width = offW + 'px';}
}

function homeON(domEle){
	domEle.setAttribute('class','homeOver');
	domEle.setAttribute('className','homeOver');
	var homeSpan = document.getElementById('homeSpan');
	homeSpan.style.color = '#ffffff';
}

function homeOUT(domEle){
	domEle.setAttribute('class','homeOff');
	domEle.setAttribute('className','homeOff');
	var homeSpan = document.getElementById('homeSpan');
	homeSpan.style.color = '#343434';
}
