/* $Header: /usr/local/cvsroot/scottmadden.com/elements/scripts/script.js,v 1.6 2010/03/02 20:47:50 tngsandiego Exp $ */
function display(element) {
	var but = document.getElementById(element);
	but.style.display = 'block';
}
function hide(element) {
	var but = document.getElementById(element);
	but.style.display = 'none';
}
function removeOpt(element){
	var tdel = document.getElementById(element);
	tdel.parentNode.removeChild(tdel);
}
function disablEnable(element){
	var obj = document.getElementById(element);
	if(obj.disabled==true){
		obj.disabled=false;
	}else{
	        obj.disabled=true
	}
	return true;
}
function hidedisplay(element){
	var but = document.getElementById(element);
	if(but.style.display == 'block'){
		but.style.display = 'none';
	}else{
		but.style.display = 'block';
	}
}
function checkuncheck(id){
	var idLab = document.getElementById(id);
	if(idLab.checked){
		idLab.checked = false;
	}else{
	        idLab.checked = true;
	}
return true;
}
function visibleFlash(){
	var obj = top.document.getElementsByTagName("object");
	var emb = top.document.getElementsByTagName("embed");
	obj.style.visibility = 'visible';
	emb.style.visibility = 'visible';
}
function getHeight(id){
	var thisOne = document.getElementById(id);
	return thisOne.style.height
}
function resizeHeight(altezza,id){
	var TotAltezza = altezza;
	var thisOne = document.getElementById(id);
	thisOne.style.height = TotAltezza + "px";
}
function resizeWidth(larghezza,id){
	var TotLarghezza = larghezza;
	var thisOne = document.getElementById(id);
	thisOne.style.width = TotLarghezza + "px";
}
function setMarginLeft(margin,id){
	var margine = margin;
	var thisOne = document.getElementById(id);
	thisOne.style.marginLeft = margine + "px";
}
function setTop(altezza,id){
	var TotAltezza = altezza;
	document.getElementById(id).style.top = TotAltezza + "px";
}
function linkInTopFrame(link,frame){
        top.frames[frame].location.href = link;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function changeLabel(id,newLabel){
	var idLab = document.getElementById(id);
	idLab.innerHTML = newLabel;
}
function checkit(id){
	var idLab = document.getElementById(id);
	idLab.checked = true;
}
/* Numbers */
function numToDB(number){
	return number.replace(",","");
}
function number_format (number, decimals, dec_point, thousands_sep){
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1){
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }

  if (decimals != null){
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ?
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0){
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }

  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != ""){
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }

  return sign + integer + fractional + exponent;
}

