/* ####################################################
   #
   #  Children and nodes functiosn
   #
   ######################################################
 */   
  
 	function utils_cleartxtfield( txtfield , defaulttext ){
		if (  txtfield ){
			if ( txtfield.value == defaulttext ){
				
				txtfield.value = "";	
			}
		}
	}	

  
  function utils_removeAllChilds ( idobject ){

    	//alert('will remove all the children of object with id='+ iddropdownmenu );
		var dropobject = document.getElementById( idobject );
		
		if ( dropobject){
				while ( dropobject.hasChildNodes() ){
					var anode = dropobject.lastChild;
					dropobject.removeChild(anode); 
				}
				
		}
	}

	function utils_writediv( adiv, text ){
		
		var adiv = document.getElementById (adiv );
		if ( adiv ){
			adiv.innerHTML = text;
		}
	}
	
	
	function utils_setCheckAppropiately( value, idcheck ){
	  
	  var checkobj = document.getElementById( idcheck );
	  
	  if (checkobj) {
		  
		if( value == "Y" || value == 'y' ) {
				checkobj.checked = true;
		}  
	  }
  }

	
  /* Receives a select (dropdown name) and returns the current selected text
   */


	function utils_getSelectedTextDropDown ( name_dropdown ){
	  
	  var theobj = document.getElementById( name_dropdown );
	  
	  if ( !theobj ) {
			return "";  
	  }
	  
	  if ( !theobj.hasChildNodes() ){
		  return "";
	  }
	  
	  if ( theobj ){
		  
		var elements = theobj.getElementsByTagName ( "option" );
		for(var j=0; j< elements.length; j++){
				if ( theobj.value == elements[j].value ){
					return elements[j].innerHTML;
				}
		}
		  
	  }else{
			return "";  
	  }
	  
  }
	
  function utils_getDropDownValue ( name_dropdown ){
	  
	  var theobj = document.getElementById( name_dropdown );
	  
	  if (!theobj ){
		return "";  
		}
	  
	  if ( !theobj.hasChildNodes() ){
		  return "";
	  }
	  return theobj.value ;
	  
  }



/* ####################################################
   #
   #  html functions
   #
   ######################################################
 */   

  function html_txtfield( name, value, css, jscode){
		
		return '<input type="text"  id="'+name+'" name="'+name+'" value="'+value+'" class="'+css+'" '+jscode+'   >';
  
  }
  function html_button( name, value, css, jscode){
  
  	    return '<input name="send" type="submit" id="'+name+'"  name="'+name+'" value="'+value+'" class="'+css+'" '+jscode+' >';
  }

  function html_txtarea( name, value, css, jscode, cols, vals ){
  
  	    return '<textarea name="send"  id="'+name+'" name="'+name+'" class="'+css+'" '+jscode+' cols="'+cols+'" rows="'+vals+'"  >'+value+'</textarea>';
  }
 function html_checkbox( checkname,  isselected, css, jscode){
	  	
	  return '<input type="checkbox" name="'+checkname+'"  id="'+checkname+'" value="Y" class="'+css+'" '+jscode+' >';
  }




