/*Javascript to control the influx of charicters put in by users.*/

/*
* textCounter: text count down function
* Parameters:
*		fieldName - xhtml field name this is on,
*		maxLength - max number of characters allowed in this function,
*		spanName - span tag to control colur and update text as it counts down.
* Returns:
*		remaining characters to input on keyup
* Example:
*	<span style="color:red;" id="count_Joke">255</span>
*	<span style="color:blue;" id=""> remaining characters </span>
*	... textArea, input, etc... name="" id="" onKeyUp="textCounter(0,255,'count_Joke');">
*
*/
function textCounter(fieldName,maxLength,spanName) {
	var textArea = document.getElementById(fieldName);
   	var tempString = "";
	
    if (textArea.value.length > maxLength) {
		alert("Sorry this field can only hold " + maxLength + " characters.");
		tempString = textArea.value.substring(0, maxLength);
		textArea.value = tempString; }
   	document.getElementById(spanName).innerHTML = maxLength - textArea.value.length;
	document.getElementById(spanName).style.color = colorFade(0,0,0,255,0,0,255,0,maxLength-textArea.value.length);
	

	//var countColor = black;
	
   	//if () {
	//	document.getElementById(spanName).style.color = orange;
}
  
function colorFade(start_r,start_g,start_b,end_r,end_g,end_b,start_val,end_val,current_val)
{
r_diff = start_r-end_r;
g_diff = start_g-end_g;
b_diff = start_b-end_g;
if (start_val-current_val != 0)
	{
	scale = (start_val-current_val)/(start_val-end_val);
	r_diff*=scale;
	g_diff*=scale;
	b_diff*=scale;
	start_r-=r_diff;
	start_g-=g_diff;
	start_b-=b_diff;	
	}
return "rgb("+Math.floor(start_r)+","+Math.floor(start_g)+","+Math.floor(start_b)+")";
}
   
/*
* toggleTag: dynamic table drop down function 
* Parameters:
*		id - id of element to hide & seek
* Returns:
*
* Example:
*
*/
function toggle_tag (id) {
  	div = document.getElementById("tag_" + id);
  	if (div.style.display == "none") {
    	document.getElementById("tag_" + id).style.display = ""; }
	else {
    	document.getElementById("tag_" + id).style.display = "none"; }
}

/*
* next function commetns
* 
* 
*	
*		
*/

/*
* next function
*
*
*
*
*/

/*
* next function
*
*
*
*
*/
/*
* next function
*
*
*
*
*/

/*
* A DW function for roll over 1 of 4:
*
*
*
*
*/
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/*
* A DW function for roll over 2 of 4:
*
*
*
*
*/
function MM_preloadImages() {
  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];}}
}

/*
* A DW function for roll over 3 of 4:
*
*
*
*
*/
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;
}

/*
* A DW function for roll over 4 of 4:
*
*
*
*
*/
function MM_swapImage() {
  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];}
}

//loading pix div transparentcy...
//variables for window size
var winwidth, winheight;

//get screen size
function alertSize() {
  var winW = 630, winH = 460;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth - 21;
  winH = document.body.offsetHeight -25;
 }
}

winwidth = winW;
winheight = winH;
}

//set div sizes
function screensize()
{
var screenW = 640, screenH = 480;

alertSize();
//alert(winwidth);
//screenW = winwidth;
screenH = winheight/3;
txtheight = screenH/3;
document.getElementById("currentmessage").style.top = '0px';
document.getElementById("currentmessage").style.left = '0px';
document.getElementById("currentmessage").style.width = winwidth + 'px';
document.getElementById("currentmessage").style.height = winheight + 'px';

document.getElementById("msgbg").style.top = '0px';
document.getElementById("msgbg").style.left = '0px';
document.getElementById("msgbg").style.width = winwidth + 'px';
document.getElementById("msgbg").style.height = winheight + 'px';

document.getElementById("msgtxtbg").style.left = '0px';
document.getElementById("msgtxtbg").style.top = screenH + 'px';
document.getElementById("msgtxtbg").style.width = winwidth + 'px';
//document.getElementById("msgtxtbg").style.height = winheight + 'px';

document.getElementById("chsmsgimg").style.top = screenH/2 + 'px';

//document.getElementById("msgtxt").style.top = screenH + (screenH/6) + 'px';
document.getElementById("msgtxt").style.width = winwidth-6 + 'px';
document.getElementById("msgtxt").style.left = 1 + 'px';
}

//show message popup
function seemessage()
{
//alert("hi");
screensize();
document.getElementById("currentmessage").style.visibility = 'visible';
//setTimeout("hide();",5000);
}


//hide message popup
function hide()
{
	document.getElementById("currentmessage").style.visibility = 'hidden';
}

function writediv()
{
	var output;
	document.getElementById("msgbox").innerHTML = '<div id="currentmessage" onMouseUp="hide();" style="width:';
	document.getElementById("msgbox").innerHTML += '100';
	document.getElementById("msgbox").innerHTML += 'px; height:';
	document.getElementById("msgbox").innerHTML += '100';
	document.getElementById("msgbox").innerHTML += 'px; visibility:hidden; position:absolute; left:0px; top:0px;">';
	document.getElementById("msgbox").innerHTML += 'visibility:inherit; height:100%; width:100%; background-color:#9BADC8;';
	document.getElementById("msgbox").innerHTML += 'filter:-moz-opacity:.50;" id="msgbg">something</div>';
	output = '<div style=\"background-color:#9BADC8;\">here</div>';
	//document.getElementById("msgbox").innerHTML = output;	
}
//end loading pix div transparency
