
/*
	Common Javascript function used in the system
*/
function createXMLHttpRequest(){
    var reqObj;
    if(window.XMLHttpRequest){
        try{
            reqObj = new XMLHttpRequest();
        }catch(e){
            reqObj = false;
        }
    }else if(window.ActiveXObject){
        try{
            reqObj = new ActiveXObject("Microsoft.XMLHTTP ");
        }catch(e){
            reqObj = false;
        }
    }
    return reqObj;
}

function getObjByID(layerID) {
  if (document.getElementById){
      // this is the way the standards work
      return document.getElementById(layerID);
  }else if (document.all){
      // this is the way old msie versions work
      return document.all[layerID];
  }else if (document.layers){
      // this is the way nn4 works
      return document.layers[layerID];
  }

  return null;
}

function trim(str) {
    return str.replace(/^\s*|\s*$|\n|\r/g,"");
}

function buildQueryString(params) {
    var query = "";
    for (var i = 0; i < params.length; i++) {
        query += (i > 0 ? "&" : "")
            + escape(params[i].name) + "="
            + escape(params[i].value);
    }
    return query;
}

function toggleDiv(layerID) {
	var layer = getObjByID(layerID);
	if (layer.style.display == 'none')
		layer.style.display = "block";
	else
		layer.style.display = "none";
}

function handleHide(layerID) {
	var mainStyle = getStyleForDiv(layerID);
	mainStyle.display = "none";
}

function handleShow(layerID) {
	var mainStyle = getStyleForDiv(layerID);
	mainStyle.display = "block";
}

function getStyleForDiv(layerID) {
	var mainStyle;

	if (document.getElementById){
	  // this is the way the standards work
	  mainStyle = document.getElementById(layerID).style;
	}else if (document.all){
	  // this is the way old msie versions work
	  mainStyle = document.all[layerID].style;
	}else if (document.layers){
	  // this is the way nn4 works
	  mainStyle = document.layers[layerID].style;
	}

	return mainStyle;
}

function echeck(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
	 }

	 return true					
}


