// Change language
function change_language(lang){
		mystr = window.location.href;
		page_name = mystr.substring(mystr.lastIndexOf("/")+1);
		temp_path = mystr.substring(0,mystr.lastIndexOf("/"));
		//image_path = temp_path +  "/" + page_name;
		if(lang=="norway"){
			image_path = temp_path.substring(0,temp_path.lastIndexOf("/")) + "/" + page_name;
		}
		else if(lang=="english"){
			image_path = temp_path + "/" + lang + "/" + page_name;
		}
		//alert("page_name   " + page_name + " temp_path " +temp_path + " image_path " + image_path);
		window.location.href = image_path;
	}
// JavaScript Document

function valContactForm(){
	var name = document.getElementById("name").value;
	//var company = document.getElementById("company").value;
	var email = document.getElementById("email").value;
	var phone = document.getElementById("phone").value;
	var question = document.getElementById("question").value;
	if(name==""){
		showError("Name field cannot be left blank");
		document.getElementById("name").focus();
		changeError('name')
		return false;
	}else{
		changeProper('name')
	}
	/*
	if(company==""){
		showError("Company name cannot be left blank");
		document.getElementById("company").focus();
		changeError('company')
		return false;
	}else{
		changeProper('company')
	}
	*/
	if(email==""){
		showError("E-mail field cannot be left blank");
		document.getElementById("email").focus();
		changeError('email');
		return false;
	}else{
		changeProper('email')
	} 
	
	if(!isValidEmail(email))
	{
		showError("Please enter valid E-mail ID");
		document.getElementById("email").focus();
		changeError('email')
		return false;
	}else{
		changeProper('email')
	}
	
	/*
	if(phone=="" || phone.length < '9'){
		showError("Phone number should be numeric and at least 8 characters");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	
	if(!isNumber(phone))
	{
		showError("Please enter numeric only");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	*/
	
	if(question==""){
		showError("Question field cannot be left blank");
		document.getElementById("question").focus();
		changeError('question')
		return false;
	}else{
		changeProper('question')
	}
	//document.guest_form.submit();
}



function valContactFormNorway(){
	var name = document.getElementById("name").value;
	//var company = document.getElementById("company").value;
	var email = document.getElementById("email").value;
	var phone = document.getElementById("phone").value;
	var question = document.getElementById("question").value;
	if(name==""){
		showError("Navn må fylles ut");
		document.getElementById("name").focus();
		changeError('name')
		return false;
	}else{
		changeProper('name')
	}
	/*
	if(company==""){
		showError("Company name cannot be left blank");
		document.getElementById("company").focus();
		changeError('company')
		return false;
	}else{
		changeProper('company')
	}
	*/
	if(email==""){
		showError("E-mail må fylles ut");
		document.getElementById("email").focus();
		changeError('email');
		return false;
	}else{
		changeProper('email')
	} 
	
	if(!isValidEmail(email))
	{
		showError("Korrekt e-mailadresse må fylles ut");
		document.getElementById("email").focus();
		changeError('email')
		return false;
	}else{
		changeProper('email')
	}
	
	/*
	if(phone=="" || phone.length < '9'){
		showError("Phone number should be numeric and at least 8 characters");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	
	if(!isNumber(phone))
	{
		showError("Please enter numeric only");
		document.getElementById("phone").focus();
		changeError('phone')
		return false;
	}else{
		changeProper('phone')
	}
	*/
	
	if(question==""){
		showError("Spørsmål må fylles ut");
		document.getElementById("question").focus();
		changeError('question')
		return false;
	}else{
		changeProper('question')
	}
	//document.guest_form.submit();
}
/*
Common Function to validate contact form
*/	
function trim(str)
{ 
	return((""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function isSpchar(value){
  var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isNumber(str){
	
//	var filter=/^[\d]+$/;
	var filter=/^[0-9]+$/;
	if(filter.test(trim(str)))
	return true;
	else
	return false;
}

function isNum(value){
  var iChars = "0123456789";

  for (var i = 0; i < value.length; i++) {
  	if (iChars.indexOf(value.charAt(i)) != -1) 
  	{
  		return true;
  	}
  }	
  return false;
}

function isValidEmail(value){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(trim(value)))
		return true;
	else
		return false;
	
}

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');
	try{
	increaseHeight()
	}catch(e){}
}

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 showThanks(formdiv){
	toogleElement(formdiv,'none');
	toogleElement('thanks','block');
}
function showform(url){
//alert(parent.popup);
	if(parent.popup==1)
	{
	//	alert("calling show form");
		hideFeedback();
		popup=false;
	}else{
	location=url;
	}
}
