var xmlHttp;

    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }

// Function for Ajax
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function SelectAllCheckBoxes(frm)
{
  count = frm.elements.length;
    for (i=0; i < count; i++) 
	{
    //if(frm.elements[i].checked == 1)
    //	{frm.elements[i].checked = 0; }
    //else {frm.elements[i].checked = 1;}
    frm.elements[i].checked = frm.elements[0].checked;
	}
}

function checkUncheckAll(theElement) {
  var theForm = theElement.form, z = 0;
  for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
    theForm[z].checked = theElement.checked;
  }
  }
}
function toggle_div(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'block')
      e.style.display = 'none';
   else
      e.style.display = 'block';
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function show_layer(byID){
  var e = document.getElementById(byID);
  e.style.display = "block";
}

function hide_layer(byID){
  var e = document.getElementById(byID);
  e.style.display = "none";
}

function layer_message(byID, mess) {
  var e = document.getElementById(byID);
  e.innerHTML = mess;
}

function is_email(str) {
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1) return false;
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
		if (str.indexOf(at,(lat+1))!=-1) return false;
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
    if (str.indexOf(dot,(lat+2))==-1) return false;
		if (str.indexOf(" ")!=-1) return false;
 		else return true;					
}

function instr(strSearch, charSearchFor)
{
  return strSearch.indexOf(charSearchFor) + 1;
}

function strlen(str) {
  return str.length;
}

function replace(mainString, thisString, newString) {
  return mainString.replace(thisString, newString);
}
function left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function asc(str)
{
  var code = str.charCodeAt(0);
  return code;
}

function strtolower(str) {
  return str.toLowerCase(); 
}

function strtoupper(str) {
  return str.toUpperCase(); 
}

