// JavaScript Document

/*Email box */

function doOnFocus(input) {
//	input.style.backgroundColor = '#FFAAAA';
	if ( input.value == input.title ) input.value = "";
}
function doOnBlur(input) {
	if ( input.value == "" ) input.value = input.title;
}

function doOnFocusMultiLine(input) {
	input.focus();
	var val = input.value;
	input.value = '';
	input.value = val;  
	input.focus();
}
function doSomething(input) {
	if ( input.value == input.title ) input.value = "";

//	if ( input.value.indexof("@", 2 ) >= 0 ) input.style.backgroundColor = '#8888FF';
	if ( input.value.length >= 0 ) input.style.backgroundColor = '#AAFFAA';
}

function doSomething2(input) {
//	alert(event.srcElement.value);
	input.style.backgroundColor = '#AAAAAA';
	if ( input.value == "" ) input.value = input.title;
}

// document.getElementById('email-box-input').focus = doSomething;


// Validate form
function validateForm(form,type)
 {
 var Fejl="" 
 
 // tjek navn
 var value=form["name"].value
 // trim name
 value = value.replace(/^\s+|\s+$/g, '')
 if ( value != form["name"].value ) { form["name"].value = value }
  // check name
 if ( value.length < 2|| value==form["name"].title  ) 
  {
	if ( Fejl != "" ) 
	{ Fejl = Fejl + " og "  }
   Fejl = Fejl + "dit navn";
   form["name"].style.backgroundColor = '#FFDDDD';
   }
   else
   {
   form["name"].style.backgroundColor = '#DDFFDD';
   }

 // tjek phone
 if ( type == 5 ) {
 var value=form["phone"].value
  // trim name
 value = value.replace(/^\s+|\s+$/g, '')
 if ( value != form["phone"].value ) { form["phone"].value = value }
  // remove common characters
 value = value.replace(/[\(\)\.\+\-\ ]/g, '');     
 // check phone
 if ( isNaN(parseInt(value))  || value.length<8 )
   {
	if ( Fejl != "" ) 
	{Fejl = Fejl + " og "  }
   Fejl = Fejl + "dit telefonnummer";
   form["phone"].style.backgroundColor = '#FFDDDD';
   }
   else
   {
   form["phone"].style.backgroundColor = '#DDFFDD';
   }
 
 }
 
 // tjek e-mail
 var field="email"
 if (type != 5 ) {
	 field = "email1"
 }

 var value=form[field].value
  // trim e-mail
 value = value.replace(/^\s+|\s+$/g, '')
  if ( value != form[field].value ) { form[field].value = value }
 // check e-mail
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 // var reg = /^([A-Za-z0-9_\-\.])+\@(\S)+\.([A-Za-z]{2,4})$/; // \S = non-space

 if ( !reg.test(value) || value.length <6 )
   {
	if ( Fejl != "" ) 
	{Fejl = Fejl + " og "  }
   Fejl = Fejl + "din e-mail";
   form[field].style.backgroundColor = '#FFDDDD';
   }
   else
   {
   form[field].style.backgroundColor = '#DDFFDD';
   }

 // tjek text
 if ( type == 5 ) {
 var value=form["text"].value
  // trim text
 value = value.replace(/^\s+|\s+$/g, '')
 if ( value != form["text"].value ) { form["text"].value = value }
 // check text
 if ( value.length < 5|| value==form["text"].title  ) 
   {
	if ( Fejl != "" ) 
	{Fejl = Fejl + " og "  }
   Fejl = Fejl + "din beskrivelse";
   form["text"].style.backgroundColor = '#FFDDDD';
   }
   else
   {
   form["text"].style.backgroundColor = '#DDFFDD';
   }
 }
   
   
   if ( Fejl != "" ) {
		alert("Der er fejl i skemaet. Du må gerne tjekke " + Fejl);
		return false;
   }
 }
 

// Reset form
function resetForm(form,type)
 {
//	var form=button.form.id	 
 //reset name	 
   form["name"].style.backgroundColor = '#FFFFFF';
 // reset phone
 if ( type = 5 ) {
   form["phone"].style.backgroundColor = '#FFFFFF';
 }
 
 // reset e-mail
 var field="email"
 if (type != 5 ) {
	 field = "email1"
 }
   form[field].style.backgroundColor = '#FFFFFF';

 // reset text
 if ( type = 5 ) {
   form["text"].style.backgroundColor = '#FFFFFF';
 }
}
 


