//==========================================
// Get object by ID
//==========================================
function my_getbyid(id)
{
 	itm = null;

 	if (document.getElementById)
 	{
 		itm = document.getElementById(id);
 	}
 	else if (document.all)
 	{
 		itm = document.all[id];
 	}
 	else if (document.layers)
 	{
 		itm = document.layers[id];
 	}

 	return itm;
}

//==========================================
// Check field lengths
//==========================================
function countChars(formName,id,maxChar)
{
  field = document.forms[formName].elements[id];
  if (field.value.length > maxChar)
  {
    field.value = field.value.substring(0, maxChar);
  }
  else
  {
    my_getbyid(id+'_char').innerHTML = maxChar-field.value.length;
  }
}

//==========================================
// Hide Google Watermark
//==========================================
function changeSearchInput(inputStatus)
{

  if (inputStatus=='show')
  {
    if (my_getbyid('searchTextBox').value == '')
    {
      my_getbyid('searchTextBox').style.backgroundImage = 'url('+base+'style/'+ourStyle+'/images/googleSearch.gif)';
      my_getbyid('searchTextBox').value = '';
    }
  }
  if (inputStatus=='hide')
  {
    my_getbyid('searchTextBox').style.backgroundImage = 'url()';
  }
  return true;

}

//==========================================
// Buttonize Submit Button
//==========================================
function changeSearchSubmit(submitStatus)
{
  if (submitStatus=='clicked')
  {
    my_getbyid('searchSubmit').style.backgroundImage = 'url('+base+'style/'+ourStyle+'/images/searchRightClicked.gif)';
  }
  if (submitStatus=='hover')
  {
    my_getbyid('searchSubmit').style.backgroundImage = 'url('+base+'style/'+ourStyle+'/images/searchRightHover.gif)';
  }
  if (submitStatus=='clear')
  {
    my_getbyid('searchSubmit').style.backgroundImage = 'url('+base+'style/'+ourStyle+'/sss_new/images/searchRight.gif)';
  }
  return true;
}

//==========================================
// Set DIV ID to hide
//==========================================
my_hide_div = function (itm)
{
  if (!itm) return

	 my_getbyid(itm).style.display = "none";

}

//==========================================
// Set DIV ID to show
//==========================================
my_show_div = function (itm)
{
  if (!itm) return

  //my_getbyid('sb-gen').my_getbyid(itm).style.display = "";
	 my_getbyid(itm).style.display = "";

}

//==========================================
// Center Div
//==========================================
function center_div(itm)
{
  if (!itm) return
	 //----------------------------------
	 // Figure width and height
	 //----------------------------------

	 var my_width  = 0;
	 var my_height = 0;
	
	 if ( typeof( window.innerWidth ) == 'number' )
	 {
		  //----------------------------------
		  // Non IE
		  //----------------------------------
		  my_width  = window.innerWidth;
		  my_height = window.innerHeight;
	 }
	 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	 {
		  //----------------------------------
	  	// IE 6+
		  //----------------------------------
	  	my_width  = document.documentElement.clientWidth;
		  my_height = document.documentElement.clientHeight;
	 }
 	else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
 	{
		  //----------------------------------
		  // Old IE
		  //----------------------------------
		  my_width  = document.body.clientWidth;
		  my_height = document.body.clientHeight;
	 };

  setX = my_width/2;
  setY = my_height/2;

	 my_getbyid(itm).style.position = 'absolute';
  my_getbyid(itm).style.zIndex   = 99;
	 my_getbyid(itm).style.left = setX + "px";
	 my_getbyid(itm).style.top  = setY + "px";
}

//==========================================
// SetCookie
//==========================================
function my_setcookie( name, value, sticky, deleteCookie )
{
 	expire = "";

	 if ( sticky )
	 {
	  	expire = " expires=Sat, 1 Jan 2020 00:00:00 GMT;";
	 }
	 if ( deleteCookie==1 )
	 {
	  	expire = " expires=Sat, 1 Jan 1979 00:00:00 GMT;";
	 }

	 document.cookie = "sss_" + name + "=" + value + "; path=/;" + expire;
}

//==========================================
// GetCookie
//==========================================
function my_getcookie( name )
{
	cname = gtw_cookieid + name + '=';
	cpos  = document.cookie.indexOf( cname );
	
	if ( cpos != -1 )
	{
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		
		if (cend == -1)
		{
			cend = document.cookie.length;
		}
		
		return unescape( document.cookie.substring(cstart, cend) );
	}
	
	return null;
}

