﻿	function checkEmail() {
		var strEmail = reg_form.email.value;
		if (strEmail == "") {
			window.alert("Vinsamlegast sláið inn netfang");
			reg_form.email.focus();
			return false;
		}
		if (strEmail.indexOf("@") == -1) {
			window.alert("Netfang rangt");
			reg_form.email.select();
			reg_form.email.focus();
			return false;
		}
		if (strEmail.indexOf(".") == -1) {
			window.alert("Netfang rangt");
			reg_form.email.select();
			reg_form.email.focus();
			return false;
		}
		return true;
	}

	function checkPassword() {
		var strPass1 = reg_form.password1.value;
		var strPass2 = reg_form.password2.value;
		if (strPass1.indexOf(" ") != -1) {
			window.alert("Ekki má hafa bil í lykilorði");
			reg_form.password1.select();
			reg_form.password1.focus();
			return false;
		}
		if (strPass1.length < 6) {
			window.alert("Lykilorðið þitt þarf að vera 6 stafir hið minnsta");
			reg_form.password1.select();
			reg_form.password1.focus();
			return false;
		}
		if (strPass1 != strPass2) {
			window.alert("Lykilorðið sem þú slóst inn í \"Staðfesta lykilorð\" er ekki það sama og \"Lykilorð\"");
			reg_form.password1.select();
			reg_form.password1.focus();
			return false;
		}
		return true;
	}

	function checkUserName() {
		if (reg_form.user_name.value == "") {
			window.alert("Sláðu inn notendanafn");
			reg_form.user_name.select();
			return false;
		}
		return true;
	}

	function checkSSN() {
		if (reg_form.ssn.value == "") {
			window.alert("Please enter your social security number");
			reg_form.ssn.select();
			return false;
		}
		return true;
	}

	function checkTitle() {
		if (reg_form.title.value == "") {
			window.alert("Please enter your title");
			reg_form.title.select();
			return false;
		}
		return true;
	}

	function checkFirstName() {
		if (reg_form.first_name.value == "") {
			window.alert("Sláið inn fornafn");
			reg_form.first_name.select();
			return false;
		}
		return true;
	}

	function checkLastName() {
		if (reg_form.last_name.value == "") {
			window.alert("Sláið inn eftirnafn");
			reg_form.last_name.select();
			return false;
		}
		return true;
	}

	function checkGender() {
		if (reg_form.gender.options[reg_form.gender.selectedIndex].value == "") {
			window.alert("Vinsamlegast tilgreindu kyn");
			return false;
		}
		return true;
	}

	function checkAge() {
		if (reg_form.age.value == "") {
			window.alert("Vinsamlegast sláðu inn aldur");
			reg_form.age.select();
			return false;
		}
		return true;
	}

	function checkMaritalStatus() {
		if (reg_form.marital_status.options[reg_form.marital_status.selectedIndex].value == "") {
			window.alert("Vinsamlegast tilgreinið hjúskaparstöu");
			return false;
		}
		return true;
	}

	function checkCompanyName() {
		if (reg_form.company_name.value == "") {
			window.alert("Vinsamlegast tilgreinið fyrirtæki");
			reg_form.company_name.select();
			return false;
		}
		return true;
	}

	function checkOccupation() {
		if (reg_form.occupation.options[reg_form.occupation.selectedIndex].value == "") {
			window.alert("Tilgreindu stöðu");
			return false;
		}
		return true;
	}

	function checkCountry() {
		if (reg_form.country.options[reg_form.country.selectedIndex].value == "") {
			window.alert("Veldu land úr lista");
			return false;
		}
		return true;
	}

	function checkState() {
		if (reg_form.state.value == "") {
			window.alert("Please enter your state / province");
			reg_form.state.select();
			return false;
		}
		return true;
	}

	function checkCity() {
		if (reg_form.city.value == "") {
			window.alert("Sláðu inn borg");
			reg_form.city.select();
			return false;
		}
		return true;
	}

	function checkZip() {
		if (reg_form.zip.value == "") {
			window.alert("Sláðu inn póstnúmer");
			reg_form.zip.select();
			return false;
		}
		return true;
	}

	function checkAddress() {
		if (reg_form.address.value == "") {
			window.alert("Sláðu inn heimilisfang");
			reg_form.address.select();
			return false;
		}
		return true;
	}

	function checkPhone() {
		if (reg_form.phone.value == "") {
			window.alert("Vinsamlegast sláðu inn símanúmer");
			reg_form.phone.select();
			return false;
		}
		return true;
	}

	function checkMobile() {
		if (reg_form.mobile.value == "") {
			window.alert("Vinsamlegast sláðu inn farsímanúmer");
			reg_form.mobile.select();
			return false;
		}
		return true;
	}

	function checkImage(blnRequired) {
		var strPath = reg_form.image.value;
		if (strPath == "" && blnRequired == true) {
			window.alert("Vinsamlegast veldu mynd");
			return false;
		}
		if (strPath != "") {
			var strPathLC = strPath.toLowerCase()
			if (strPathLC.slice(strPath.length - 4) == ".gif") {
				window.alert("Því miður getum við ekki tekið við myndum á gif formati. Vinsamlegast veldu annað format. ");
				return false;
			}
			if (strPathLC.slice(strPath.length - 4) == ".tif") {
				window.alert("Því miður getum við ekki tekið við myndum á tiff formati. Vinsamlegast veldu annað format.");
				return false;
			}
		}
		return true;
	}
