﻿/**
 * @author: Jens Blomme
 * @projectDescription: Deze webapi omvat alle javascript functies voor de Anzie website.
 * @version 0.1
 * @since: 21-02-2007
 */
 

/* IE 6 LI:HOVER FIX  */
function loadPage(strPage) {
    fixFlash(strPage);
    backgroundCheck(strPage);
    
    if (window.attachEvent) window.attachEvent("onload", sfHover);
}

function sfHover () {
    var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    for (var i=0; i<sfEls.length; i++) {
        sfEls[i].onmouseover=function() {
            this.className+=" sfhover";
        }
        sfEls[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }
}

function backgroundCheck(strLocation) {
    if (window.screen.width <= 1024) {
        if (strLocation == "default") {
	        document.body.background = "images/background-1024.jpg";
	    }
	    else {
	        document.body.background = "../images/background-1024.jpg";
	    }
    }	
    else if ((window.screen.width > 1024) && (window.screen.width <= 1280)) {
	    if (strLocation == "default") {
	        document.body.background = "images/background-1280.jpg";
	    }
	    else {
	        document.body.background = "../images/background-1280.jpg";
	    }
    }
    else if (window.screen.width > 1280) {
        if (strLocation == "default") {
            document.body.background = "images/background.jpg";
        }
        else {
            document.body.background = "../images/background.jpg";
        }
    }
}

/* IE 6 Flash "disabled" */
function fixFlash(pagina) {
    var strLink = document.getElementById("webnet4u").innerHTML;
    if (pagina != "default") {
        document.getElementById("webnet4u").innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"16\" height=\"19\" id=\"w-logo_WHITE\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"../webnet4u.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#000000\" /><embed src=\"../webnet4u.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#000000\" width=\"16\" height=\"19\" name=\"w-logo_WHITE\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object><br/>" + strLink;
    }
    else {
        document.getElementById("webnet4u").innerHTML = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"16\" height=\"19\" id=\"w-logo_WHITE\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" /><param name=\"movie\" value=\"webnet4u.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#000000\" /><embed src=\"webnet4u.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#000000\" width=\"16\" height=\"19\" name=\"w-logo_WHITE\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /></object><br/>" + strLink;
    }
}
/* CONTACT FORM check boxes */

function checkTextBoxes() {
	var naam, telefoon, email, bericht, error_color;
	error_color = "#ECDBC8";
	ok_color = "#FFFFFF";
	
	naam = document.getElementById("ctl00_contentHolder_txtNaam").value;
	telefoon = document.getElementById("ctl00_contentHolder_txtTelefoon").value;
	email = document.getElementById("ctl00_contentHolder_txtEmail").value;
	bericht = document.getElementById("ctl00_contentHolder_txtBericht").value;
	
	if ((naam.length < 1) || (telefoon.length < 9) || (bericht < 1) || (email < 1)) {
		
		if (naam.length < 1) {
			window.document.getElementById("ctl00_contentHolder_txtNaam").style.backgroundColor = error_color;    
		}
		else {
			window.document.getElementById("ctl00_contentHolder_txtNaam").style.backgroundColor = ok_color;
		}
		
		if (telefoon.length < 1) {
			window.document.getElementById("ctl00_contentHolder_txtTelefoon").style.backgroundColor = error_color;
			window.document.getElementById("rqrTelefoon").innerHTML = "(*)";
		}
		else {
		    if (telefoon.length < 9) {
		        window.document.getElementById("ctl00_contentHolder_txtTelefoon").style.backgroundColor = error_color;
		        window.document.getElementById("rqrTelefoon").innerHTML = "ongeldig";
		    }
		    else {
		        window.document.getElementById("ctl00_contentHolder_txtTelefoon").style.backgroundColor = ok_color;
		        window.document.getElementById("rqrTelefoon").innerHTML = "(*)";
		    }
		}
		
		if (email.length < 1) {
			window.document.getElementById("ctl00_contentHolder_txtEmail").style.backgroundColor = error_color;
			window.document.getElementById("rqrEmail").innerHTML = "(*)";
		}
		else {
			if (validateEmail(email)) {
				window.document.getElementById("ctl00_contentHolder_txtEmail").style.backgroundColor = ok_color;
				window.document.getElementById("rqrEmail").innerHTML = "(*)";
			}
			else {
				window.document.getElementById("ctl00_contentHolder_txtEmail").style.backgroundColor = error_color;
				window.document.getElementById("rqrEmail").innerHTML = "ongeldig";
			}
		}
		
		if (bericht.length < 1) {
			window.document.getElementById("ctl00_contentHolder_txtBericht").style.backgroundColor = error_color;
		}
		else {
			window.document.getElementById("ctl00_contentHolder_txtBericht").style.backgroundColor = ok_color;
		}
		
		return false;
	}
	else {
		window.document.getElementById("ctl00_contentHolder_txtNaam").style.backgroundColor = ok_color;
		window.document.getElementById("ctl00_contentHolder_txtTelefoon").style.backgroundColor = ok_color;
		window.document.getElementById("ctl00_contentHolder_txtEmail").style.backgroundColor = ok_color;
		window.document.getElementById("ctl00_contentHolder_txtBericht").style.backgroundColor = ok_color;
		
		if (validateEmail(email)) {
			return true;
		}
		else {
			window.document.getElementById("ctl00_contentHolder_txtEmail").style.backgroundColor = error_color;
			window.document.getElementById("rqrEmail").innerHTML = "ongeldig.";
						
			return false;
		}
	}
}

function validateEmail(strEmail) {
	//var strEmail = document.getElementById("txtEmail").value;
   
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
    var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
   
  	if (!reg1.test(strEmail) && reg2.test(strEmail)) { // if syntax is valid
    	return true;
  	}
  	
	//window.document.getElementById("txtEmail").style.backgroundColor = error_color;
	  	  
 	return false;
}