/* ####################################################
   #
   #  text functions
   #
   ######################################################
 */   
 
  function utils_clearDiv(  divname ){
	  
		utils_setDivText(  divname , "" )  ;
  }
  
  function utils_setDivText(  divname , text ){
		var thediv = document.getElementById( divname );
		if ( thediv ){
			thediv.innerHTML = text;
		}
  }

  function formatpad( text , themax, rightpad, padchar  ){
  
  	var toreturn = "";
	
	var size = text.length;
	
	//alert( "size of " + text +  "  is " + size );
	
	if ( size > themax ) {
			return text.substring(0,themax);
	}
	
	for(var i=0; i<themax; i++){
	
		if ( i < size ){
			
			toreturn += text.charAt(i);
			
		}else{
			if ( rightpad ) {
				toreturn += padchar;
			}else{
				toreturn =  padchar + toreturn ;
			}
		}
	
	}
	
	return toreturn;
  
  }
  
  function utils_emptyDropDown( dropdownopbject ){
	  
	     while ( dropdownopbject.hasChildNodes() ){
					var anode = dropdownopbject.lastChild;
					dropdownopbject.removeChild(anode); 
				}
				

  }
  
  function alert2( text ){
	  	//alert(text );
  }
  function alert3( text ){
	  	//alert(text );
  }
  
  
  /*
  	Validatedate expects the year, month and day to be integers above or equal to  0 , where 0 indicates that the user hasn;t
	select a number from the dropdown menu !!
  */
  
  function utils_validateDate1( year, month, day ,extra) {
		
	  	var leap = 0;


		//alert(" receiving year " + year + " and month " + month  + " and day " + day );

		if (   year == 0 || month == 0 || day ==0 ){
		  alert("Please select a valid date "+ extra );
		  return false;		  
		}
		
	    if ((month < 1) || (month > 12)) {
		  alert("Please select a valid date "+ extra );
		  return false;
	   }
  	   /* Validation leap-year / february / day */
	   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
    	  leap = 1;
	   }
	   if ((month == 2) && (leap == 1) && (day > 29)) {
		  alert("Please select a valid date "+ extra );		   
    	  return false;
	   }
	   if ((month == 2) && (leap != 1) && (day > 28)) {
		  alert("Please select a valid date "+ extra );
		  return false;
	   }
   	   /* Validation of other months */
	   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		  alert("Please select a valid date "+ extra );
    	  return false;
	   }
	   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
    	  alert("Please select a valid date "+ extra );
    	  return false;
	   }

		return true;
}
  
  function utils_validateRadioSelected( nameradio , errormessage){
	  

			
			var elements = document.getElementsByName( nameradio );
			
			//alert( "found " + elements.length + " elements of name "+ nameradio );
			
			var wasselected = false;
			for( var x=0; x < elements.length; x++){
				//alert( elements[x].checked );
				if ( elements[x].checked  ){
						wasselected = true;
						break;
				}
			}													
		    if ( !wasselected ) {
				alert ( errormessage );
				return false;
			}					
														
			return true;														
  }
  
  
  /*
  	Validates europena format like:
	
	ddmmyy (171201) or 
	ddmmyyyy (17122001) or 
	ddXmmXyy (17-12-01 or 17y12q01 ... ) or 
	ddXmmXyyyy (17.12.2001 or 17,12,2001 ...) 
	where "X" is any sign not in 0..9, i.e. "-" or "/"
	
  */
  
  
  
  /*
  
  function check_date( valuedate ){
		var checkstr = "0123456789";
		var Datevalue = "";
		var DateTemp = "";
		var seperator = ".";
		var day;	
		var month;
		var year;
		var leap = 0;
		var err = 0;
		var i;
		err = 0;
	    DateValue = valuedate;
	   // Delete all chars except 0..9 
   	   for (i = 0; i < DateValue.length; i++) {
	  		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			     DateTemp = DateTemp + DateValue.substr(i,1);
			  }
	   }
	   DateValue = DateTemp;
	   // Always change date to 8 digits - string
	   // if year is entered as 2-digit / always assume 20xx 
	   if (DateValue.length == 6) {
    		  DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); 
	   }
	   if (DateValue.length != 8) {
	      err = 19;
	   }
	   // year is wrong if year = 0000 
	   year = DateValue.substr(4,4);
	   if (year == 0) {
    	  err = 20;
	   }
   	   // Validation of month
		   month = DateValue.substr(2,2);
		   if ((month < 1) || (month > 12)) {
		      err = 21;
	   }
	   // Validation of day
	   day = DateValue.substr(0,2);
	   if (day < 1) {
    		 err = 22;
	   }
	   // Validation leap-year / february / day 
	   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
    	  leap = 1;
	   }
	   if ((month == 2) && (leap == 1) && (day > 29)) {
    	  err = 23;
	   }
	   if ((month == 2) && (leap != 1) && (day > 28)) {
    	  err = 24;
	   }
   	  // Validation of other months 
	   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
    	  err = 25;
	   }
	   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
    	  err = 26;
	   }

	   if ((day == 0) && (month == 0) && (year == 00)) {
    	  err = 0; day = ""; month = ""; year = ""; seperator = "";
	   }

	   if (err == 0) {
    	  //DateField.value = day + seperator + month + seperator + year;
		  return true;
	   }

	   else {
	      alert("Date is incorrect!");
		  return false;
    	  //DateField.select();
		  //DateField.focus();
	   }
	}
*/


  