/* document.getElementById("first_name").maxLength = 130;
document.getElementById("last_name").maxLength = 130;
document.getElementById("email_address").maxLength = 64;
document.getElementById("email_address_verify").maxLength = 64;
document.getElementById("address1").maxLength = 600;
document.getElementById("address2").maxLength = 600;
if(typeof(eval(document.getElementById("city")))!= "undefined"){
	document.getElementById("city").maxLength = 80;
}
document.getElementById("country").maxLength = 40;
document.getElementById("postal_code").maxLength = 20;
document.getElementById("phone2").maxLength = 30;
*/
var title = document.contactus.title?document.contactus.title:null;
//var title = document.contactus.title;
var first_name = document.contactus.first_name;
var last_name = document.contactus.last_name;
var email_address = document.contactus.email_address;
var email_address_verify = document.contactus.email_address_verify;
var address1 = document.contactus.address1;
var address2 = document.contactus.address2;
var city = document.contactus.city;
var country = document.contactus.country;
var postal_code = document.contactus.postal_code;
var phone2 = document.contactus.phone2;
var comments = document.contactus.comments;
var checkId;

function display(obj,maxlength){
	var txt = obj.value;
	
	
	s = txt;
	if(s.length == 0) obj.maxLength = 1000;
	var totalLength = 0;
	var i;
	var charCode;
	for (i = 0; i < s.length; i++) {
	charCode = s.charCodeAt(i);
	if (charCode < 0x007f) {
	totalLength = totalLength + 1;
	
	} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
	totalLength += 2;
	
	} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
	totalLength += 3;

	}
	
	if(totalLength > maxlength){
		obj.maxLength = i;
		obj.value = obj.value.substring(0,i);
		obj.focus();
		return;
	}
	}
}

if(typeof(eval(document.contactus.title))!= "undefined"){

title.onchange = function(){
	display(title,30);
	clearInterval(checkId);
}
title.onfocus = function(){ 
	checkId = setInterval(function(){display(title,30);},200);	
}

}

if(typeof(eval(document.contactus.first_name))!= "undefined"){

first_name.onchange = function(){
	display(first_name,130);
	clearInterval(checkId);
}
first_name.onfocus = function(){ 
	checkId = setInterval(function(){display(first_name,130);},200);	
}

}

if(typeof(eval(document.contactus.last_name))!= "undefined"){
last_name.onchange = function(){
	display(last_name,130);
	clearInterval(checkId);
}
last_name.onfocus = function(){ 
	checkId = setInterval(function(){display(last_name,130);},200);	
}

}

if(typeof(eval(document.contactus.email_address))!= "undefined"){
email_address.onchange = function(){
	display(email_address,64);
	clearInterval(checkId);
}
email_address.onfocus = function(){ 
	checkId = setInterval(function(){display(email_address,80);},200);	
}
}



if(typeof(eval(document.contactus.email_address_verify))!= "undefined"){
email_address_verify.onchange = function(){
	display(email_address_verify,64);
	clearInterval(checkId);
}
email_address_verify.onfocus = function(){ 
	checkId = setInterval(function(){display(email_address_verify,80);},200);	
}

}


if(typeof(eval(document.contactus.address1))!= "undefined"){

address1.onchange = function(){
	display(address1,600);
	clearInterval(checkId);
}
address1.onfocus = function(){ 
	checkId = setInterval(function(){display(address1,130);},200);	
}

}
if(typeof(eval(document.contactus.address2))!= "undefined"){

address2.onchange = function(){
	display(address2,600);
	clearInterval(checkId);
}
address2.onfocus = function(){ 
	checkId = setInterval(function(){display(address2,130);},200);	
}

}
if(typeof(eval(document.contactus.city))!= "undefined"){
city.onchange = function(){
	display(city,80);
	clearInterval(checkId);
}
city.onfocus = function(){ 
	checkId = setInterval(function(){display(city,80);},200);	
}
}
if(typeof(eval(document.contactus.country))!= "undefined"){

country.onchange = function(){
	display(country,40);
	clearInterval(checkId);
}
country.onfocus = function(){ 
	checkId = setInterval(function(){display(country,40);},200);	
}
}
if(typeof(eval(document.contactus.postal_code))!= "undefined"){

if(document.contactus.brand_name.value == "Origins Germany"){
        document.contactus.postal_code.maxLength = 5;
	postal_code.onchange = function(){
		var post_code = document.contactus.postal_code.value;
	//	alert(post_code);

	}
}else{

	postal_code.onchange = function(){
		display(postal_code,20);
		clearInterval(checkId);
	}
	postal_code.onfocus = function(){ 
		checkId = setInterval(function(){display(postal_code,20);},200);	
	}
   }

}

if(typeof(eval(document.contactus.phone2))!= "undefined"){

phone2.onchange = function(){
	display(phone2,30);
	clearInterval(checkId);
}
phone2.onfocus = function(){ 
	checkId = setInterval(function(){display(phone2,30);},200);	
}
}
if(typeof(eval(document.contactus.comments))!= "undefined"){

comments.onchange = function(){
	display(comments,5000);
	clearInterval(checkId);
}
comments.onfocus = function(){ 
	checkId = setInterval(function(){display(comments,5000);},200);	
}
}

