
if((formular == "catalog_request") || (formular == "watch_registration")) {
	var contactm = 'post';

} else {
	var contactm = 'email';

}




var countrygroup = null;

var emailLabel =getLabelText(lang, 'email');
if(formular == 'user_request'){
	emailLabel += "*";
}

var contactDataPanel = null;
Ext.onReady(function(){
	
	var test = null;
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.QuickTips.init();
	
	
	//statecombo.setVisible(false);
	
     contactDataPanel = new Ext.form.FormPanel({
    	id: 'form_main',
        labelAlign: 'top',
        frame:true,
        name: 'contact_form',
		width: 717,
		border: false,
		renderTo: Ext.get('form-main'),
		layout: 'form',
		
	
        items: [ 
				
	        	new Ext.XTemplate(
	        	'<p class=\'text-top\'>'+getLabelText(lang, 'contact_data')+'<p/>',
				'<div class=\'lineSpacer\'><img src=\'images/1x1_trans.gif\' height=\'1\' width=\'1\' border=\'0\'></div>'
							
	        	),
				
        		new Ext.form.ComboBox({
				    	fieldLabel: getLabelText(lang, 'country')+ '*',
				    	labelSeparator: '',
					    displayField: 'country',
						valueField: 'id',
						name: 'country',
					    mode: 'local',
						editable: false,
					    triggerAction: 'all',
						id:'countryAdressData',
					    //emptyText:getLabelText(lang, 'waehlen'),
					    selectOnFocus: true,
					    border: true,
						width: 413,
						listWidth: 413,
						allowBlank: false,
                    	msgTarget:'under',
						blankText:getLabelText(lang, 'country_validation'),
						
				    	store: new Ext.data.SimpleStore({
				    		
						    fields: [
						     {name: 'id'},
						     {name: 'country', type:'string'},
						     {name: 'group'},
						     {name:'kurzel'}
						    ],
							forceSelection: true,
						    data : countryStore[lang],
						   // sortInfo: { field: "country", direction: "ASC" },
						    autoLoad:true
						    
						        
						    
						}),
						
						listeners: {
						//  select : ( Ext.form.ComboBox combo, Ext.data.Record record, Number index )  
		                select: function(f, n, o){
		                		disableErrordisclaimerField();
		                		disableErrorIndication();
		                		var group = n.get('group');
		                		
			                	if(group =='1-0'){
			                		countrygroup = '1-0';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			
			              						              			
			                	}
			                	if(group =='1-1'){
			                		countrygroup = '1-1';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			
			              			
			                	}
			                	if(group =='2'){
			                		countrygroup = '2';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			
			                	}
			                	if(group =='3'){
			                		countrygroup = '3';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              		
			              			
			                	}
			                	if(group =='5'){
			                		countrygroup = '5';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			
			              			
			                	}
			                	if(group =='9'){
			                		countrygroup = '9';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			
			              			
			                	}
			                	
			                	if(group =='6'){
			                		countrygroup = '6';
			              			insertFields(countrygroup);
			              			errorcounter = 0;
			              			//disableErrordisclaimerField();
			                	}
			                	
			                	try {
			                		// only exists for watch-registration.html
			                		selectDisclaimerByCountryId(n.get('kurzel'));
			                		
			                	} catch(e) {
			                		// do nothing
			                		
			                	}
			                	
			                	initIframe();
		
		               	 	}

						}
						
        	}),
              
		
			{
            	
		        xtype:'textfield',
		        fieldLabel:getLabelText(lang, 'telefon'),
		        labelSeparator: '',
		        name: 'telefon',
		        id:'telefon',
				autoCreate : {tag: 'input', type: 'text', size: '24', maxlength: '30', autocomplete: 'off'},
		        width: 413
	   	 	},
	    	 {
		        xtype:'textfield',
		        fieldLabel:emailLabel,
		        labelSeparator: '',
		        name: 'email',
		        id:'email',
		        vtype:'emailux',
		        //allowBlank: false,
		        //emailMask:'/[a-z0-9_\.\-@]/i/-',
	            msgTarget:'under',
	            emailuxText:getLabelText(lang, 'erroremail'),
				autoCreate : {tag: 'input', type: 'text', size: '20', maxlength: '200', autocomplete: 'off'},
				//blankText:getLabelText(lang, 'erroremail'),
		       
		        width: 413
	   		 },
	    
	   		 {
				xtype:'ux-radiogroup',
	            fieldLabel:getLabelText(lang, 'contact-medium'),
	            name:'contactMedium',
	            labelSeparator: '',
				horizontal: true,
				id:'contactMedium',
				width: 220,
				cls:'checkbox-small',
				ctCls: 'nospace',
	            items:[{
						inputValue:"post",
						boxLabel: getLabelText(lang, 'contact_post'),
						name: 'contactMedium-auto',
						width:'90px',
						checked: (formular == "user_request"?false:true),
						listeners:{'check':function(r,c){
							if(c ==true){
									contactm = "post";
								}
							}
						}
						
					}, {
						inputValue:"email",
						name: 'contactMedium-auto',
						width:'90px',
						checked:(formular == "user_request"?true:false),
						boxLabel: getLabelText(lang, 'contact_email'),
						listeners:{'check':function(r,c){
							if(c ==true){
									contactm = "email";
								}
							}
						}
					},
					{
						inputValue:'telefon',
						name: 'contactMedium-auto',
						width:'90px',
						boxLabel: getLabelText(lang, 'contact_telefon'),
						listeners:{'check':function(r,c){
							if(c ==true){
									contactm = "telefon";
								}
							
							}
							
						}
					}
				]
			},

	 new Ext.XTemplate(
    	
    		'<p class=\'x-form-item-label\'>'+getLabelText(lang, 'birthday')+'<p/>'
		
    	),
	
		{

	 		items: [displayCalender('calendar_birthday', true, lang, 'form-main')]
		},
       		
		 {
			xtype:'ux-radiogroup',
            fieldLabel: getLabelText(lang, 'newsletter_text'),
            name:'newsletterRb',
			horizontal: true,
			//cls:'newsletter_Text',
			labelSeparator: '',
			id:'newsletter_text',
			cls:'checkbox-small',
			ctCls: 'nospace',
			width: 110,
            items:[{
				inputValue:'on',
				boxLabel: getLabelText(lang, 'agreement_yes'),
				
				name: 'newsletterRb-auto',
				checked:true
			},
			{
				inputValue:'',
				name: 'newsletterRb-auto',
				boxLabel: getLabelText(lang, 'agreement_no')
			}]
		},
	        {
			 
            layout: 'column',
            id:'disclaimer_box',
            bodyStyle: 'padding:0 0 20px 0;',
	        width: 717,
	        //height:80,
	                items: [{
			    	layout: 'form',
			    	//columnWidth:.02,
			    	width:15,
			    	id:'parent_disclaimer_div',
			    	height:70,
			    	style: 'padding-bottom: 0px;',
			    	items: [
					    	new Ext.form.Checkbox({
							hideLabel: true,
							name: 'disclaimer',
							labelSeparator: '',
							id:'disclaimer',
							//itemCls :'disclaimer_transparent',
							boxLabel:''
						 
						})
					]
				    }, {
				    	layout: 'form',
				    	id: 'disclaimer_text_cmp',
				    	//columnWidth:.53,
				    	width:400,
				    	//height:105,
				    	items: [
						    new Ext.XTemplate(
		        				'<div id="disclaimer_text">'+ getLabelText(lang, 'agreement_text')+'</div>'			
		       				 )
						]
				    },
				     {
				    	layout: 'form',
				    	//columnWidth:.45,
				    	width:265,
				    	height:105,
				    	items: [
						    new Ext.XTemplate(
		        				'<div id="error_disclaimer_text"></div>'		
		       				 )
						]
				    }
				    ]
            
				}
	       
	        ],
	        
   
	
		buttonAlign:'left',
		id:'send_button',
		name:'send_button',
		
        buttons: [
        		
          		send = new Ext.Button(
	                {
	                	fieldLabel:'',
	                	 text:'',
	                	 //icon:'../images/send_'+lang+'.gif',
	                	 cls:'send_button_'+lang,
	                	 
	                 	handler:function(){
	                 		contactDataPanel.getForm().items.each(function(f) {
	                 			//alert(f.getId() + ": " + f.getValue());
	                 			//alert(watchData.getForm().getValues(true).replace(/&/g,', '));
	                 			//alert(checkboxenPanel.getForm().getValues(true).replace(/&/g,', '));
	                 			//alert(contactDataPanel.getForm().getValues(true).replace(/&/g,', ')+ ' disclaimer:' +Ext.getCmp('disclaimer').getValue());
	                 			//alert(Ext.getCmp('mediacode').getValue());
	                 		});
	                 		
							//window.location.href = "confirm-"+formular+".html";
	                 		validate();
	                 		

	                 	},
	                 	scope: this
	                	/* handler: function(){
	                	 	validate();
			               if(contactDataPanel.getForm().isValid()){
			                    Ext.Msg.alert('Submitted Values', ': <br />'+ 
			                        contactDataPanel.getForm().getValues(true).replace(/&/g,', ')+ ' disclaimer:' +Ext.getCmp('disclaimer').getValue());
			                }
			                
			            }*/
	                 	
	                 }
             
               	)
        ]
    });
	/*
	// Useragent holen
	var userAgent = navigator.userAgent;
	//alert(navigator.appCodeName);
	
	// f�r IE
	if(userAgent.indexOf('MSIE') > -1){
		language = navigator.browserLanguage;
		
		if(language.indexOf( 'de') > -1){
			lang = 'de';
			Ext.getCmp('country').setValue('Deutschland');
			countrygroup = '1-0';
		    insertFields(countrygroup);
		}
		
		if(language.indexOf( 'en') > -1){
			lang = 'en';
			Ext.getCmp('country').setValue('USA');
			countrygroup = '3';
		    insertFields(countrygroup);
		}
	}
	// f�r FF
	if(userAgent.indexOf('Firefox') > -1){
		language = navigator.language;
		if(language.indexOf( 'de') > -1){v
		
			lang = 'de';
			Ext.getCmp('country').setValue('Deutschland');
			countrygroup = '1-0';
		    insertFields(countrygroup);
		}
		if(language.indexOf( 'en') > -1){
		
			lang = 'en';
			
			Ext.getCmp('country').setValue('USA');
			countrygroup = '3';
			insertFields(countrygroup);
		}
	}
	*/
  
   	/*
	function getPosition(obj) {
  	var pos = { x:0, y:0 };

	  do {
	    pos.x += obj.offsetLeft;
	    pos.y += obj.offsetTop;
	  } while (obj = obj.offsetParent);
	
	  return pos;
	}

	var test =document.getElementById('x-form-el-disclaimer').parentNode;
	test.style.width = '20px';
	
	//var posLeft = document.getElementById('x-form-el-disclaimer').offsetLeft();
	//var posTop = document.getElementById('x-form-el-disclaimer').offsetTop();
	//alert(pos);
	var pos = getPosition(document.getElementById('x-form-el-disclaimer').parentNode);
	var left = pos.x;
	var top = pos.y;
	
	var text = document.getElementById('disclaimer_text').parentNode.parentNode.parentNode;
	text.style.width='400px';
	text.style.position = 'absolute';
	
    text.style.top=top;
    text.style.left=left;
    */
 
    
	/*if(lang == "de"){
		
		Ext.getCmp('countryAdressData').setValue(getCountryValue(lang,'germany'));
		countrygroup = '1-0';
		insertFields(countrygroup);
		
	}
	if(lang == "en"){
		lang = 'en';
			Ext.getCmp('countryAdressData').setValue(getCountryValue(lang,'usa'));
			countrygroup = '3';
		    insertFields(countrygroup);
		
	}
	if(lang == "jn"){
			lang = 'jn';
			Ext.getCmp('countryAdressData').setValue(getCountryValue(lang,'japan'));
			countrygroup = '5';
		    insertFields(countrygroup);
		
	}
	if(lang == "cn"){
			lang = 'cn';	
			Ext.getCmp('countryAdressData').setValue(getCountryValue(lang,'china'));
			countrygroup = '9';
		    insertFields(countrygroup);
		
	}
	*/
	
	
	if(Ext.form.VTypes){
		   Ext.apply(Ext.form.VTypes, {
		      emailText    : getLabelText(lang, 'erroremail')
		      //urlText      : ln_i18n[lang]["ext"]["VT_urlText"],
		      //alphaText    : ln_i18n[lang]["ext"]["VT_alphaText"],
		      //alphanumText : ln_i18n[lang]["ext"]["VT_alphanumText"]
		   });
		}
		
	Ext.getCmp('calendar_birthdayday').setValue(getLabelText(lang, 'day'));
	Ext.getCmp('calendar_birthdaymonth').setValue(getLabelText(lang, 'month'));
	Ext.getCmp('calendar_birthdayyear').setValue(getLabelText(lang, 'year'));
	
	if(Ext.getCmp('purchasedateday')){
		Ext.getCmp('purchasedateday').setValue(getLabelText(lang, 'day'));
	}
	if(Ext.getCmp('purchasedatemonth')){
		Ext.getCmp('purchasedatemonth').setValue(getLabelText(lang, 'month'));
	}
	if(Ext.getCmp('purchasedateyear')){
		Ext.getCmp('purchasedateyear').setValue(getLabelText(lang, 'year'));
	}
	
	var countryId;
	
	formService.getLastAddressData(function(data) {
	 	if(data != null){
	 		
	 		// Country Combo
	 		var stateId = data.stateId;
	 		countryId = data.countryId;
	 		
	 		if(data.countryId == null) {
	 			countryId = data.country;

	 		}

	 		if(data.stateId == null){
	 			stateId = data.state;
	 		}
	 		Ext.getCmp('countryAdressData').setValue(countryId);
	 		var group = getGroup(countryId,lang);
	 		countrygroup = group;
			insertFields(countrygroup);
			errorcounter = 0;
	 		
	 		//State Combo
			var countryKey =  getCountryKey(countryId,lang);
			if(countryKey == 'US'){
				if(stateId != null || stateId != ""){
	 				Ext.getCmp('state').setValue(stateId);
	 			}
			}else if(countryKey == 'JP'){
				if(stateId != null){
	 				Ext.getCmp('prefecture').setValue(stateId);
	 			}
	 		}else if(countryKey == 'IT'){
				if(stateId != null){
	 				Ext.getCmp('province').setValue(stateId);
	 			}
	 		}
			
	 		
	 		if(data.firstname != null || data.firstname != ""){
	 			Ext.getCmp('firstname').setValue(data.firstname);
	 		}
	 		if(data.lastname != null || data.lastname != ""){
	 			Ext.getCmp('lastname').setValue(data.lastname);
	 		}
	 		if(data.street != null || data.street != ""){
	 			Ext.getCmp('street').setValue(data.street);
	 		}
	 		if(data.additionalAddress != null || data.additionalAddress != ""){
	 			Ext.getCmp('additionalAdressData').setValue(data.additionalAddress);
	 		}
	 		
	 		if(data.salutation !=null){
	 			Ext.getCmp('salutation').setValue(data.salutation);
	 			if(data.salutation == getLabelText(lang, 'satlutation_mr')){
	 				Ext.getCmp('salutation').setValue(1);
	 			}
	 			if(data.salutation == getLabelText(lang, 'satlutation_ms')){
	 				Ext.getCmp('salutation').setValue(2);
	 			}
	 			if(data.salutation == getLabelText(lang, 'satlutation_mr_ms')){
	 				Ext.getCmp('salutation').setValue(3);
	 			}
	 			//Ext.getCmp('salutation').setValue(data.salutation);
	 		}
	 	
	 		Ext.getCmp('title').setValue(data.title);
	 		
	 		if(data.city != null){
	 			Ext.getCmp('city').setValue(data.city);
	 		}
	 		
	 		if(data.streetNo != null || data.streetNo != ""){
	 			Ext.getCmp('housenumber').setValue(data.streetNo);
	 		}
	 		
	 		if(data.zip != null || data.zip != ""){
	 			Ext.getCmp('plz').setValue(data.zip);
	 		}
	 		if(data.phone != null || data.phone != ""){
	 			Ext.getCmp('telefon').setValue(data.phone);
	 		}
	 		if(data.email != null || data.email != ""){
	 			Ext.getCmp('email').setValue(data.email);
	 		}
	 		
	 		
	 		
	 		if(data.dayOfBirth != null && data.dayOfBirth == 0 ){
	 			Ext.getCmp('calendar_birthdayday').setValue(getLabelText(lang, 'day'));
	 		}
	 		else if(data.dayOfBirth != null && data.dayOfBirth != 0 ){
	 			Ext.getCmp('calendar_birthdayday').setValue(data.dayOfBirth);
	 		}
	 		
	 		if(data.monthOfBirth != null && data.monthOfBirth == 0 ){
	 			Ext.getCmp('calendar_birthdaymonth').setValue(getLabelText(lang, 'month'));
	 		}
	 		else if(data.monthOfBirth != null && data.monthOfBirth != 0 ){
	 			Ext.getCmp('calendar_birthdaymonth').setValue(data.monthOfBirth);
	 		}
	 		
	 		if(data.yearOfBirth != null && data.yearOfBirth == 0 ){
	 			Ext.getCmp('calendar_birthdayyear').setValue(getLabelText(lang, 'year'));
	 		}
	 		else if(data.yearOfBirth != null && data.yearOfBirth != 0 ){
	 			Ext.getCmp('calendar_birthdayyear').setValue(data.yearOfBirth);
	 		}
	 		
	 		if(data.contactMode !=null){
	 			Ext.getCmp('contactMedium').setValue(data.contactMode);
	 		}
	 		
	 		if(data.newsletter != null){
	 			Ext.getCmp('newsletter_text').setValue(data.newsletter);
	 		}
	 		
	 		if(data.lastname2 != null){
	 			Ext.getCmp('lastname2').setValue(data.lastname2);
	 		}
	 		
	 		if(data.address1 != null){
	 			Ext.getCmp('adress1').setValue(data.address1);
	 		}
	 		
	 		if(data.address2 != null){
	 			Ext.getCmp('adress2').setValue(data.address2);
	 		}
	 		if(data.address3 != null){
	 			Ext.getCmp('adress3').setValue(data.address3);
	 		}
	 		
	 		try {
				selectDisclaimerByCountryId(countryId);
			} catch(e) {
				// do nothing
			}
	 		
	 	}
	
	 });
	Ext.getCmp('countryAdressData').setValue(getCountryGroup()[0]);
	
	countrygroup = getCountryGroup()[1];
	insertFields(countrygroup);
    
	initIframe();
	
	
	Ext.apply(Ext.form.VTypes, {
        
         'emailux' : function(v) {
         	var email = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
         	return email.test(v);
         },
       
        'emailuxText' : getLabelText(lang, 'erroremail')
        
	}); 
	
   });

