// is a time in 'uummss' or 'uu:mm:ss' format, 
// where ":" may also be any other non-alphanumeric character

Indicator_Expand = new Image();
Indicator_Expand.src = "images/icon_expand.gif";
Indicator_Collapse = new Image();
Indicator_Collapse.src = "images/icon_collapse.gif";

function HideShowMenu(group, indicator){
	document.getElementById(group).style.display = (document.getElementById(group).style.display == 'none') ? 'block' : 'none';
	document.forms["payment"][indicator].src = (document.getElementById(group).style.display == 'none') ? Indicator_Collapse.src : Indicator_Expand.src;
	
	if (group=="Title2"){
		document.getElementById("Title1").style.display ='none';
		document.forms["payment"]["Indicator1"].src = Indicator_Collapse.src;
	}else{
		document.getElementById("Title2").style.display ='none';
		document.forms["payment"]["Indicator2"].src = Indicator_Collapse.src;

	}
	
}


function isTime(inputObj) {
	var input = inputObj.value;
	var hour;
	var minute;
	var second;
	match1 = /^[0-9][0-9][0-9][0-9][0-9][0-9]$/;
	match2 = /^[0-9][0-9]\W[0-9][0-9]\W[0-9][0-9]$/;
	if (match1.test(input)) {
		hour = input.substring(0,2);
		minute = input.substring(2,4);
		second = input.substring(4,6);
	}
	else{
		if (match2.test(input)) {
			hour = input.substring(0,2);
			minute = input.substring(3,5);
			second = input.substring(6,8);
		}
		else {return false;}
	}
	
	if (hour > 23) {return false;}
	if (minute > 59) {return false;}
	if (second > 59) {return false;}
	inputObj.value = hour + ":" + minute + ":" + second;
	return true;
}

// is a date. The format parameter should be either:
// "dd-MM-yyyy" -> accepts input formats ddMMyyyy or d(d)-M(M)-yyyy,
// "yyyy-MM-dd" -> accepts input formats yyyyMMdd or yyyy-M(M)-d(d),
// where '-' may also be any other non-alphanumerical character
function isDate(inputObj, format) {
	var f;
	if (format == "dd-MM-yyyy"){f=1;}
	else{if (format == "yyyy-MM-dd"){f=2;}else {return false;}}
	var input = inputObj.value;
	var day;
	var month;
	var year;
	match1 = /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
	match2 = /^[0-9][0-9]?\W[0-9][0-9]?\W[0-9][0-9][0-9][0-9]$/;
	match3 = /^[0-9][0-9][0-9][0-9]\W[0-9][0-9]?\W[0-9][0-9]?$/;
	if (match1.test(input)) {
		if (f == 1){
			day = input.substring(0,2);
			month = input.substring(2,4);
			year = input.substring(4,8);
		}
		if (f == 2){
			day = input.substring(6,8);
			month = input.substring(4,6);
			year = input.substring(0,4);
		}
	}
	else{
		if ((match2.test(input) && f==1) || (match3.test(input) && f==2)) {
			sep = /\W/;
			var sep1, sep2;
			var i = 0;
			for(i=0;i<input.length;i++){
				if (sep.test(input.charAt(i))){sep1=i; break;}
				}
			for(var j=i+1;j<input.length;j++){
				if (sep.test(input.charAt(j))){sep2=j; break;}
				}
			if (f == 1){
				day = input.substring(0,sep1);
				month = input.substring(sep1+1,sep2);
				year = input.substring(sep2+1,input.length);
			}
			if (f == 2){
				year = input.substring(0,sep1);
				month = input.substring(sep1+1,sep2);
				day = input.substring(sep2+1,input.length);
			}
		}
		else {return false;}
	}
	if (month > 12) {return false;}
	var daymax;
	if (month==4 || month==6 || month==9 || month==11) {daymax = 30;}
	else {
		if (month==2) {
			if ((year%4==0 && year%100!=0) || year%400==0) {daymax = 29}
			else {daymax = 28;}
			}
		else {daymax = 31;}
	}
	if (day > daymax) {return false;}
	if (f == 1){inputObj.value = day + "-" + month + "-" + year;}
	if (f == 2){inputObj.value = year + "-" + month + "-" + day;}
	return true;
}

// Removes white space from both ends of a string.
function trim(inputObject) {
	var input = inputObject.value;
	var left=0;	
	var right = input.length;
	var i;
	var j;
	for(i=0;i<=right;i++){
		if (input.substring(i,i+1).search(/\u0020/)!=-1)     
		{
			left++;
		} else {
			break;
		}
	}
	if (left != right)
	{
		for(j=input.length;j>left;j--){
			if (input.substring(right,right-1).search(/\u0020/)!=-1)     
			{
				right--;
			} else {
				break;
			}
		}
	}
	inputObject.value = input.substring(left,right);
	return inputObject;
}