//==========================================
// Validate Login
//==========================================
function NewAntiSpamCode(url)
{
  spamimg = my_getbyid('antispam');
  refreshImg = my_getbyid('refresh');
  spamimg.innerHTML = "<img src='"+base+"style/"+ourStyle+"/images/ajax-loader.gif' />";
  refreshImg.innerHTML = "<img src='"+base+"style/"+ourStyle+"/images/refresh.gif' width='20' height='20' border='0' alt='Refresh' title='Refresh' />";

  var xmlHttp;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support XMLHttpRequest!");
        return false;
      }
    }
  }

  xmlHttp.onreadystatechange=function()
  {
    if(xmlHttp.readyState==4 && xmlHttp.status==200)
    {
      theimg = "<img src='"+base+"style/"+ourStyle+"/images/refresh.png' width='20' height='20' border='0' alt='Refresh' title='Refresh' />";
      setTimeout("refreshImg.innerHTML = theimg",1000);
      reponse = "<img src='"+ base + url + "/antispam/1/anti_id/" + xmlHttp.responseText + "/' width='180' height='60' alt='Loading Image' />";
      setTimeout("spamimg.innerHTML = reponse",1000);
    }
    else
    {
    }
  }

  //xmlHttp.onreadystatechange();
  xmlHttp.open("GET",base + "frame/captcha_img.php?random=" + Math.random(),true);
  xmlHttp.send(null);

}

//==========================================
// Validate Login
//==========================================
function ValidateLogin()
{

  user = "";
  pass = "";
  msg  = "";
  error = 0;

  if (document.LOGIN.sss_user.value.length < 3 || document.LOGIN.sss_user.value.length > 32)
  {
    user = "You Must Enter a valid Username!\n";
    error = 1;
  }

  if (document.LOGIN.sss_pass.value.length < 3  || document.LOGIN.sss_pass.value.length > 32)
  {
    pass = "You Must Enter a valid Password!\n";
    error = 1;
  }

  if (error == 1)
  {
    msg = user+pass;
    alert(msg);
    return false;
  }

}

//==========================================
// Loading
//==========================================
doDotCount = 3;
function doDots(redo,thecount)
{
  if (my_getbyid('loading'))
  {
    if (redo==1)
    {
      dots = "";
      thecount = 0;
      my_getbyid('loading').innerHTML = dots;
    }
    else if (redo==0)
    {
      if (thecount==0)
      {
        dots = "";
      }
      else if (thecount==1)
      {
        dots = ".";
      }
      else if (thecount==2)
      {
        dots = "..";
      }
      else if (thecount==3)
      {
        dots = "...";
      }

      thecount++;
      my_getbyid('loading').innerHTML = dots;
    }

    if (thecount<=doDotCount)
    {
      setTimeout("doDots(0,"+thecount+")",300);
    }
    else
    {
      setTimeout("doDots(1,0)",200);
    }
  }
}

//==========================================
// Show Loading
//==========================================
function show_loading() {
      my_getbyid('weatherTable').innerHTML = 'Loading';
return;
}

//==========================================
// Hide Loading
//==========================================
function hide_loading() {
      my_getbyid('weatherTable').innerHTML = '';
return;
}

//==========================================
// Alerts Scroller
//==========================================
ticker_width = "500px";
mticker_width = 500;
ticker_height = "14px";
mticker_height = 14;
ticker_speed = 2;
ticker_pause_onhover = 1;

ticker_speed = (document.all) ? ticker_speed : Math.max(1, ticker_speed-1);
var copyspeed = ticker_speed;
var pausespeed = (ticker_pause_onhover == 0) ? copyspeed : 0;
var iedom = document.all || document.getElementById;

var actualwidth='';
var rh_ticker_iedom, rh_ticker_ns;

