function setCookie(pName,pValue) {
  var cName = 'document.cookie = '+"'"+pName+'='+pValue+"; path=/'";
  eval(cName);
}

//***********************************************

function readCookie (cCookie) {
  var cTempCookie = document.cookie+";" ;
  var cValue = "" ;
  var label = cCookie+'=' ;
  var labelLen = label.length ;
  var cLen = cTempCookie.length ;
  var i = 0 ;
  while (i < cLen) {
    var j = i + labelLen ;
    if (cTempCookie.substring(i,j) == label) {
      var cEnd = cTempCookie.indexOf(";",j) ;
      if (cEnd ==     -1) {
        cEnd = cTempCookie.length ;
      }
        cValue = unescape(cTempCookie.substring(j,cEnd)) ;
        return cValue ;
      }
    i++
  }
  return cValue ;
}

//***********************************************

function goToURL(form)
  {
    var myindex=form.dropdownmenu.selectedIndex
    if(!myindex=="")
      {
        window.location.href=form.dropdownmenu.options[myindex].value;
      }
}

//***********************************************

function Empty(field,msg){
 
if (field.value == "" || field.length < 1) {
  alert(msg)
  field.focus()
  field.select()
 }
}

//***********************************************

function IsEmpty(field) {
 if (field.value == "" || field.length < 1) {
  return true 
 } else {
  return false
 }
}


//***********************************************

function IsDigit(field,msg) {
 var valid = "0123456789"
 var ok = "yes"
 var temp

 for (var i=0;  i<field.value.length; i++)  {
   temp = "" + field.value.substring(i, i+1)
   if (valid.indexOf(temp) == "-1") 
      ok = "no"
  }

 if (ok == "no") { 
   alert(msg);
   field.focus();
   field.select();
   return false;
 } else {
   return true;
 }
 
}

//***********************************************

function IsDigitComa(field,msg) {
 var valid = "0123456789 ,"
 var ok = "yes"
 var temp

 for (var i=0;  i<field.value.length; i++)  {
   temp = "" + field.value.substring(i, i+1)
   if (valid.indexOf(temp) == "-1") 
      ok = "no"
  }

 if (ok == "no") { 
   alert(msg);
   field.focus();
   field.select();
   return false; 
 }
}

//***********************************************

function IsAlpha(string) {
 var valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 var ok = "yes"

 firstChar = string.substr(0,1)
 firstChar = firstChar.toUpperCase()
 if (valid.indexOf(firstChar) == "-1") {
     ok = "no"
  }

 if (ok == "no") { 
    return false; 
 } else {
 	return true;
 }
}

//***********************************************

function ChangeBox(cbox) {

box = eval(cbox)
box.checked = !box.checked
}

//***********************************************
function noEnter(e) {
	if (e.srcElement.type == 'text' && e.keyCode == 13) {
		return false;
	}
}

//***********************************************
function alltrim(s) {
	if (s.length > 0) {
		while (s.indexOf('  ') > -1) { s = s.replace('  ',' ') }
		if (s.substr(s.length-1,1)==' ') { s = s.substr(0,s.length-1) } // rTrim()
		if (s.substr(0,1)==' ') { s = s.substr(1,s.length-1) }          // lTrim()
	}
	return s
}	

//***********************************************
 function listSearch(cSearchBox,cListName) {
	var whichKey   = window.event.keyCode;
	oSearchBox     = eval("document.getElementById('"+cSearchBox+"')");
	oListName      = eval("document.getElementById('"+cListName+"')");
	if (whichKey==8) { // BS
		var string = oSearchBox.value.substring(0,oSearchBox.value.length-1) ;
	}else{
		if (whichKey < 65 || (whichKey > 90 && whichKey < 97) || whichKey > 122) {
			return false;
    	}
    	var string = oSearchBox.value + String.fromCharCode(whichKey);
    }
    string = string.toLowerCase();
    var optionsLength = oListName.length;
    for (var n=0; n < optionsLength; n++) {
    	var optionText = oListName.options[n].text;
    	optionText = optionText.toLowerCase();
    	if (optionText.indexOf(string,0) == 0) { 
    		oListName.selectedIndex = n;
    		return false;
    	}
    }
    oListName.selectedIndex = 0;
    return true;
}

