function alertWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}


function alertHeight() {
  myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}


function getWidth() { 
	this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
	return(pageX);
}


function getHeight() { 
	this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
	return(pageY);
}

function getH() {
var windowWidth;
var windowHeight;

if(window.addEventListener) {
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
}
else {
windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
}
return windowHeight;
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll;
}

















// Functions checks if all fields in a form is filled out
function checkForm() {

	var d = document.kontakt;
	var ok = false;

	//Check navn
	if (stringEmpty(d.navn.value)) {
		alert("Feltet \"Navn\" er tomt!");
		d.navn.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	//Check adresse
	if (stringEmpty(d.adresse.value)) {
		alert("Feltet \"Adresse\" er tomt!");
		d.adresse.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	//Check postnummer
	if (stringEmpty(d.postnummer.value)) {
		alert("Feltet \"Postnummer\" er tomt!");
		d.postnummer.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	//Check poststed
	if (stringEmpty(d.poststed.value)) {
		alert("Feltet \"Poststed\" er tomt!");
		d.poststed.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	//Check telefon
	if (stringEmpty(d.telefon.value)) {
		alert("Feltet \"Telefon\" er tomt!");
		d.telefon.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	//Check epost
	if (stringEmpty(d.epost.value)) {
		alert("Feltet \"E-post\" er tomt!");
		d.epost.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	// Check for a valid email address
	if (!checkValidation(d.epost)) {
		d.epost.focus();
		return false;
		exit(0);
	} else {
		ok = true;
	}

	// Check melding
	if (stringEmpty(d.melding.value)) {
		alert("Feltet \"Melding\" er tomt!");
		d.melding.focus();
		return false;
		exit(0);
	}

	return true;

}



function checkValid (formField) {
    if ( checkValidation ( formField ) == true ) {
        alert ( 'E-Mail Address Validates OK' );
    }

    return ( false );
}

function stringEmpty (formField) {
    // CHECK THAT THE STRING IS NOT EMPTY
    if ( formField.length < 1 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function noAtSign (formField) {
    // CHECK THAT THERE IS AN '@' CHARACTER IN THE STRING
    if (formField.indexOf ('@', 0) == -1) {
        return ( true )
    } else {
        return ( false );
    }
}

function nothingBeforeAt (formField) {
    // CHECK THERE IS AT LEAST ONE CHARACTER BEFORE THE '@' CHARACTER
    if ( formField.indexOf ( '@', 0 ) < 1 ) {
        return ( true )
    } else {
        return ( false );
    }
}

function noValidPeriod (formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf ( '@', 0 ) > 1 && formField.charAt (formField.length - 1 ) == ']')
        return ( false );

    // CHECK THAT THERE IS AT LEAST ONE PERIOD IN THE STRING
    if (formField.indexOf ( '.', 0 ) == -1)
        return ( true );

    return ( false );
}

function noValidSuffix(formField) {
    // IF EMAIL ADDRESS IN FORM 'user@[255,255,255,0]', THEN WE ARE NOT INTERESTED
    if (formField.indexOf('@', 0) > 1 && formField.charAt(formField.length - 1) == ']') {
        return ( false );
    }

    // CHECK THAT THERE IS A TWO OR THREE CHARACTER SUFFIX AFTER THE LAST PERIOD
    var len = formField.length;
    var pos = formField.lastIndexOf ( '.', len - 1 ) + 1;
    if ( ( len - pos ) < 2 || ( len - pos ) > 4 ) {
        return ( true );
    } else {
        return ( false );
    }
}

function checkValidation(formInput) {

    if (typeof(formInput) != "object") {
        alert("Validation not supported on this browser.");
        return(false);
    }

    var message;

    if (noAtSign( formInput.value )) {
        message = "E-post (" + formInput.value + ") mangler '@'-tegnet.";
        alert(message);
    } else if (nothingBeforeAt(formInput.value)) {
        message = "E-post (" + formInput.value;
        message += ") mangler tegn foran '@'-tegnet.";
        alert(message);
    } else if (noValidPeriod(formInput.value)) {
        message = "E-post (" + formInput.value + ") skal inneholde punktum ('.').";
        alert(message);
    } else if (noValidSuffix(formInput.value)) {
        message = "E-post (" + formInput.value;
        message += ") mangler to eller tre tegns suffix.";
        alert(message);
    } else {
        return true;
        exit(0);
    }

    var objType = typeof(formInput.focus);
    if (objType == "object" || objType == "function") {
         formInput.focus();
    }

    return (false);
}








