	/* 
		All Rights Reserved
	*/
	
function open_home() {
	 document.location='/index2.php';
}
function open_rates() {
	 document.location='/rates.php';
}
function open_mobilrates() {
	 document.location='/mobile_rates.php';
}
function open_rates_txt() {
	 window.open('/rates_printer.php','rates_txt','scrollbars=yes,status=no,menubar=yes,toolbar=yes,location=no,resizable=yes,width=700,height=550');
}
function open_signup() {
	 window.open('https://myaccount.finarea.ch/123/createuser','signup','scrollbars=yes,status=yes,resizable,width=710,height=550');
}
function open_customerlogin() {
	 window.open('https://myaccount.finarea.ch/123/','customerlogin','scrollbars=yes,status=yes,resizable,width=710,height=550');
}
function open_customerservice() {
	 window.open('/customerservice/','customerservice','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_unsubscribe() {
	 document.location='/contact.php';
}
function open_contact() {
	 document.location='/contact.php';
}
function open_sms() {
	 document.location='/sms.php';
}
function open_reportafault() {
	 document.location='/customerservices/customerserviceslogin.php';
}
function open_info() {
	 document.location='/info.php';
}
function open_faq() {
	 window.open('/customerservice/step1.php?type=general','faq','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_tellafriend() {
	 window.open('/tellafriend2.php','tellafriend','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_flyerservice() {
	 window.open('/flyerservice.php','flyerservice','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_cheapertelco() {
	 window.open('/cheapertelco.php','cheapertelco','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_tellfriends() {
	 window.open('/tellafriend2.php','tellfriends','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_termsofuse() {
	 window.open('/termsofuse.php','termsofuse','scrollbars=yes,status=no,menubar=yes,toolbar=yes,location=no,resizable=yes,width=700,height=550');
}
function open_termsconditions() {
	 window.open('/termsconditions.php','termsconditions','scrollbars=yes,status=no,menubar=yes,toolbar=yes,location=no,resizable=yes,width=700,height=550');
}
function open_pop_callcharges() {
	 window.open('/pop_tariffnotice.php','pop_callcharges','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_testimonial() {
	 window.open('/testimonial.php','testimonial','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_customerservicefault() {
	 window.open('http://www.1031telekom.at/customerservice/step3.php?type=general','customerservicefault','scrollbars=yes,status=no, resizable,width=670,height=550');
}
function open_tariffnotice() {
	 window.open('/info_tariffmessage.php','tariffnotice','scrollbars=no,status=no,resizable,width=350,height=400');
}
function open_comments() {
	 window.open('/info_comment.php','comments','scrollbars=no,status=no,resizable,width=350,height=400');
}
function open_privacy() {
	 document.location='/privacy.php';
}
		
	function checkForm() {
		var formElements = document.forms[0].elements;
		var formOK = true;
		var formElementOK = true;
		var name;
		var value;
		var type;
		var required;
		var i = 0;
		var msg = "";
		
		while (formOK && (i < formElements.length)) {
			name  = formElements[i].name;
     		value = formElements[i].value;
     		type  = "";
     		required = false;
			msg   = "";
			if (name.search("form_") != -1) {
				name = name.replace("/form_/g", "");
				
	     		if (name.search("opt_")  != -1) { type = "opt"; name = name.replace("/opt_/g",  "");  }
	     		if (name.search("sel_")  != -1) { 
     				type = "sel"; 
     				name = name.replace("/sel_/g",  "");  
     				value = "filled";
	     		}
	     		if (name.search("email") != -1) { type = "email"; }
	     		if (name.search("ANR")   != -1) { type = "phone"; }
	     		if (name.search("BNR")   != -1) { type = "number"; }
	     		if (name.search("cust")	 != -1) { type = "cust";  }
	
				if (name.search("required_") != -1) {
					name = name.replace("/required_/g", "");
					formElementOK = (value != '');
					msg = "Wichtig! Bitte füllen Sie mit * gekennzeichnet Felder aus. Ihre Email kann dadurch schneller bearbeiten werden.";
					required = true;
				}
				if (formElementOK) {
					switch (type) {
						case "number":
							formElementOK = isNumber(value);
							msg = "Die eingegebene Rufnummer ist falsch";
							break;
						case "email": 
							formElementOK = isEmail(value); 
							msg = "Die eingegebene Emailadresse ist falsch";
							break;
						case "phone": 
							document.forms[0].elements[i].value = formatPhone(value);
							value = document.forms[0].elements[i].value;
							formElementOK = isPhone(value);
							msg = "Die eingegebene Telefonnummer ist falsch";   
							break;
						case "opt":   
							formElementOK = optionChecked(formElements[i]); 
						   msg = "Bitte wählen Sie aus"; 
						   break;
						case "sel":
							if (required) {
								formElementOK = optionSelected(formElements[i]);
							} else {
								formElementOK = true;
							}
							msg = "Bitte wählen Sie aus";
							break;
						case "cust":
							formElementOK = (value.length == 9) || ((value.length == 0) && !required);
							msg = "Ihre Kundenummer besteht immer aus 9 Stellen. Falls Sie diese nicht zur Hand haben bzw. noch keine erahlten haben, lassen Sie das Feld leer)";
							break;
					}		
				}
				formOK = formOK && formElementOK;
			}
			i++;
	   }	   
	   if (!formOK) {
	   	alert(msg);
	   	formOK = false;
	   }
	   return formOK;
	}

	function isEmail(address) {
		var isValid = false;
		// basic checks (relying on lazy evaluation for correct behaviour!)
		// not empty
		// at least 7 characters (x@yy.zz)
		// has @
		// has only 1 @
		// has at least one . (domain.ext)
		isValid = (address!=null) 
		       && (address.length >= 7) 
		       && (address.indexOf('@')!=-1) 
		       && (address.indexOf('@') == address.lastIndexOf('@'))
		       && (address.indexOf('.')!=-1)
		;
		
		if (isValid) {
			var parts = address.split('@');
			var name  = parts[0].split('.');
			var host  = parts[1].split('.');
			var regName  = new RegExp("^([!#$%&'*+-/0-9=?A-Z^_a-z{}~]+)$"); // at least length 1
			var regLabel = new RegExp("^(^[-0-9A-Za-z][-0-9A-Za-z]+)$"); // at least length 2
			var regExt   = new RegExp("^([A-Za-z]{2,63})$"); // at least length 2
			var i;
			for (i=0; i < name.length; i++) {
				isValid = isValid && (name[i].search(regName) != -1);
			}
			for (i=0; i < host.length-1; i++) {
				isValid = isValid && (host[i].search(regLabel) != -1) && (host[i].length <= 63);
			}
			isValid = isValid && (host[host.length-1].search(regExt) != -1);
		}
		return isValid;
	}
	
	function isPhone(number) {
		return ( (number.length >= 9) && (number.length <= 17) && isNumber(number) );
	}
	
	function isNumber(testNumber){
	   var validChars = "0123456789";
	   var valid      = testNumber.length > 0;
		var i          = 0;
	   while (valid && (i < testNumber.length)) {
	      valid = (validChars.indexOf(testNumber.charAt(i)) != -1);
	      i++;
	   }
	   return valid;
	}	

	function optionChecked(field) {
		var checked;
		var i = 0;
		while (!checked && (i < document.forms[0].elements[field.name].length)) {
			checked = document.forms[0].elements[field.name][i].checked;
			i++;
		}
		return checked;	
	}
	
	function optionSelected(element) {
		return (element.selectedIndex != 0);
	}

	function formatPhone(number) {
	   var digits = "0123456789";
	   var digit;
	   var parsedNumber = "";
		var firstZeros = true;
		
		// parse out everything that's not a digit
	   for (i=0; i < number.length; i++) {
	      digit = number.charAt(i);
	      if (digits.indexOf(digit) != -1) {
        		parsedNumber += digit;
	      }
	   }
		if (parsedNumber.substr(0,4) == "1031") { parsedNumber = parsedNumber.substr(4); }
		if (parsedNumber.substr(0,4) == "00"+"43") { parsedNumber = parsedNumber.substr(4); }
		if (parsedNumber.substr(0,2) ==   "43") { parsedNumber = parsedNumber.substr(2); }	   
		while (parsedNumber.substr(0,1) == "0") { 
			parsedNumber = parsedNumber.substr(1); 
		}	   
		return "0043"+parsedNumber;
	}

		
