// JavaScript Document
function changeError(id){
	document.getElementById(id).style.borderStyle="solid";
	document.getElementById(id).style.borderColor="red";
	}
function changeProper(id){
	document.getElementById(id).style.borderStyle="";
	document.getElementById(id).style.borderColor="";
	}

function toogleElement(EleName,style){
	var objEle = document.getElementById(EleName);
	if(objEle)
		objEle.style.display=style;
	
}

function showNotification(msg){
	showStatus(msg,'statusMsg');
}
function showError(msg){
	showStatus(msg,'statusErr');
}

function showStatus(msg,type){
	var ele = document.getElementById('errmsg');
	ele.innerHTML = msg;
	ele.className = type;
	toogleElement('errmsg','block');
}

function showError1(msgbox,msg,type){
	var ele = document.getElementById(msgbox);
	ele.innerHTML = msg;
	ele.className = type;
	toogleElement(msgbox,'block');
}

function validate_email(emailTxt)
{
	
	var checkEmail = "@.";
	var checkStr = emailTxt;
	var EmailValid = false;
	var EmailAt = false;
	var EmailPeriod = false;
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkEmail.length;  j++)
	{
	if (ch == checkEmail.charAt(j) && ch == "@")
	EmailAt = true;
	if (ch == checkEmail.charAt(j) && ch == ".")
	EmailPeriod = true;
	  	if (EmailAt && EmailPeriod)
			break;
	  	if (j == checkEmail.length)
			break;
		}
	// if both the @ and . were in the string
	if (EmailAt && EmailPeriod)
	{
		EmailValid = true
		break;
	}
	}
	if (!EmailValid)
	{
	  return false;
	}else{
		return true;
	}
	
}

function validateNumber(){
	//check Telefoon
	if (document.form1.phone.value.length < 5)
	{
		alert("Enter Proper Phone Number");
		document.form1.phone.focus();
		return false;
	}
	
	var checkOK = "0123456789";
		var checkStr = document.form1.phone.value;
		var allValid = true;
		for (i = 0;  i < checkStr.length;  i++)
		{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length)
		{
		allValid = false;
		break;
		}
		}
	if (!allValid)
	{
	alert("Please enter only Numeric Values in the \"Telefoon\" field.");
	document.form1.phone.focus();
	return (false);
	}	
}

function valForm_login()
{
	
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	isValid=1;
	//alert(fname);
	if(username==""){
		document.getElementById("username").focus();
		changeError('username')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('username')
	}
	
	if(password==""){
		if(isValid)
		document.getElementById("password").focus();
		changeError('password')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('password')
	}
	
	if(isValid==0){
		showError("The fields highlighted  in red cannot be blank");
		
		return false;
		}else{
		toogleElement('errmsg','none');
		document.loginform.submit();
	}
}


