// preload images
// simplePreload( '01.gif', '02.gif' );
function simplePreload(){
  	 var args = simplePreload.arguments;
  	 document.imageArray = new Array(args.length);
  	 for(var i=0; i<args.length; i++)
  	 {
    	 document.imageArray[i] = new Image;
    	 document.imageArray[i].src = args[i];
  	 }
}
	 
// switch images
// switchImage( 'nomeImg', '01.gif' );
function switchImage(imgName, imgSrc){
	if (document.images){
		if (imgSrc != ''){
		 document.images[imgName].src = imgSrc;
		}
	}
}

function MM_openBrWindow(theURL,winName,features){
  window.open(theURL,winName,features);
}

// validate forms
// check('formName');
function check(frm){
	if(validate(document.forms[frm])){
	  document.forms[frm].submit();
	}
}

function returnSelection(radioButton) {
	var selection=null;
	for(var i=0; i<radioButton.length; i++) {
		 if(radioButton[i].checked) {
		   selection=radioButton[i].value;
		   return selection;
		 }
	}
	return selection; 
} 

// function open pop-up
// openWindow('urlPage', 'namePopup', 'width', 'height', 'yes/no', 'yes/no');
function openWindow(mypage,myname,w,h,resizable,scrollbars){ 
	LeftPosition = ((screen.width) ? (screen.width-w)/2 : 0)-13; 
	TopPosition = ((screen.height) ? (screen.height-h)/2 : 0); 
	settings = 'scrollbars='+scrollbars+',resizable='+resizable+',height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	win = window.open(mypage,myname,settings) 
	if(win.window.focus){
		win.window.focus();
	} 
}

/* function open file manager */
function openFile(field){ 
	openWindow('flag.php?field='+field+'','file','350','300','yes');
}
/* function open file manager */

/* clock script */ 
var timerID = null 
var timerRunning = false 

function stopclock(){ 
    if(timerRunning) 
        clearTimeout(timerID) 
    timerRunning = false 
} 

function startclock(){ 
    stopclock() 
    showtime() 
} 

function showtime(){ 
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    var timeValue = "" + hours;
    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes;
    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds;
    document.clock.face.value = timeValue;
    timerID = setTimeout("showtime()",1000);
    timerRunning = true;
} 
/* clock script */ 

/* function correct date */
function areCharsInList(s,list) {
	var i,c;
	for (i=0;i<s.length; i++) {
		c = s.charAt(i);
	if (list.indexOf(c) == -1)
		return false;
	}
return true;
}

function isDate(str){
	if(str.length!=10){
		return false;
	}
	if(str.charAt(2)!='/' || str.charAt(5)!='/'){
		return false;
	}
	if( !areCharsInList(str.substring(0,2)+str.substring(3,5)+str.substring(6,10), '1234567890') ){
		return false;
	}
	if(str.substring(3,5)>12){
		return false;
	}
	if(str.substring(0,2)>31){
		return false;
	}
return true;
}

function isTime(str){
	if(str.length!=5){
		return false;
	}
	if(str.charAt(2)!=':'){
		return false;
	}
	if( !areCharsInList(str.substring(0,2)+str.substring(3,5), '1234567890') ){
		return false;
	}
	if(str.substring(3,5)>60){
		return false;
	}
	if(str.substring(0,2)>24){
		return false;
	}
return true;
}
/* function correct date */