//***********************************************
 function reverseSearchItem(cSearchBox,cListName) {
	oSearchBox = eval("document.getElementById('"+cSearchBox+"')");
	oListName  = eval("document.getElementById('"+cListName+"')");
	oSearchBox.value = oListName.options[oListName.selectedIndex].text;
}

//***********************************************
function addItem(cSearchBox,cListName,cSelectedItems) {
 	oSearchBox     = eval("document.getElementById('"+cSearchBox+"')");
 	oListName      = eval("document.getElementById('"+cListName+"')");
 	oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
 	x = oListName.value;
	xLower = x.toLowerCase();
	if (x.length == 0) { return;}
	lFound  = false;
	nLength = oSelectedItems.length;
	if (nLength > 0) {
		for (i=0; i < nLength; i++) {
			if (xLower == oSelectedItems.options[i].value.toLowerCase()) {
				lFound = true;
				break;
			}
		}
	}
	if (lFound==false){
		optionValue = oListName.options[oListName.selectedIndex].value;
		optionText  = oListName.options[oListName.selectedIndex].text;
		newOption = new Option(optionText,optionValue);
   	    oSelectedItems.options[nLength] = newOption;
	}
	oSearchBox.value        = '';
	oListName.selectedIndex = 0;
	oSearchBox.focus();
	oSearchBox.select();
}



//***********************************************
/*function addItem(cSearchBox,cListName,cSelectedItems) {
 	oSearchBox     = eval("document.getElementById('"+cSearchBox+"')");
 	oListName      = eval("document.getElementById('"+cListName+"')");
 	oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
 	x = alltrim(oSearchBox.value);
	xLower = x.toLowerCase();
	if (x.length == 0) { return;}
	lFound  = false;
	nLength = oSelectedItems.length;
	if (nLength > 0) {
		for (i=0; i < nLength; i++) {
			if (xLower == oSelectedItems.options[i].text.toLowerCase()) {
				lFound = true;
				break;
			}
		}
	}
	if (lFound==false){
		optionValue = oListName.options[oListName.selectedIndex].value;
		optionText  = oListName.options[oListName.selectedIndex].text;
		newOption = new Option(optionText,optionValue);
   	    oSelectedItems.options[nLength] = newOption;
	}
	oSearchBox.value        = '';
	oListName.selectedIndex = 0;
	oSearchBox.focus();
	oSearchBox.select();
}
*/

//***********************************************
function removeItemSelected(cSelectedItems) {
	oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
	for (i=oSelectedItems.length-1 ; i >=0; i--) {
		if (oSelectedItems.options[i].selected) {
			oSelectedItems.remove(i);
		}
	}
}

//***********************************************
function removeItemAll(cSelectedItems)	{
	oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
	for (i=oSelectedItems.length-1 ; i >=0; i--) {
		oSelectedItems.remove(i);
	}
}

//***********************************************
function selectList(cSelectedItems){
oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
lnLength = oSelectedItems.length;
for (j = 0 ; j < lnLength; j++) {
oSelectedItems.options[j].selected = true;
}
}

//***********************************************
function unselectList(cSelectedItems){
	oSelectedItems = eval("document.getElementById('"+cSelectedItems+"')");
	lnLength = oSelectedItems.length;
	for (j = 0 ; j < lnLength; j++) {
		oSelectedItems.options[j].selected = false;
	}
}

//***********************************************
function strTran(cString,cSearchFor,cReplaceBy) {    
    a = cString.split(cSearchFor)
    newString = ''
    for (i=0 ; i < a.length; i++) {
       	newString = newString+a[i]+cReplaceBy
    }
    finalString = newString.slice(0,eval(newString.length - cReplaceBy.length))
    return finalString
}

//***********************************************
function AJAX() {
	// Create the XMLHttpRequest Object
	// Different browsers use different methods to create the XMLHttpRequest object.
		
	var oAJAX  = null;
			
	try {oAJAX = new XMLHttpRequest();} 							    // Firefox, Opera 8.0+, Safari uses built in JavaScript Object XMLHttpRequest()
		catch (e){
			try { oAJAX = new ActiveXObject("Msxml2.XMLHTTP"); } 		// Internet Explorer 6.0+ uses ActiveXObject("Msxml2.XMLHTTP")
				catch (e){
					oAJAX = new ActiveXObject("Microsoft.XMLHTTP");		// Internet Explorer 5.5+ uses ActiveXObject("Microsoft.XMLHTTP")
			    }
			}
	return oAJAX;
}




