//Get mouse coordinates
var isIE = document.all?true:false;
var isIE = document.all?true:false;
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(e) {
	if (!isIE) {
		_x = e.pageX;
		_y = e.pageY;
	}
	if (isIE) {
		_x = event.clientX + document.body.scrollLeft;
		_y = event.clientY + document.body.scrollTop;
	}
	
	return true;
}

function _hide(obj_id) {
	if(id_element_visible) {
		document.getElementById(obj_id).style.display = 'none';
		id_element_visible = false;
	}
	id_element_visible = true;
}

function _hide2(obj_id) {
	id_element_visible = true;
	_hide(obj_id);
}

function _show(obj_id) {
	document.getElementById(obj_id).style.display = '';
	id_element_visible = false;
}

var id_element_visible = false;


//------------------------------------------------------------------------------
function counter(text_field, limit, counter_id) {
	var ramas = limit - text_field.value.length;
	if (ramas < 0) {
		text_field.value = text_field.value.substring(0, limit);
		ramas = 0;
	}
	if(ramas == 0) {
		ramas = '<font color="red">[' + ramas + ']</font>';
	}
	else {
		ramas = '[' + ramas + ']';
	}
	document.getElementById(counter_id).innerHTML = ramas;
	
	/*if(text_field.value.length >= limit) {
		document.getElementById(counter_id).innerHTML = '<font color="red">[' + limit + ']</font>';
		//text_field.maxlength = limit;
		text_field.value = text_field.value.substring(0, limit);
	}*/
}

//------------------------------------------------------------------------------
function over2(obj) {
	obj.className = "bg14";
}

//------------------------------------------------------------------------------
function out2(obj) {
	obj.className = "bg13";
}

//------------------------------------------------------------------------------
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

//------------------------------------------------------------------------------
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

//------------------------------------------------------------------------------
function checkCookie(c_name)
{
	username=getCookie(c_name);
	if (username!=null && username!="")
	{
		return true;
	}
	else 
	{
		return false;
	}
}

//------------------------------------------------------------------------------
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

//------------------------------------------------------------------------------
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 "";
}


// Image Check Box (15-11-2005)
// by Vic Phillips http://vicsjavascripts.org.uk

// The Script converts an existing Check Box to an Image Check Box
// using function icbCBoxtoImgCB(.......

// The image check box has images for the true and false conditions
// The true or false conditions are reflected in a 'real' check box.
// This allows standard techniques to be employed when submitting the form.
// Verify the state against the same id/name
// as the id of the original image/checkbox.
// There may be a many image check boxes on a page as required.

// Initialise the check boxes 'onload' of the page.
// ie
// <body onload="icbCBoxtoImgCB(*id*,*state*,'*ImageTrue*','*ImageFalse*','*width*,*height*);" >
// where
// *id*         = id of the image checkbox (string)
// *state*      = the initial condition (true or false )
// *ImageTrue*  = the image to be displayed for the 'true' condition (string)
// *ImageFalse* = the image to be displayed for the 'false' condition (string)
// *width*      = the width of the image (optional)(digits)
// *height*     = the height of the image (optional)(digits)

// The function icbCheckBoxMoniter(icb) may be used to action external functions
// the function is passed with the checkbox object when the checkbox checked state changes

// All variables name ect are prefixed with 'icb'
// to minimise conflicts with other javascripts.
// Tested with IE6, NS7, MozillaFF and Opera7


function icbCheckBoxMoniter(icb){
 //alert('CheckBox '+icb.id+' is '+icb.checked);
}

// No Need to Change
var icbCursor='pointer';
if (document.all){ icbCursor='hand'; }


function icbCBoxtoImgCB(icb,icbs,icbT,icbF,icbw,icbh){
  // Create Image Element, Append Before the Check Box, Add OnClick Event & Load Correct Image
 icbNewImg=document.createElement('img');
 icbNewImg.id='icb'+icb;
 icbcb=document.getElementById(icb);
 icbcb.parentNode.insertBefore(icbNewImg,icbcb);
 icbNewImg.style.cursor=icbCursor;
 if (icbw!=null&&icbh!=null){ icbNewImg.width=icbw; icbNewImg.height=icbh; }
 icbNewImg.cb=icbcb;
 icbNewImg.icbT=icbT;
 icbNewImg.icbF=icbF;
 icbNewImg.onclick=function(){ icbImgCBox(this); };
 if (icbs){ icbNewImg.src=icbT; } else { icbNewImg.src=icbF; }
 // Hide the real Check Box
 icbcb.checked=icbs;
 icbcb.style.position='absolute';
 icbcb.style.visibility='hidden';
}

function icbImgCBox(icb){
 if (icb.cb.checked){
  icb.src=icb.icbF;
  icb.cb.checked=false;
 }
 else {
  icb.src=icb.icbT;
  icb.cb.checked=true;
 }
 icbCheckBoxMoniter(icb.cb);
}


