function CJL_getCurrentStyle(elem, prop)
{
   if( elem.currentStyle )
   {  
      var ar = prop.match(/\w[^-]*/g);
      var s = ar[0];
      
      for(var i = 1; i < ar.length; ++i)		   
      {
         s += ar[i].replace(/\w/, ar[i].charAt(0).toUpperCase());
      }
           
      return elem.currentStyle[s]
   }
   else if( document.defaultView.getComputedStyle )
   {
      return document.defaultView.getComputedStyle(elem, null).getPropertyValue(prop);
   }
}

function validate (objX) {
	var cond =false;
	var temp = new Array();
	if (objX.indexOf('|') < 0){
		obj =MM_findObj(objX);
		if (obj.value == "") {
			cond = true;
		}
	}
	else {
		temp = objX.split('|');
		obj = MM_findObj(temp[0]);
		if (temp.length==2) {
			if (temp[1]=="@" ) {cond = isNotEmailAddr (obj.value);}
			else {
				if (temp[1]=="$" ){
					cond =  !IsNumeric(obj.value);
				}
				else{
					if ( obj.value.length != (temp[1]*1) ) {
						cond = true;
					}
				}
			}
		}
		
		if (temp.length>2) {
			//alert("temp[2]: "+temp[2]+" temp.length: "+ temp.length+" obj.value.length: "+ obj.value.length)
			if (temp[1]=="@" &&  temp[2]=="0") {obj.value!=''?cond = isNotEmailAddr (obj.value):cond=false;}
			else{
				if (temp[1]=="$"){
					if(temp[2]=="0" && temp.length==3){obj.value!=''?cond=!IsNumeric(obj.value):cond=false;}
					if (temp[2]=="0" && temp.length>3 ){
						if (obj.value.length==0) cond = false;
						else (obj.value.length == (temp[3]*1))?cond=!IsNumeric(obj.value):cond=true;
					}
					if (temp[2]!="0"){
						if (temp[3]=="+"){ 
							if (obj.value.length < (temp[2]*1))cond=true;
							else cond=!IsNumeric(obj.value);
							}
						else{
							if ( obj.value.length == (temp[2]*1)  && temp.length==3)cond=!IsNumeric(obj.value);
							else cond=true;
							if (obj.value.length > (temp[3]*1) || obj.value.length < (temp[2]*1)) {cond = true;}
							else{ cond=!IsNumeric(obj.value);	}														   
							
						}
					}
						// alert(cond);
					
				}
				else{
				
					if (temp[2]=="+" && obj.value.length < (temp[1]*1) ) {cond = true;}
					else { 
						if (obj.value.length > (temp[2]*1) || obj.value.length < (temp[1]*1) ) {
						cond = true;
						}
					}
				}
			}
		}
	}
	isRadio = 0;
	radioOrSelect=false;
	if (obj[isRadio]!=null) radioOrSelect=true;
	if (obj.options!=null) radioOrSelect=true;
	if (obj[isRadio]!=null && obj.options == null){
		if( obj[isRadio].type.toUpperCase()=="RADIO"){
			cond =true;
			
			while(obj[isRadio]!=null){
				if (obj[isRadio].checked == true) {
					cond =false ;
				}
				isRadio++;
			}
			obj=obj[isRadio-1];
		}
	}
	nx=obj.nextSibling;
	
	if (nx != null){
		if (nx.nodeType == 3){
			nx = nx.nextSibling;
		}	
		if (cond) {
			if (nx.tagName == "span" ||nx.tagName == "SPAN" ){
				
				nx.className="errF";
				c=CJL_getCurrentStyle(obj, 'width');
				c= c.replace("px"," ");
				radioOrSelect?nx.style.marginLeft = -5:nx.style.marginLeft = -(c/3);
				return 1;	
			}
		}
		else {
			if (nx.tagName == "span" || nx.tagName == "SPAN"){
				nx.className="err";
			}
			return 0;
		}	
	}
	else return 0;
}

