/**
 * @author Jude@iSys Nairobi
 * file contains all shared js functions
 * Date: 04-04-2011
 */

function validDate(o){
	date=o.value;
	cal1 = new calendar1(o);
	if (/[^\d-]|(\-\-)/g.test(date)){
		o.value=o.value.replace(/[^\d-]/g,'');
		o.value=o.value.replace(/\-{2}/g,'-'); 
		return
	}
	if (/^\d{2}$/.test(date)){
		o.value=o.value+'-'; 
		return 
	}
	if (/^\d{2}\-\d{2}$/.test(date)){
		o.value=o.value+'-';
		return
	}
	if (!/^\d{1,2}\-\d{1,2}\-\d{4}$/.test(date)){
		return
	}
	isDate(o);
	 o.focus();
	 return false;
}

function isDate(o){
	if (o.value =='') return ;
	cal1 = new calendar1(o);
	 if (cal1.prs_date(o.value)==null){
		 return false;
		 
	 }
	 
}

function isDigit(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

function isGoodDate(strDate){
	var reDate = /(?:0[1-9]|[12][0-9]|3[01])\-(?:0[1-9]|1[0-2])\-(?:19|20\d{2})/;
	if(reDate.test(strDate.value)){
		return true;
	} else {
		alert('Den indtastede dato er desværre ugyldig.');
		strDate.focus();
		strDate.value = "";
		return false;
	}
}
