function $(id){return document.getElementById(id);}

function headTo(toPage)
{
	window.location = toPage;
}

function shiftBg(shiftTo, number, obj, what)
{
	if (what == 'six'){
		if (shiftTo == 'on'){
			obj.className  = 'sixlinebtnover ' + number + 'ofsix';
		} else {
			obj.className  = 'sixlinebtn ' + number + 'ofsix';
		}
	} else if (what == 'four'){
		if (shiftTo == 'on'){
			obj.className  = 'buttonfoursover';
		} else {
			obj.className  = 'buttonfours';
		}
	}
}

function replaceChar(tester)
{
	var _m = "[oe]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[oe]', '&oslash;');
	}
	var _m = "[ae]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[aa]', '&aring;');
	}
	var _m = "[ae]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[ae]', '&aelig;');
	}
	var _m = "[oe]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[oee]', '&Oslash;');
	}
	var _m = "[ae]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[aaa]', '&Aring;');
	}
	var _m = "[ae]"; // pattern to match.
	var _s = tester;
	var _c = 0; // count
	for (var i=0;i<_s.length;i++) {
		if (_m == _s.substr(i,_m.length))
			tester = tester.replace('[aee]', '&AElig;');
	}
}

function getURLParam(strParamName)
{
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (
			aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
			var aParam = aQueryString[iParam].split("=");
			strReturn = aParam[1];
			break;
			}
		}
	}
	return strReturn;
}

function checkForm()
{
	
	var theForm = $('theForm');
	var valid = true;
	if (getURLParam('id') == 0){
		if ($('firstnameForm').value == ""){
			valid = false;
		}
		if (($('areacodeForm').value != "" && isNumber($('areacodeForm').value)  && $('areacodeForm').value.length != 4) || ( $('areacodeForm').value != "" &&  !isNumber($('areacodeForm').value))){
			valid = false;
		}
		
		if ($('phoneForm').value == "" || !isNumber($('phoneForm').value)) {
			valid = false;
		}
		
		if ($('AddressForm').value == "" || $('AddressForm').value.length < 2) {
			valid = false;
		}
		
		if ($('districtForm').value == "" || $('districtForm').value.length < 2) {
			valid = false;
		}
	}
	
	if (getURLParam('id') == 2){
		if ($('firstnameForm').value == ""){
			valid = false;
		}
		if ($('lastnameForm').value == ""){
			valid = false;
		}
		if ($('positionForm').value == ""){
			valid = false;
		}
		if (($('areacodeForm').value != "" && isNumber($('areacodeForm').value)  && $('areacodeForm').value.length != 4) || ( $('areacodeForm').value != "" &&  !isNumber($('areacodeForm').value))){
			valid = false;
		}
		
		if ($('phoneForm').value == "" || !isNumber($('phoneForm').value)) {
			valid = false;
		}
	}
	
	if (getURLParam('id') == 4){
		if ($('firstnameForm').value == ""){
			valid = false;
		}
		if ($('lastnameForm').value == ""){
			valid = false;
		}
		if ($('AddressForm').value == ""){
			valid = false;
		}
		if ($('areacodeForm').value == "" || !isNumber($('areacodeForm').value) || (isNumber($('areacodeForm').value) && $('areacodeForm').value.length != 4)){
			valid = false;
		}
		if ($('districtForm').value == ""){
			valid = false;
		}
		if ($('phoneForm').value == "" || !isNumber($('phoneForm').value)) {
			valid = false;
		}
	}
	
	if (valid){
		$('forms').submit();
	} else {
		alert('Der var en fejl i din indtastning\nAlle felter med * skal udfyldes');
	}
}

function isNumber(check)
{
	var validChars = '0123456789';
	var isNumber = true;
	var Char;
	for (i = 0; i < check.length && isNumber == true; i++){
		Char = check.charAt(i);
		if (validChars.indexOf(Char) == -1){
			isNumber = false;
		}
	}
	return isNumber;
}

function showVideo(input)
{
	if (deconcept.SWFObjectUtil.getPlayerVersion().major < 8 || deconcept.SWFObjectUtil.getPlayerVersion() == ""){
		if (input == 'solhus'){
			$('video1').innerHTML = '<a href="http://adobe.com/go/getflash/"><img src="imgs/get_flash.gif" /></a>';
		} else if (input == 'meddo'){
			$('video2').innerHTML = '<a href="http://adobe.com/go/getflash/"><img src="imgs/get_flash.gif" /></a>';
		} else if (input == 'hapro'){
			$('video3').innerHTML = '<a href="http://adobe.com/go/getflash/"><img src="imgs/get_flash.gif" /></a>';
		}
	} else {
		if (input == 'solhus'){
			var so = new SWFObject("flash/solhus.swf", 'solhus', "260", "166", "8", "#ffffff");
			so.write("video1");
		} else if (input == 'meddo'){
			var so = new SWFObject("flash/meddo.swf", 'meddo', "260", "166", "8", "#ffffff");
			so.write("video2");
		} else if (input == 'hapro'){
			var so = new SWFObject("flash/hapro.swf", 'hapro', "260", "166", "8", "#ffffff");
			so.write("video3");
		}
	}
}