function display(id)
	{
		document.getElementById(id).style.display = (document.getElementById(id).style.display == "block" ? "none" : "block");
	}
	
function displayid(id, action)
	{
	switch(action) {
		case 'none':
		document.getElementById(id).style.display = "none";
		break;
		
		case 'block':
		document.getElementById(id).style.display = "block";
		break;
	}
	}
	

function validate_field(field, value, frm) {
		var email_r = new RegExp("email");
		switch(true) {
		case field=='email':
		case email_r.test(field):
		part1=value.indexOf("@")
		part2=value.lastIndexOf(".")
		if (part1<1||part2-part1<2) {return false} else {return true}		
		break

		case field=='password':
		if (value!=frm.password_repeat.value||value.length<6) {
			frm.password_repeat.style.borderBottom = '2px solid #FF0000';
			return false
		} else {
			frm.password_repeat.style.borderBottom = '1px solid #00AA00';
			return true
		}
		break
		
		case field=='username':
		if (value==null||value==""||value.length<2)  {return false} else {return true}
		break
		
		case field=='seccode':
		if (value.length>3)  {return true} else {return false}
		break;
		
		case frm[field].type=='checkbox':
		    if(frm[field].checked == false) {
				frm[field].style.outline = '2px solid #FF0000'; // mozilla
				return false
			} else {
				frm[field].style.outline = '1px solid #00AA00'; // mozilla
				return true
			}	
		break
		
		default:
			if (value==null||value==0)  {return false} else {return true}
		break
	}
}

function validate_form(form_id, array_fields, error_msg) {
var frm = document.getElementById(form_id);
var fields=array_fields.split(", ");
var alert_msg='';
var field='';
//alert(formname);
for (i=0;i<fields.length;i++) {
	if (validate_field(fields[i], frm[fields[i]].value, frm)==false) {
		alert_msg = 1;
		frm[fields[i]].style.border = '2px solid #FF0000';
		} else {
		//alert_msg = 0;
		frm[fields[i]].style.border = '1px solid #00AA00';
		};
}
	
	if (alert_msg == 1) {
		// scroll(0,0);
		alert(error_msg);
		return false;
	} else {
		if(frm['submit']){
			frm['submit'].disabled=true;
			frm['submit'].value='Loading...';
		}
		//displayid('web', 'none');
		//displayid('loading', 'block');
		return true;
	}
	
}


function url2frame(id, url) {
	document.getElementById('frame_content').src=url;
	document.getElementById('layer0').style.display="block";
}

function js_confirmUrl(url, msg) {
		if (confirm(msg)) {
			window.open(url, '_self');
		}
}

function fillSelect(selectName, optionArray, selectedItem) {
	var i, j;

	for (i = selectName.options.length; i > 0; i--) {
		selectName.options[i] = null; 
	}
	
	if (optionArray != null) {

		for (i = 0; i < optionArray.length; i++) {
				selectName.options[i+1] = new Option(optionArray[i]);
				selectName.options[i+1].value = optionArray[i]; 
				
			}
		}		
	if (selectedItem != null) {	
	selectName.options[selectedItem].selected = true;
	}
}