function spitFlash(filename,width,height){
	if(!width) var width='100%';
	if(!height) var height='100%';
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" name="artist" id="artist" align="middle">');
		document.write('<param name="loop" value="false">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + filename + '" />');
		document.write('<param name="wmode" value="transparent">');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#FFFFFF" />');
		document.write('<embed src="' + filename + '" loop="false" quality="high" width="'+width+'" height="'+height+'" name="artist" wmode="transparent" bgcolor="#FFFFFF" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
function spitVarFlash(filename,data,width,height){
	if(!width) var width='100%';
	if(!height) var height='100%';
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" name="artist" id="artist" align="middle">');
		document.write('<param name="loop" value="false">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + filename + '" />');
		document.write('<param name="wmode" value="transparent">');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#FFFFFF" />');
		document.write('<param name="FlashVars" value="xml=' + escape(data) + '">');
		document.write('<embed src="' + filename + '" loop="false" FlashVars="xml=' + escape(data) + '" quality="high" width="'+width+'" height="'+height+'" name="artist" wmode="transparent" bgcolor="#FFFFFF" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/* TRIGGERS */
var timerId;
var timerId2;
var lopen='';
var idGetBig;
var actSize=10;
// 1 - dropdown
function startTrigger(n,who){
	if(!n){
		n = 10000;
	}
	if(!timerId){
        	timerId = setTimeout('resizeHeight(1,"cover_'+who+'");hide("cover_'+who+'");stopTrigger();', n);
	}
}
function stopTrigger(){
	clearTimeout(timerId);
	timerId = false;
}
// display
function displayMenu(obj,element) {
	lopen = element;
	var but = document.getElementById("cover_"+element);
	var leftIn=findPosX(obj);
	if(leftIn > 780) leftIn=790;
	but.style.left = leftIn +'px';
	but.style.display = 'block';
	var actMaxHeight=document.getElementById("flier_"+element).offsetHeight+10;
	var part=parseFloat(actMaxHeight/100);
	actsize=10;
        idGetBig = setInterval(function(){
                //alert(actMaxHeight);
        	actSize = parseInt(actSize * 2);
                but.style.height = actSize+'px';
                var perc=parseFloat(actSize/part);
                but.style.opacity = number_format(parseFloat(perc/100), 1, ".", ",");
                but.style.filter = 'alpha(opacity=' + parseInt(perc) + ')';
                if(actSize >= actMaxHeight){
	                but.style.opacity = 100;
	                but.style.filter = 'alpha(opacity=100)';
                        but.style.height = actMaxHeight+'px';
                        actSize=actMaxHeight;
			clearInterval(idGetBig);
		}
        },33);
}
function hideLastMenu(){
        if(lopen.length > 0){
        	//alert(lopen);
		hide("cover_"+lopen);
		resizeHeight(10,"cover_"+lopen);
		actSize=10;
		stopTrigger();
		clearInterval(idGetBig);
	}
}
// 2 - livesearch
function startTrigger2(n,who){
	if(!n){
		n = 10000;
	}
	if(!timerId){
        	timerId2 = setTimeout('hide("'+who+'");stopTrigger2();', n);
	}
}
function stopTrigger2(){
	clearTimeout(timerId2);
	timerId2 = false;
}
function findPosX(obj){
	if(eval(document.getElementById("pageContainer"))){
		var mainDad=document.getElementById("pageContainer");
	}else{
		var mainDad=document.getElementById("bigContainer");
	}
	var difference = mainDad.offsetLeft;
	var curleft = 0;
	if(obj.offsetParent){
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent) break;
			obj = obj.offsetParent;
		}
	}else if(obj.x){
		curleft += obj.x;
	}
	curleft -= difference + 7;
	return curleft;
}
/* Thingy */
function lastThingy(id){
	document.getElementById(id).className='bottomFlier_over';
}
function lastThingyOff(id){
	document.getElementById(id).className='bottomFlier';
}
var idHide,idShow;
function hideslow(id){
var obj = document.getElementById(id);
var actOpac=100;
        idHide = setInterval(function(){
        	actOpac = parseInt(actOpac * 0.8);
        	alert('Halpha(opacity=' + actOpac + ')');
                obj.style.opacity = number_format(parseFloat(actOpac/100), 1, ".", ",");
                obj.style.filter = 'alpha(opacity=' + actOpac + ')';
                if(actOpac < 1){
                        obj.style.opacity=0;
                        obj.style.filter = 'alpha(opacity=0)';
			clearInterval(idHide);
		}
        },33);
}
function displayslow(id){
var obj = document.getElementById(id);
var actOpac=1;
//alert(actOpac+ " ; " + id + " :: " + obj);
        idShow = setInterval(function(){
        	actOpac = parseInt(actOpac * 1.2);
        	alert('Salpha(opacity=' + actOpac + ')');
                obj.style.opacity = number_format(parseFloat(actOpac/100), 1, ".", ",");
                obj.style.filter = 'alpha(opacity=' + actOpac + ')';
                if(actOpac > 99){
                        obj.style.opacity=100;
                        obj.style.filter = 'alpha(opacity=100)';
			clearInterval(idShow);
		}
        },33);
}

/* Grading */
function gradeTo(id,title){
	var actual=document.forms['glb'].elements['actual'].value;
	document.forms['glb'].elements['actual'].value=id;
	
	hide('bigHead_'+actual);
	display('bigHead_'+id);
	hide('greyBall_'+actual);
	display('greyBall_'+id);
	
	var newTitle = document.getElementById('title');
	newTitle.innerHTML = title;
}
/* Bios */
function showBios(id){
	clearInterval(idShow);
	if(eval(document.getElementById("biosHead_1")))document.getElementById("biosHead_1").className="floatLeft pointer unactive relative mr2";
	if(eval(document.getElementById("biosHead_2")))document.getElementById("biosHead_2").className="floatLeft pointer unactive relative mr2";
	if(eval(document.getElementById("biosHead_3")))document.getElementById("biosHead_3").className="floatLeft pointer unactive relative mr2";
	if(eval(document.getElementById("biosHead_4")))document.getElementById("biosHead_4").className="floatLeft pointer unactive relative mr2";
	if(eval(document.getElementById("biosHead_5")))document.getElementById("biosHead_5").className="floatLeft pointer unactive relative mr2";

	document.getElementById("biosHead_"+id).className="floatLeft pointer active relative mr2";
	
	var obj = document.getElementById('biosCover');
	var actOpac=1;
	var up=true;
	display('biosCover');
        idShow = setInterval(function(){
                if(up){
	        	actOpac = actOpac * 1.6;
	                obj.style.opacity = number_format(parseFloat(actOpac/100), 1, ".", ",");
	                obj.style.filter = 'alpha(opacity=' + number_format(actOpac, 0, ".", ",") + ')';
                }else{
			actOpac = actOpac * 0.6;
		        obj.style.opacity = number_format(parseFloat(actOpac/100), 1, ".", ",");
		        obj.style.filter = 'alpha(opacity=' + number_format(actOpac, 0, ".", ",") + ')';
	        }
                if(actOpac > 99 && up){
                        obj.style.opacity=100;
                        obj.style.filter = 'alpha(opacity=100)';
			
			if(eval(document.getElementById("bios_1")))hide("bios_1");
			if(eval(document.getElementById("bios_2")))hide("bios_2");
			if(eval(document.getElementById("bios_3")))hide("bios_3");
			if(eval(document.getElementById("bios_4")))hide("bios_4");
			if(eval(document.getElementById("bios_5")))hide("bios_5");

			display("bios_"+id);
			actOpac=100;
			
			up=false;
		}else if(actOpac < 1){
			obj.style.opacity=0;
			obj.style.filter = 'alpha(opacity=0)';
			hide('biosCover');
			clearInterval(idShow);
		}
        },33);
}
/* doChanges */
function doChanges(){
	var bodyHeight = document.getElementById('bodyPage').offsetHeight;
	top.resizeHeight(bodyHeight, 'colmn1');
	top.resizeHeight(bodyHeight, 'colmn2');
}
/* doChangesAlternative */
function doChangesAlt(){
	var bodyHeight = document.getElementById('bodyPage').offsetHeight;
	top.resizeHeight(bodyHeight, 'colmn1');
	top.resizeHeight(parseInt(bodyHeight - 280), 'colmn2');
}
/* Search */
function createMenus(list){
var listArr = Array();
	var mainDiv = document.getElementById('tipContainer');
	var sb = document.getElementById('topSearchBox');
	removeOpt('newDiv');

	var newDiv = document.createElement('DIV');
	newDiv.id = 'newDiv';
	mainDiv.appendChild(newDiv);

	listArr = list.split("|");
	if(listArr.length<1 || list.length<=1){
		hide('liveSearch');
		stopTrigger2();
		return false;
	}else{
		display('liveSearch');
		//startTrigger2(5000,'liveSearch');
	}
	for(k=0;k<listArr.length;k++){
		var listDiv = document.createElement('DIV');
		//listDiv.onclick = function(){document.forms['eve_form_topsearch'].elements['form_search_phrase'].value=this.innerText;hide('liveSearch');stopTrigger2();};
		listDiv.onclick = function(){if(this.innerText==undefined || this.innerText.length<=1){var toGo = this.textContent;}else{var toGo = this.innerText;};document.forms['eve_form_topsearch'].elements['form_search_phrase'].value=toGo;hide('liveSearch');stopTrigger2();};
		listDiv.className = 'tipElement';
		listDiv.innerHTML = "<span style='font-weight:bold;font-size:10pt;margin-left:10px;'>"+sb.value+"</span>" + listArr[k].substring(sb.value.length);
		newDiv.appendChild(listDiv);
		
		delete newDiv;
	}
	return true;
}
/* Ajax */
function callApiPOST(url, parameters, what) {
//alert(url+"?"+parameters);
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Internal Server Error');
		return false;
	}
	http_request.onreadystatechange = eval(what);
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
function jj_showResults() {
	if (http_request.readyState < 4){
		// do nothing
	}else if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			createMenus(http_request.responseText);
		} else {
                        //alert("There is a problem with this update! "+ http_request.responseText);
		}
	}
}
/* IE6 HACK */
function mObscure(id){
	document.getElementById(id).style.backgroundColor='#485e71';
}
function mEnlight(id){
	document.getElementById(id).style.backgroundColor='#6E89A1';
}