function startAlert(alertcontent) {

function populate() {
  if (iedom) {
    rh_ticker_iedom = document.getElementById? my_getbyid("ie_rh_ticker") : document.all.ie_rh_ticker;
    rh_ticker_iedom.style.left = parseInt(ticker_width)+8+"px";
    rh_ticker_iedom.innerHTML = alertcontent;
    actualwidth = document.all ? ALERT_OFFSET.offsetWidth : my_getbyid("ALERT_OFFSET").offsetWidth;
  } else if (document.layers) {
    rh_ticker_ns=document.rh_ticker_ns.document.ns_marquee2;
    rh_ticker_ns.left=parseInt(ticker_width)+8;
    rh_ticker_ns.document.write(alert_content);
    rh_ticker_ns.document.close();
    actualwidth=rh_ticker_ns.document.width;
  }
  lefttime = setInterval("rh_ticker_scroll()",20);
}
window.onload=populate;

if (iedom||document.layers) {
  with (document) {
    toshow = '<table border="0" cellspacing="0" cellpadding="0"><tr><td>';
    if (iedom) {
      toshow = toshow + '<div style="position:relative;width:'+ticker_width+';height:'+ticker_height+';overflow:hidden;">';
      toshow = toshow + '<div style="position:absolute;width:'+ticker_width+';height:'+ticker_height+';" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=ticker_speed">';
      toshow = toshow + '<div id="ie_rh_ticker" style="position:absolute;left:0px;top:0px"></div>';
      toshow = toshow + '</div></div>';
    } else if (document.layers) {
      write('<ilayer width='+ticker_width+' height='+ticker_height+' name="rh_ticker_ns" bgColor='+ss_marquee_color_bg+'>')
      write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=ticker_speed"></layer>')
      write('</ilayer>')
    }
    toshow = toshow + '</td></tr></table>';
  }
  my_getbyid('ALERT').innerHTML = toshow;
}

}

function rh_ticker_scroll(){
  if (iedom) {
    if (parseInt(rh_ticker_iedom.style.left) > (actualwidth*(-1)-5)) {
      rh_ticker_iedom.style.left=parseInt(rh_ticker_iedom.style.left)-copyspeed+"px"
      //document.getElementById('reachedEnd').innerHTML = "False";
    } else {
      rh_ticker_iedom.style.left=parseInt(ticker_width)+8+"px"
    }
  } else if(document.layers) {
    if(rh_ticker_ns.left > (actualwidth*(-1)+8)) {
      rh_ticker_ns.left -= copyspeed;
    } else {
      rh_ticker_ns.left=parseInt(ticker_width)+8
    }
  }
  /*document.getElementById('leftScroll').innerHTML = parseInt(rh_ticker_iedom.style.left);
  document.getElementById('actualWidth').innerHTML = actualwidth*(-1)-5;
  document.getElementById('rightScroll').innerHTML = parseInt(rh_ticker_iedom.style.left);
  document.getElementById('strtWidth').innerHTML = actualwidth*(-1)-5 + (mticker_width/2);

  if (parseInt(rh_ticker_iedom.style.left) <= (actualwidth*(-1)-5) + (mticker_width/2))
  {
    document.getElementById('reachedEnd').innerHTML = "Start New Scroll";
  }
  else
  {
    document.getElementById('reachedEnd').innerHTML = "False";
  }*/
}

//==========================================
// Slider
//==========================================
function FoldElement(contentId,cookieName)
{
	//var contentElement = element(contentId);
 var contentElement = my_getbyid(contentId);
	if (contentElement.style.display == 'none')
	{
  if (cookieName)
  {
    my_setcookie( cookieName, 0, 1, 0 );
  }
		TransitionShowNode(contentElement);
	}
	else if (contentElement.style.display == 'block'
		|| !contentElement.style.display)
	{
  if (cookieName)
  {
    my_setcookie( cookieName, 1, 0, 0 );
  }
		TransitionHideNode(contentElement);
	}
}

function TransitionHideNode(contentElement)
{
	SlideElement(contentElement.id, false);
}

function TransitionShowNode(contentElement)
{
	SlideElement(contentElement.id, true);
}

function SlideElement(elementId, show)
{
	var slideSpeed = 10;
	var slideTimer = 1;

	//var content = element(elementId);
 var content = my_getbyid(elementId);
	//var content_inner = element(elementId + "_inner");
 var content_inner = my_getbyid(elementId + "_inner");
	var height = content.clientHeight;
	if (height == 0)
	{
		height = content.offsetHeight;
		content.style.display = 'block';
	}
	height = height + (show ? slideSpeed : -slideSpeed);

	var rerun = true;
	if (height >= content_inner.offsetHeight)
	{
		height = content_inner.offsetHeight;
		rerun = false;
	}
	else if (height <= 1)
	{
		height = 1;
		rerun = false;
	}

	content.style.height = height + 'px';
	var topPos = height - content_inner.offsetHeight;
	if (topPos > 0)
	{
		topPos = 0;
	}
	content_inner.style.top = topPos + 'px';

	if (rerun)
	{
		setTimeout("SlideElement('"
			+ elementId + "', " + show + ");",
			slideTimer);
	}
	else
	{
		if (height <= 1)
		{
			content.style.display = 'none';
		}
	}
}
