//*** validate form
var error="";
var cCount=0;

	function patternCheck(e){
		if (e == null) e = window.event;
		var key = (e.which)?e.which:e.keyCode
		
		if(trapZero()){
		if ((key >=48 && key <=57)||(key == 9)||(key == 8) || (key ==46) || (key ==44)){
			//alert("good" + key);
			document.getElementById("msg").innerHTML = "";
			document.getElementById("msg").style.display = "none";
			return true;
		}else{
		document.getElementById("msg").style.display = "block";
		document.getElementById("msg").innerHTML = "ERROR: You can only enter numbers here."; //"ERROR: You can only enter valid characters in this field:Numbers: 0-9"
			return false;
		}
		}else{		
			document.getElementById("INVamount").value = "";
			return false;
		}
	}
	
	function trapZero(){
		var t = document.getElementById("INVamount").value;
				
		if(t.charAt(0)== "0"){
			document.getElementById("msg").style.display = "block";
			document.getElementById("msg").innerHTML	= "ERROR: Invalid Input. Must not start with zero."	
			return false;
		}else{
			document.getElementById("msg").innerHTML = "";
			document.getElementById("msg").style.display = "none";
			return true;
		}
	}

function checkWholeForm(theForm) {
 var why = "";
why+= checkINVnum (theForm.INVnum.value);
why+= checkINVamt(theForm.INVamount.value);


   if (why != "") {    alert(why);  return false;    }
return true;

}



function checkINVnum (strng)
{
	 if (strng == "") {    error = "You didn't enter a Invoice number.\n"; }
	 else error="";
 return error;
}

function checkINVamt (strng)
{
	 if (strng == "") {    error = "You didn't enter a Invoice amount.\n"; }
	 	 else error="";
 return error;
}

//*************************************8
function getBTN(url){
			name= document.form1.name.value
			desc = document.form1.desc.value
			merID = document.form1.merID.value
			price = document.form1.price.value			
			param_number = document.form1.param_number.value
            
			
	
			document.getElementById("div1").innerHTML='...'
            url="include/test2.ajax.php?merID="+merID+"&name="+name+"&desc="+desc+"&price="+price+"&param_number="+param_number
	
			xmlHttp=GetXmlHttpObject(btnStateChanged)
			xmlHttp.open("GET", url , true)
			xmlHttp.send(null)
						
		}
		
		

		function btnStateChanged(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
				document.getElementById("div1").innerHTML=xmlHttp.responseText
  			    document.getElementById("div2").innerHTML=xmlHttp.responseText
			}
		}


// show buttons
		function getBTNall(url){
     
	       elemID ='contents'
            url="include/showall.php?elemID="+elemID
			xmlHttp=GetXmlHttpObject(btnStateChangedall)
			xmlHttp.open("GET", url , true)
			xmlHttp.send(null)
	

						
		}
		




		function btnStateChangedall(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
  			    document.getElementById("div2").innerHTML=xmlHttp.responseText
			}
		}

// END show button

// show buttons
		function showcode(url){
     
	       elemID ='contents'
            url="include/showall.php?elemID="+elemID
			xmlHttp=GetXmlHttpObject(codeStateChanged)
			xmlHttp.open("GET", url , true)
			xmlHttp.send(null)
	

						
		}
		

		function codeStateChanged(){
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
  			    document.getElementById("div_code").innerHTML=xmlHttp.responseText
			}
		}

// END show button


// update

		function getUpdate(url){
			
            name= document.form1.name.value
			desc = document.form1.desc.value
			merID = document.form1.merID.value
			price = document.form1.price.value			
			param_number = document.form1.param_number.value
			dummy= document.form1.dummy.value            
			check= document.form1.check.value            
			
	
			document.getElementById("div1").innerHTML='...'
            url="test2.ajax.php?merID="+merID+"&name="+name+"&desc="+desc+"&price="+price+"&param_number="+param_number+"&dummy="+dummy+"&check="+check
	
			xmlHttp=GetXmlHttpObject(btnStateChanged)
			xmlHttp.open("GET", url , true)
			xmlHttp.send(null)
						
		}
// end update




function toggle(toggleId, e)
{
  var body,im,i;

  
  myhide(toggleId,e);
 if (!e)e = window.event;

 if (!document.getElementById)return false;

 body = document.getElementById(toggleId);
 if (!body) return false;
 
  im = toggleId + "_toggle";

 if (body.style.display == 'none')body.style.display = 'block'; 

 if (e) {
  // Stop the event from propagating, which
  // would cause the regular HREF link to
  // be followed, ruining our hard work.
  e.cancelBubble = true;
  if (e.stopPropagation) {
   e.stopPropagation();
  }
 }
}

function myhide(toggleId, e)
{
  var body,im;
 if (!e)e = window.event;

 if (!document.getElementById)return false;

 body = document.getElementById(toggleId);
 if (!body) return false;
 
  im = toggleId + "_toggle";

 if (body.style.display != 'none') body.style.display = 'none'; 


 if (e) {
  // Stop the event from propagating, which
  // would cause the regular HREF link to
  // be followed, ruining our hard work.
  e.cancelBubble = true;
  if (e.stopPropagation) {
   e.stopPropagation();
  }
 }
}


function myhide2(toggleId,toggleId2, e)
{
	myhide(toggleId,toggleId2,e);
}