/*	
	function checkCreditCardNumber() {
		var form = document.frmRegister;
		form.CardNumber.value = fixString(form.CardNumber.value);
		var sCardNumber = form.CardNumber.value;
		form.CardNumber.value = sCardNumber
		if( sCardNumber == "" ){
			alert("Vantar kreditkortanúmer");
			form.CardNumber.focus();
			return false;
		}
		if( sCardNumber.length < 16 ){
			alert("Vitlaus lengd á kreditkortanúmeri");
			form.CardNumber.focus();
			return false;
		}
		sCardNumber = check_ccn(sCardNumber);
		if( sCardNumber ){
			alert("Kreditkortanúmer ekki rétt");
			form.CardNumber.focus();
			return false;	
		}	
	
		// Declare regular expression
		var re = /[^0-9]/;

		// Check expiration date
		form.CardExpires.value = form.EXM.value + form.EXY.value;
		if (form.EXM.value == "") {
			alert("Mánuð vantar í gildistíma");
			form.EXM.focus();
			return false;
		}
		if (form.EXY.value == "") {
			alert("Ár vantar í gildistíma");
			form.EXY.focus();
			return false;
		}
		var strMonth = new String(form.EXM.value);
		var strYear = new String(form.EXY.value);
		if ((strMonth.search(re) != -1)) {

			// Non numerical symbols, alert the user
			alert("Ólöglegur gildistími");
			form.EXM.select();
			form.EXM.focus();
			return false;
		}
		if ((strYear.search(re) != -1)) {

			// Non numerical symbols, alert the user
			alert("Ólöglegur gildistími");
			form.EXY.select();
			form.EXY.focus();
			return false;
		}
		var intMonth = 0;
		if (strMonth.length == 1) {
			intMonth = parseInt(strMonth);
		}
		else {
			if (strMonth.substr(0, 1) == "0") {
				intMonth = parseInt(strMonth.substr(1, 1));
			}
			else {
				intMonth = parseInt(strMonth);
			}
		}
		if (intMonth > 12 || intMonth < 1) {
			alert("Ólöglegur gildistími");
			form.EXM.select();
			form.EXM.focus();
			return false;
		}
	
		// Fix the expiration date if needed
		if (strMonth.length == 1) {
			form.EXM.value = "0" + strMonth;
		}
		if (strYear.length == 1) {
			form.EXY.value = "0" + strYear;
		}
		return true;
	}
	
function check_ccn(ccn) {
	var i=ccn.length;
    var c,p,val;
    var str='';
    var res=0;
    var fac=0;
    while (i>0) {
	    c=ccn.substring(i-1,i);
	    p='0123456789'.indexOf(c)+1;
	    if (p>0) {
			str=c+str;
			fac=(fac%2)+1;
			val=c*fac;
			if (val<10) {
				res=res+val;
			} else {
				res=res+(val%10)+1;
			}
		}
		i=i-1;
	} 
    if (str.length!=16 || '45'.indexOf(str.substring(0,1))==-1 || res%10>0) {
		// Has error
		return true;
	} else {
		// No error
		return false;
	}
}
*/
function strip(n,s) {
                var lpos=0;
                var len=n.length;
                var res='';
                while (lpos<len) {
                        if (s.indexOf(n.charAt(lpos))!=-1) {
                                res+=n.charAt(lpos);
                        }
                        lpos++;
                }
                return(res);        
}
/*
function fixString(cardnumber){
	var fixed = new String();
	for(var i=0; i<cardnumber.length; i++){
		if( !isNaN(cardnumber.charAt(i)) ) fixed += cardnumber.charAt(i);
	}
	//alert(fixed + ", " + fixed.length);
	return fixed;
}
*/