function formReValidate (arr) {

	var errCount = 0;
	args=formValidate.arguments;
	for (w = 0; w < arr.length; w=w+3 ){
		
		if(arr[w+2] == 1 || (arr[w+2] == 2 && unfold>1) || (arr[w+2] == 3 && unfold>2) || (arr[w+2] == 4 && unfold>3) ) {
			oF=arr[w]+arr[w+1];
			pE = validate(oF);
			
			errCount = errCount + pE; 
		}
	}
	if (errCount > 0) {
		if (errCount ==1) alert("Sorry, but there is still " + errCount + " missing or wrong field in this page!");
		else alert("Sorry, but there are still " + errCount + " missing or wrong fields in this page!");
		return (false);
		}
	else { return (true);}
}

function formValidate () {
	var errCount = 0;
	args=formValidate.arguments;
	for (i = 1; i < args.length; i++ ){
		oF=args[i];
		
		pE = validate(oF);
		errCount = errCount + pE; 
	}
	if (errCount > 0) {
		if (errCount ==1) alert("Sorry, but there is still " + errCount + " missing or wrong field in this page!");
		else alert("Sorry, but there are still " + errCount + " missing or wrong fields in this page!");
		return (false);
		}
	else { return (true);}
}

function isNotEmailAddr (email) {
  var result =true 
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = false;
  }
  return result;
}
function getFormCollection (frm){
var str="";
lFrm=frm.elements.length;
for (i=0; i<lFrm; i++){
	if (((frm.elements[i].type.toUpperCase()=="RADIO" || frm.elements[i].type.toUpperCase()=="CHECKBOX") && frm.elements[i].checked!=true)||frm.elements[i].type.toUpperCase()!="SUBMIT");
	else str=str + frm.elements[i].id + "=" + escape(frm.elements[i].value) ;
	if (i<(lFrm-2))str=str+"&";
	}
return (str);
}
function IsNumeric(sText){
   var ValidChars = "0123456789. ";
   var IsNumber=true;
   var Char;
   if (sText=="") return false;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


var unfold=0;

function setUnfold (val){
	val!=""?unfold=val: unfold=0;
}

function findObj(theObj, theDoc){
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}


function changeTR(rowId, n, r){
styleN = CJL_getCurrentStyle(findObj ("primRow"), "display");
if (!r) r=4;
	for ( i=1; i<=r;i++){
		obj=findObj (rowId + i);
		if (i<=n) obj.style.display = styleN;
		else obj.style.display = "none";
		
	}
}
function changeDiv(divId, d){

		obj=findObj (divId);
		if (d) obj.style.display = "block";
		else obj.style.display = "none";
}

function fillFormFromSession (form){

  if (xmlHttp.readyState == 4) {
   var response = xmlHttp.responseText;
   var isRadio;
	loadW =MM_findObj("loadM");
	loadW.className="errM";
   objX = response.split('&');
   for (i=0; i<objX.length-1; i=i+2){
	   isRadio=0
	   obj =MM_findObj(objX[i]);
	   while(obj[isRadio]!=null) 
	   {
		   isRadio++;
	   }
		if (obj.options != null){
		
				 for(z=0; z<obj.options.length; z++){
					
					 if ( obj[z].value == objX[i+1]){obj[z].selected=true; break;}
					}	 
			   }
		else {			   
	   if (isRadio!=0){
	   		for(y=0; y<isRadio; y++){
				
	   			if ( obj[y].value == objX[i+1]){obj[y].checked=true;break;}
			}
	   }
	   else{
		   if (obj.type.toUpperCase()=="CHECKBOX") {
				if ( obj.value == objX[i+1])obj.checked=true;
				else obj.checked=false;
				}
		 
			   else obj.value = objX[i+1];
		   }
	   }
   }    // end of for loop
	loadW.className="err";
   //document.getElementById("sumary").innerHTML = response;
   callSummaryFirst();

 }
}