// 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('msg');
	ele.innerHTML = msg;
	ele.className = type;
	toogleElement('msg','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){
		toogleElement('msg','none');
		return true;
	}else{
		showError("De in rood gemarkeerde velden mogen niet leeg zijn.");
		return false;
	}
}

function validateProfile(){
	var fname = document.getElementById("fname").value;
	var lname = document.getElementById("lname").value;
	var company = document.getElementById("company").value;
	var country = document.getElementById("country1").value;
	var mailbuisness = document.getElementById("mailb").value;
	isValid=1;
	//alert("country1 "+ country);
	if(fname==""){
		document.getElementById("fname").focus();
		changeError('fname')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('fname')
	}
	
	if(lname==""){
		if(isValid)
		document.getElementById("lname").focus();
		changeError('lname')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('lname')
	}
	
	if(company==""){
		if(isValid)
		document.getElementById("company").focus();
		changeError('company')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('company')
	}
	if(country==""){
		if(isValid)
		document.getElementById("country1").focus();
		changeError('country1')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('country1')
	}
	if(mailbuisness==""){
		if(isValid)
		document.getElementById("mailb").focus();
		changeError('mailb')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('mailb')
	}
	
	if(isValid){
		if(!validate_email(mailbuisness)){
			document.getElementById("mailb").focus();
			changeError('mailb')
			showError1("errormsg","Invalid email","statusErr")
		 	return false;
		}
		toogleElement('errormsg','none');
		return true;
	}else{
		//showError("The fields highlighted  in red cannot be blank");
		showError1("errormsg","De rood gemarkeerde velden mogen niet leeg zijn.","statusErr")
		return false;
	}
	//return false;
}

//Function to validate feedback form
function validateFeedback1(){
	radioArray = new Array("accomodation","catering","amusement","teambuilding","communication","timing","gaming");
	isValid=0;
	//alert(eval("document.feedback.accomodation["+0+"]"));
	
	for(i=0;i<7;i++){ 
	  for(j=0;j<5;j++){ 
	   	if(eval("document.feedback."+radioArray[i]+"["+j+"]").checked){
		    isValid=1;
		    break;
	    }else { 
		   isValid=0;
		}
	  }
	  if(!isValid)
	  	break;
	}
	
	if(isValid==1){
		return true;     
	} else {
		showError1("errormsg","Geef aub een score aan elk deelaspect.","statusErr")
		//alert("Please rate each option.");
		return false;
	}
}

//Function to validate contact form
function validateContact(){
	var subject = document.getElementById("subject").value;
	var comments = document.getElementById("comments").value;
	
	isValid=1;
	//alert("country1 "+ country);
	if(subject==""){
		document.getElementById("subject").focus();
		changeError('subject')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('subject')
	}
	
	if(comments==""){
		if(isValid)
		document.getElementById("comments").focus();
		changeError('comments')
		isValid=0;
	}else {
		//showError("The to city cannot be blank");
		changeProper('comments')
	}
	
	if(isValid){
		toogleElement('errormsg','none');
		return true;
	}else{
		//showError("The fields highlighted  in red cannot be blank");
		showError1("errormsg","De in rood gemarkeerde velden mogen niet leeg zijn.","statusErr")
		return false;
	}
}
