// Get Map Contact
function showMapContact(uID) {
		
	if (isDigit(uID)) {
		var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_right");
		resultHTML.innerHTML = '<img src="fileadmin/css/loading.gif" />';


		var url = 'index.php';
		var pars = 'eID=tx_ddmapmatrix_pi1_getcontact&uid=' + uID; 
		var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: function(result) {
									var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_right");
									resultHTML.innerHTML = result;
								}
				       }).request();
	}	
}

function loadMap(map) {
		
	var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_left");
	resultHTML.innerHTML = '<img src="fileadmin/css/loading.gif" />';

	var url = 'index.php';
	var pars = 'eID=tx_ddmapmatrix_pi1_getmap&map=' + map; 
	var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: function(result) {
								var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_left");
								resultHTML.innerHTML = result;
							}
			       }).request();
	
	if (map == 'europa') {
		var continent = dojo.byId("tx_ddmapmatrix_pi1[filter_continent]");
		for( i=continent.length-1; i>=0; i--) {
			switch(continent.options[i].value)  {
				case "1":
				case "66":	
					continent.options[i].selected = true;
					break;
			}
		}
	}
	
	if (map == 'german') {
		var continent = dojo.byId("tx_ddmapmatrix_pi1[filter_continent]");
		for( i=continent.length-1; i>=0; i--) {
			switch(continent.options[i].value)  {
				case "1":
				case "66":	
					continent.options[i].selected = true;
					break;
			}
		}

		var land = dojo.byId("tx_ddmapmatrix_pi1[filter_land]");
		for( i=land.length-1; i>=0; i--) {
			switch(land.options[i].value)  {
				case "1":
				case "66":	
					land.options[i].selected = true;
					break;
			}
		}
		
		var type = dojo.byId("tx_ddmapmatrix_pi1_type");
		type.style.visibility = "visible"
	}
	
}


function showMapLocation(uID) {
	if (isDigit(uID)) {
		var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_right");
		resultHTML.innerHTML = '<img src="fileadmin/css/loading.gif" />';

		var url = 'index.php';
		var pars = 'eID=tx_ddmapmatrix_pi1_getlocation&uid=' + uID; 
		var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: function(result) {
									var resultHTML = dojo.byId("tx_ddmapmatrix_pi1_result_item_group_right");
									resultHTML.innerHTML = result;
								}
				       }).request();
	}	

	
}


// Verbrauchsrechner Grundierung
dojo.declare("teaser.calc.Grundierung", dijit.form.Form,{

	onSubmit: function(/*Event?*/e){ 
		var m2 = dojo.byId('calc_m2');
		var verbrauch = dojo.byId('calc_verbrauch');
		if (isDigit(m2.value)) {
			var result = parseInt(m2.value) * parseInt(verbrauch.value);
			var result = parseFloat(m2.value.replace(/\,/,".")) * parseFloat(verbrauch.value.replace(/\,/,"."));
			var resultCalc = dojo.byId('tx-ddrenderteasertypeimatrix-pi1-item-calc-result');
			resultCalc.innerHTML = String(result).replace(/\./,",");
		}
		dojo.stopEvent(e);
		return false;
	}
});


// Verbrauchsrechner Spachteln
dojo.declare("teaser.calc.Spachteln", dijit.form.Form,{

	onSubmit: function(/*Event?*/e){ 
		var m2 = dojo.byId('calc_m2');
		var mm = dojo.byId('calc_mm');
		var verbrauch = dojo.byId('calc_verbrauch');
		if (isDigit(m2.value) && isDigit(mm.value)) {
			var result = parseFloat(m2.value.replace(/\,/,".")) * parseFloat(mm.value.replace(/\,/,".")) * parseFloat(verbrauch.value.replace(/\,/,"."));
			var resultCalc = dojo.byId('tx-ddrenderteasertypeimatrix-pi1-item-calc-result');
			resultCalc.innerHTML = String(result).replace(/\./,",");
		}
		dojo.stopEvent(e);
		return false;
	}
});

// Verbrauchsrechner Kleben
dojo.declare("teaser.calc.Kleben", dijit.form.Form,{

	onSubmit: function(/*Event?*/e){ 
		var m2 = dojo.byId('calc_m2');
		var zahn = dojo.byId('calc_zahn');
		var verbrauch = dojo.byId('calc_verbrauch');
		if (isDigit(m2.value) && isDigit(zahn.value)) {
			var result = parseFloat(m2.value.replace(/\,/,".")) * parseFloat(zahn.value.replace(/\,/,".")) * parseFloat(verbrauch.value.replace(/\,/,"."));
			var resultCalc = dojo.byId('tx-ddrenderteasertypeimatrix-pi1-item-calc-result');
			resultCalc.innerHTML = String(result).replace(/\./,",");
		}
		dojo.stopEvent(e);
		return false;
	}
});

// Verbrauchsrechner Fugen
dojo.declare("teaser.calc.Fugen", dijit.form.Form,{
	onSubmit: function(/*Event?*/e){ 
		var ka = dojo.byId('calc_ka');
		var kb = dojo.byId('calc_kb');
		var fb = dojo.byId('calc_fb');
		var fh = dojo.byId('calc_fh');
		var dichte = dojo.byId('calc_dichte');
		if (isDigit(ka.value) && isDigit(kb.value) && isDigit(fb.value) && isDigit(fh.value) ) {
			var result = (((100 / parseFloat(ka.value.replace(/\,/,"."))) +  (100 / parseFloat(kb.value.replace(/\,/,".")))) * 10) * (parseFloat(fb.value.replace(/\,/,".")) / 100)  * (parseFloat(fh.value.replace(/\,/,".")) / 100)  * (parseFloat(dichte.value.replace(/\,/,".")) + 10) ;
			var resultCalc = dojo.byId('tx-ddrenderteasertypeimatrix-pi1-item-calc-result');
			resultCalc.innerHTML = String(result).replace(/\./,",");
		}
		dojo.stopEvent(e);
		return false;
	}
});


 // Codex Registration
// ----------------------
dojo.declare("reg_thanks.Dialog",dijit.Dialog,{

	_onSubmit: function(e){
		window.location.href = 'index.php?id=531';
	}

});

dojo.declare("codex.Registration", dijit.layout.TabContainer, {
	company:'',
	gender: '',
	firstname:'',
	lastname:'',
	zip:'',
	city:'',
	street:'',
	phone:'',
	fax:'',
	mobile:'',
	email:'',
	web:'',
	foundingyear:'',
	employees:'',
	capability_profile:'',
	reference_profile:'',
	miscellaneous_company:'',
	shopper_type:'',
	direct_shopper_number:'',
	direct_shopper_merchant:'',
	direct_shopper_merchant_city:'',
	tilesetter_foreman:'',
	tilesetter_assistant:'',
	stonemason_foreman:'',
	stonemason_assistant:'',
	job_miscelaneous:'',
	fe_user_uid:'',
	

	startup: function() {

		// User ID
		this.fe_user_uid 	= dojo.byId("fe_user_uid");



		if (!checkMendatoryInput( this.fe_user_uid.value )) {
			dojo.connect(dojo.byId("base_next"), "onclick", this, this.nextStep);
			dojo.byId("base_next").page = dijit.byId('tab2');

			dojo.connect(dojo.byId("qualification_next"), "onclick", this, this.nextStep);
			dojo.byId("qualification_next").page = dijit.byId('tab3');
	
			dojo.connect(dojo.byId("qualification_back"), "onclick", this, this.nextStep);
			dojo.byId("qualification_back").page = dijit.byId('tab1');

		} else {
			
			dojo.connect(dojo.byId("login_next"), "onclick", this, this.nextStep);
			dojo.byId("login_next").page = dijit.byId('tab2');
			
			
			dojo.connect(dojo.byId("base_next"), "onclick", this, this.nextStep);
			dojo.byId("base_next").page = dijit.byId('tab3');
			
		}
		dojo.connect(dojo.byId("company_next"), "onclick", this, this.nextStep);
		dojo.byId("company_next").page = dijit.byId('tab4');

		dojo.connect(dojo.byId("company_back"), "onclick", this, this.nextStep);
		dojo.byId("company_back").page = dijit.byId('tab2');

		dojo.connect(dojo.byId("customer_next"), "onclick", this, this.nextStep);
		dojo.byId("customer_next").page = dijit.byId('tab5');

		dojo.connect(dojo.byId("customer_back"), "onclick", this, this.nextStep);
		dojo.byId("customer_back").page = dijit.byId('tab3');

		dojo.connect(dojo.byId("overview_back"), "onclick", this, this.nextStep);
		dojo.byId("overview_back").page = dijit.byId('tab4');

		dojo.connect(dojo.byId("overview_save"), "onclick", this, this.saveOverAjax);

		this.inherited(arguments);	
	},
	
	nextStep: function(e) {
		var params = e.target;
		this.selectChild(params.page);
	},

	saveOverAjax: function() {

		this.checkBaseData();
		if (!checkMendatoryInput( this.fe_user_uid.value )) {
			this.checkQualificationData();	
		} else {
			this.getQualificationHiddenData();	
		}
		this.checkCompanyProfile();	
		this.checkCustomerProfile();	

		var url = 'index.php';
		var pars = 'eID=tx_ddcdregistration_pi1_save&company=' + this.company.value + '&gender=' + this.gender.value + '&firstname=' + this.firstname.value + '&lastname=' + this.lastname.value; 
		var pars = pars + '&zip=' + this.zip.value + '&city=' + this.city.value + '&street=' + this.street.value + '&phone=' + this.phone.value + '&fax=' + this.fax.value;
		var pars = pars + '&mobile=' + this.mobile.value + '&email=' + this.email.value + '&web=' + this.web.value + '&foundingyear=' + this.foundingyear.value;
		var pars = pars + '&employees=' + this.employees.value + '&capability_profile=' + this.capability_profile.value + '&reference_profile=' + this.reference_profile.value; 
		var pars = pars + '&miscellaneous_company=' + this.miscellaneous_company.value + '&shopper_type=' + this.shopper_type + '&direct_shopper_number=' + this.direct_shopper_number.value;
		var pars = pars + '&direct_shopper_merchant=' + this.direct_shopper_merchant.value + '&direct_shopper_merchant_city=' + this.direct_shopper_merchant_city.value;
		var pars = pars + '&tilesetter_foreman=' + this.tilesetter_foreman + '&tilesetter_assistant=' + this.tilesetter_assistant + '&stonemason_foreman=' + this.stonemason_foreman;
		var pars = pars + '&stonemason_assistant=' + this.stonemason_assistant + '&job_miscelaneous=' + this.job_miscelaneous + '&fe_user_uid=' + this.fe_user_uid.value;
		
		var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: function() {
									var dialog = dijit.byId("thanks_registration");
									dialog.show();
								}
				       }).request();
	},
	
	checkLogin: function() {
		var result	= true;
		
		return result;
	},

	checkBaseData: function() {
		var result	= true;
		
		this.company 	= dojo.byId("company");
		this.gender	= dojo.byId("gender");
		this.firstname	= dojo.byId("firstname");
		this.lastname	= dojo.byId("lastname");
		this.zip	= dojo.byId("zip");
		this.city	= dojo.byId("city");
		this.street	= dojo.byId("street");
		this.phone	= dojo.byId("phone");
		this.fax	= dojo.byId("fax");
		this.mobile	= dojo.byId("mobilphone");
		this.email	= dojo.byId("email");
		this.web	= dojo.byId("url");

		if(!checkMendatoryInput(this.company.value)){ 		result = false; setErrorStyle(this.company); 		} else {setNormalStyle(this.company); 		}
		if(!checkMendatorySelect(this.gender.value)){ 		result = false; setErrorStyle(this.gender);  		} else {setNormalStyle(this.gender);		}
		if(!checkMendatoryInput(this.firstname.value)){ 	result = false; setErrorStyle(this.firstname);	 	} else {setNormalStyle(this.firstname);		}
		if(!checkMendatoryInput(this.lastname.value)){		result = false; setErrorStyle(this.lastname);		} else {setNormalStyle(this.lastname);		}
		if(!checkMendatoryInput(this.zip.value)){		result = false; setErrorStyle(this.zip);		} else {setNormalStyle(this.zip);		}
		if(!checkMendatoryInput(this.city.value)){		result = false; setErrorStyle(this.city);		} else {setNormalStyle(this.city);		}
		if(!checkMendatoryInput(this.street.value)){		result = false; setErrorStyle(this.street);		} else {setNormalStyle(this.street);		}
		if(!checkMendatoryInput(this.phone.value)){		result = false; setErrorStyle(this.phone);		} else {setNormalStyle(this.phone);		}
		if(!checkMendatoryInput(this.fax.value)){		result = false; setErrorStyle(this.fax);		} else {setNormalStyle(this.fax);		}
		if((!checkMendatoryInput(this.email.value)) || (!checkEmailAdr(this.email.value))) { result = false; setErrorStyle(this.email);					} else {setNormalStyle(this.email);}
		
		return result;
	},

	getQualificationHiddenData: function() {
		this.tilesetter_foreman 	= dojo.byId("tilesetter_foreman").value;
		this.tilesetter_assistant 	= dojo.byId("tilesetter_assistant").value;
		this.stonemason_foreman		= dojo.byId("stonemason_foreman").value;
		this.stonemason_assistant	= dojo.byId("stonemason_assistant").value;
		this.job_miscelaneous		= dojo.byId("job_miscelaneous").value;
	},

	checkQualificationData: function() {
		var result	= true;
		
		if (dojo.byId("tilesetter_foreman").checked) {
			this.tilesetter_foreman 	= dojo.byId("tilesetter_foreman").value;
		} else {this.tilesetter_foreman = '';}
		if (dojo.byId("tilesetter_assistant").checked) {
			this.tilesetter_assistant 	= dojo.byId("tilesetter_assistant").value;
		} else {this.tilesetter_assistant ='';}
		if(dojo.byId("stonemason_foreman").checked) {
			this.stonemason_foreman		= dojo.byId("stonemason_foreman").value;
		} else {this.stonemason_foreman = '';}
		if ( dojo.byId("stonemason_assistant").checked) {
			this.stonemason_assistant	= dojo.byId("stonemason_assistant").value;
		} else {this.stonemason_assistant = '';}
		if ( dojo.byId("job_miscelaneous").checked) {
			this.job_miscelaneous		= dojo.byId("job_miscelaneous").value;
		} else {this.job_miscelaneous = '';}
		
		return result;
	},

	checkCompanyProfile: function() {
		var result	 = true;
		this.foundingyear 		= dojo.byId("foundingyear");
		this.employees	 		= dojo.byId("employees");
		this.capability_profile		= dojo.byId("capability_profile");
		this.reference_profile		= dojo.byId("reference_profile");
		this.miscellaneous_company	= dojo.byId("miscellaneous_company");

		if(!checkMendatoryInput(this.foundingyear.value)){ 	result = false; setErrorStyle(this.foundingyear); 	} else {setNormalStyle(this.foundingyear); 	}
		if(!checkMendatoryInput(this.employees.value)){ 	result = false; setErrorStyle(this.employees); 		} else {setNormalStyle(this.employees); 	}
		
		return result;
	},

	checkCustomerProfile: function() {
		var result	= true;
		var shopper_type1 = dojo.byId("shopper_type1");
		var shopper_type2 = dojo.byId("shopper_type2");
		var shopper_type3 = dojo.byId("shopper_type3");
		this.direct_shopper_merchant 		= dojo.byId("direct_shopper_merchant");
		this.direct_shopper_merchant_city 	= dojo.byId("direct_shopper_merchant_city");
		this.direct_shopper_number		= dojo.byId("direct_shopper_number");


		if ( (shopper_type1.checked == false) && (shopper_type2.checked == false) && (shopper_type3.checked == false) ) {
			setErrorStyle(shopper_type1);
			setErrorStyle(shopper_type2);
			setErrorStyle(shopper_type3);
			result = false;
		} else {
			
			if (shopper_type1.checked ) {
				this.shopper_type = shopper_type1.value;	
			} else if (shopper_type2.checked ) {
				this.shopper_type = shopper_type2.value;	
			} else if (shopper_type3.checked ) {
				this.shopper_type = shopper_type3.value;	
			}			

			setNormalStyle(shopper_type1);			
			setNormalStyle(shopper_type2);			
			setNormalStyle(shopper_type3);			
		}
			
		return result;
		
	},
	
	setTabOverview: function() {
		
		var overview_company 			= dojo.byId("overview_company");
		var overview_contact 			= dojo.byId("overview_contact");
		var overview_zipcity			= dojo.byId("overview_zipcity"); 
		var overview_address 			= dojo.byId("overview_address");
		var overview_phone 				= dojo.byId("overview_phone");
		var overview_mobilphone 		= dojo.byId("overview_mobilphone");
		var overview_email 				= dojo.byId("overview_email");
		var overview_url 				= dojo.byId("overview_url");
		var overview_qualification 		= dojo.byId("overview_qualification");
		var overview_founding_year 		= dojo.byId("overview_founding_year");
		var overview_employees 			= dojo.byId("overview_employees");
		var overview_capability_profile = dojo.byId("overview_capability_profile");
		var overview_referenz_projects 	= dojo.byId("overview_referenz_projects");
		var overview_customer_profile 	= dojo.byId("overview_customer_profile");
		var overview_merchant 			= dojo.byId("overview_merchant");
		
		
		overview_company.innerHTML 				= this.company.value;
		overview_contact.innerHTML 				= this.gender.value +  ' ' + this.firstname.value +  ' ' + this.lastname.value;
		overview_zipcity.innerHTML 				= this.zip.value + ' ' + this.city.value;
		overview_address.innerHTML 				= this.street.value;
		overview_phone.innerHTML 				= this.phone.value + ' ' + this.fax.value;
		overview_mobilphone.innerHTML			= this.mobile.value;
		overview_email.innerHTML				= this.email.value;
		overview_url.innerHTML					= this.web.value;
		overview_qualification.innerHTML		= '';
		overview_founding_year.innerHTML		= this.foundingyear.value;
		overview_employees.innerHTML			= this.employees.value;
		overview_capability_profile.innerHTML 	= this.capability_profile.value;
		overview_referenz_projects.innerHTML	= this.reference_profile.value;
		overview_customer_profile.innerHTML		= this.shopper_type;
		overview_merchant.innerHTML				= this.direct_shopper_merchant.value + '(' + this.direct_shopper_merchant_city.value + ')';
		
		
	},

	selectChild: function(/*Widget*/ page){
		var result = true;
		var result_tab1 = true;
		var result_tab2 = true;
		var result_tab3 = true;
		var result_tab4 = true;
		var page_new;

		if (!checkMendatoryInput( this.fe_user_uid.value )) {
			result_tab1 = this.checkBaseData();	
			result_tab2 = this.checkQualificationData();	
			result_tab3 = this.checkCompanyProfile();	
			result_tab4 = this.checkCustomerProfile();	
		} else {
			result_tab1 = this.checkLogin();	
			result_tab2 = this.checkBaseData();	
			result_tab3 = this.checkCompanyProfile();	
			result_tab4 = this.checkCustomerProfile();	
		}


		if (result_tab1 == false  ) {
			page_new = dijit.byId('tab1');
			result = false;
		} else 	if (result_tab2 == false  ) {
				page_new = dijit.byId('tab2');
				result = false;
			} else 	if (result_tab3 == false) {
					page_new = dijit.byId('tab3');
					result = false;
				} else 	if (result_tab4 == false) {
						page_new = dijit.byId('tab4');
						result = false;
					} else {
						this.setTabOverview();
						page_new = dijit.byId('tab5');
						
					}
		
		if (page_new.id <  page.id) {
			page = page_new;
		}
		
		if (this.selectedChildWidget.id != page.id) {
			this.inherited(arguments);
		}

	}
	
});

// Tooltip Login Dialog
// ----------------------
dojo.declare("login.Dialog",dijit.TooltipDialog,{


});


// Tooltip Search Dialog
// ----------------------
dojo.declare("search.Dialog",dijit.TooltipDialog,{


});


// Dialog for Person/Location Contact
// -------------------------
dojo.declare("contact.Dialog",dijit.Dialog,{
	canExecute: true,
	errorMessages: '',
	
	
	_onSubmit: function(e){
		this.canExecute = true;
		this.errorMessages = '';
		
		
		var lastname 	= dojo.byId("lastname_contact");
		var firstname 	= dojo.byId("firstname_contact");
		var gender 	= dojo.byId("gender_contact");
		var email 	= dojo.byId("email_contact");
		var street 	= dojo.byId("street_contact");
		var zip 	= dojo.byId("zip_contact");
		var city 	= dojo.byId("city_contact");
		var country 	= dojo.byId("country_contact");
		var funktion 	= dojo.byId("funktion_contact");
		
		var error_general = dojo.byId("error_general_contact");
		var error_gender = dojo.byId("error_gender_contact");
		var error_name = dojo.byId("error_name_contact");
		var error_email = dojo.byId("error_email_contact");
		var error_message = dojo.byId("error_message_contact");

		if(!checkMendatorySelect(country.value)){ 		this.canExecute = false; setErrorStyle(country); 		} else {setNormalStyle(country); 	}
		if(!checkMendatorySelect(gender.value)){ 		this.canExecute = false; setErrorStyle(gender);  		} else {setNormalStyle(gender);		}
		if(!checkMendatoryInput(firstname.value)){ 		this.canExecute = false; setErrorStyle(firstname);	 	} else {setNormalStyle(firstname);	}
		if(!checkMendatoryInput(lastname.value)){		this.canExecute = false; setErrorStyle(lastname);		} else {setNormalStyle(lastname);	}
		if(!checkMendatoryInput(zip.value)){			this.canExecute = false; setErrorStyle(zip);			} else {setNormalStyle(zip);		}
		if(!checkMendatoryInput(city.value)){			this.canExecute = false; setErrorStyle(city);			} else {setNormalStyle(city);		}
		if(!checkMendatoryInput(street.value)){			this.canExecute = false; setErrorStyle(street);			} else {setNormalStyle(street);		}
		if(!checkMendatorySelect(funktion.value)){		this.canExecute = false; setErrorStyle(funktion);		} else {setNormalStyle(funktion);	}
		if((!checkMendatoryInput(email.value)) || (!checkEmailAdr(email.value))) { this.canExecute = false; setErrorStyle(email);					} else {setNormalStyle(email);}
		
	
		if (this.canExecute) {
			this.execute(this.getValues());
		} else	{
			var error = dojo.byId("error_contact");
			error.innerHTML = error_general.value;
		
		}
	
	},






	
	show: function(name, company, street, zip, city, phone, fax, email) {
		var error = dojo.byId("error_contact");
		error.innerHTML = '';

		var tmp_Name = dojo.byId("tmp_name_contact");
		tmp_Name.value = name;

		var tmp_Company = dojo.byId("tmp_company_contact");
		tmp_Company.value = company;

		var tmp_Street = dojo.byId("tmp_street_contact");
		tmp_Street.value = street;

		var tmp_Zip = dojo.byId("tmp_zip_contact");
		tmp_Zip.value = zip;

		var tmp_City = dojo.byId("tmp_city_contact");
		tmp_City.value = city;

		var tmp_Phone = dojo.byId("tmp_phone_contact");
		tmp_Phone.value = phone;

		var tmp_fax = dojo.byId("tmp_fax_contact");
		tmp_fax.value = fax;

		var tmp_email = dojo.byId("tmp_email_contact");
		tmp_email.value = email;

		var headline = dojo.byId("contact_headline");
		headline.innerHTML = tmp_Name.value + '<br />' + tmp_email.value;

		this.reset();
		this.inherited(arguments);
		
	}
});
 

// Send Mailfields to Server
// -------------------------
function sendMailForm() {

	var gender 		= dojo.byId("gender_contact");
	var title 		= dojo.byId("title_contact");
	var lastname 		= dojo.byId("lastname_contact");
	var firstname		= dojo.byId("firstname_contact");
	
	var company		= dojo.byId("company_contact");
	var email 		= dojo.byId("email_contact");
	var phone 		= dojo.byId("phone_contact");
	var fax 		= dojo.byId("fax_contact");
	var street 		= dojo.byId("street_contact");
	var zip 		= dojo.byId("zip_contact");
	
	var city 		= dojo.byId("city_contact");
	var country 		= dojo.byId("country_contact");
	var funktion 		= dojo.byId("funktion_contact");
	var department 		= dojo.byId("department_contact");
	var occasion 		= dojo.byId("occasion_contact");
	
	var message 		= dojo.byId("message_contact");
	var emailto 		= dojo.byId("tmp_email_contact");
	
	var brand_uzin		= dojo.byId("brand_uzin_contact");
	var brand_wolff		= dojo.byId("brand_wolff_contact");
	var brand_pallmann	= dojo.byId("brand_pallmann_contact");	
	var brand_qeshfloor	= dojo.byId("brand_qeshfloor_contact");
	var brand_codex		= dojo.byId("brand_codex_contact");	
	var brand_rz		= dojo.byId("brand_rz_contact");	
		
	var solution_office	= dojo.byId("solution_office_contact");
	var solution_shop	= dojo.byId("solution_shop_contact");
	var solution_health	= dojo.byId("solution_health_contact");
	var solution_hotel	= dojo.byId("solution_hotel_contact");
	var solution_transport	= dojo.byId("solution_transport_contact");
	var solution_sport	= dojo.byId("solution_sport_contact");

	var text_1		= dojo.byId("text_1_contact");
	var text_2		= dojo.byId("text_2_contact");

	if(brand_uzin.checked){brand_uzin='1';} else{brand_uzin='0';}
	if(brand_wolff.checked){brand_wolff='1';} else{brand_wolff='0';}
	if(brand_pallmann.checked){brand_pallmann='1';} else{brand_pallmann='0';}
	if(brand_qeshfloor.checked){brand_qeshfloor='1';} else{brand_qeshfloor='0';}
	if(brand_codex.checked){brand_codex='1';} else{brand_codex='0';}
	if(brand_rz.checked){brand_rz='1';} else{brand_rz='0';}
	
	if(solution_office.checked){solution_office='1';} else{solution_office='0';}
	if(solution_shop.checked){solution_shop='1';} else{solution_shop='0';}
	if(solution_health.checked){solution_health='1';} else{solution_health='0';}
	if(solution_hotel.checked){solution_hotel='1';} else{solution_hotel='0';}
	if(solution_transport.checked){solution_transport='1';} else{solution_transport='0';}
	if(solution_sport.checked){solution_sport='1';} else{solution_sport='0';}
	
	if(text_1.checked){text_1='1';} else{text_1='0';}
	if(text_2.checked){text_2='1';} else{text_2='0';}
		
	var url = 'index.php';
	var pars = 'eID=tx_ddgeneraldojomatrix_pi1_contactform&gender=' + gender.value + '&firstname=' + firstname.value + '&lastname=' + lastname.value + '&title=' + title.value;
	var pars = pars + '&company=' + company.value + '&email=' + email.value + '&phone=' + phone.value + '&fax=' + fax.value + '&street=' + street.value + '&zip=' + zip.value;
	var pars = pars + '&occasion=' + occasion.value + '&country=' + country.value + '&funktion=' + funktion.value + '&city=' + city.value + '&department=' + department.value;
	var pars = pars + '&emailto=' + emailto.value + '&message=' + message.value;
	var pars = pars + '&brand_uzin=' + brand_uzin + '&brand_wolff=' + brand_wolff+ '&brand_pallmann=' + brand_pallmann + '&brand_qeshfloor=' + brand_qeshfloor + '&brand_codex=' + brand_codex + '&brand_rz=' + brand_rz;
	var pars = pars + '&solution_office=' + solution_office + '&solution_shop=' + solution_shop + '&solution_health=' + solution_health + '&solution_hotel=' + solution_hotel + '&solution_transport=' + solution_transport + '&solution_sport=' + solution_sport;
	var pars = pars + '&text_1=' + text_1 + '&text_2=' + text_2;
	var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: showAnswerSendMailAjax}).request();
	
}

// Answer from Server
// ------------------
function showAnswerSendMail(orgRequest) {
	if(window.ActiveXObject){ 
		var xmldoc = new ActiveXObject('Microsoft.XMLDOM');
		xmldoc.loadXML(orgRequest);
	} else {

		parser=new DOMParser();
		xmldoc=parser.parseFromString(orgRequest,"text/xml");
	}
	
	var result = xmldoc.getElementsByTagName('data')[0].firstChild.data;
	
	if (result == 'ok') {
		var dialog = dijit.byId("form_contact");
		dialog.hide();
		var dialog = dijit.byId("thanks_contact");
		dialog.show();
	}
}

// Dialog for Job
// -------------------------
dojo.declare("job.Dialog",dijit.Dialog,{
	canExecute: false,
	errorMessages: '',
	
	
	postCreate: function(){
		this.inherited(arguments);
		
		var uploadForm = dojo.byId("tx_ddjobmatrix_pi1_application_form_document_text");
		
		var form1 = "<form id='tx_ddjobmatrix_pi1_form_upload'  enctype='multipart/form-data'   name='job_application'   action='index.php?eID=tx_ddjobmatrix_pi1_jobform'   method='post'>";
		var form2 = "<input type='file' name='document_upload' id='document_upload'></form>";
		uploadForm.innerHTML = form1 + form2;
	},
	
	_onSubmit: function(e){
		this.canExecute = false;
		this.errorMessages = '';
		
		var begin_date_day 	= dojo.byId("begin_day");
		var begin_date_month 	= dojo.byId("begin_month");
		var begin_date_year 	= dojo.byId("begin_year");
		var gender 		= dojo.byId("gender");
		var first_name 		= dojo.byId("firstname");
		var last_name 		= dojo.byId("lastname");
		var birth_date_day 	= dojo.byId("birth_day");
		var birth_date_month 	= dojo.byId("birth_month");
		var birth_date_year 	= dojo.byId("birth_year");
		var nation 		= dojo.byId("nationality");
		var zip 		= dojo.byId("zip");
		var street 		= dojo.byId("street");
		var city 		= dojo.byId("city");
		var email 		= dojo.byId("email");

		var error_begin_date	= dojo.byId("error_begin_date");
		var error_gender	= dojo.byId("error_gender");
		var error_first_name	= dojo.byId("error_first_name");
		var error_last_name	= dojo.byId("error_last_name");
		var error_birth_date	= dojo.byId("error_birth_date");
		var error_nation	= dojo.byId("error_nation");
		var error_zip		= dojo.byId("error_zip");
		var error_street	= dojo.byId("error_street");
		var error_email		= dojo.byId("error_email");
		var error_city		= dojo.byId("error_city");
		var error_general	= dojo.byId("error_general");

		var result	= true;

		if(
		   ((typeof begin_date_day.value === "undefined")	|| (begin_date_day.value == null) 	|| (begin_date_day.value == 0)) ||
		   ((typeof begin_date_month.value === "undefined")	|| (begin_date_month.value == null) 	|| (begin_date_month.value == 0)) ||
		   ((typeof begin_date_year.value === "undefined")	|| (begin_date_year.value == null) 	|| (begin_date_year.value == 0))
		  ){
			result = false;
			setErrorStyle(begin_date_day); 		 
			setErrorStyle(begin_date_month); 		 
			setErrorStyle(begin_date_year); 		 
//			this.errorMessages = this.errorMessages + '<li>' + error_begin_date.value + '</li>';					
		} else {
			setNormalStyle(begin_date_day);
			setNormalStyle(begin_date_month);
			setNormalStyle(begin_date_year);
		}

		if((typeof gender.value === "undefined")	|| (gender.value == null) || (gender.value == 0)){
			setErrorStyle(gender); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_gender.value + '</li>';					
		} else {
			setNormalStyle(gender);
		}
		
		if((typeof first_name.value === "undefined")	|| (first_name.value == null) || (first_name.value.length == 0)){
			setErrorStyle(first_name); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_first_name.value + '</li>';					
		} else {
			setNormalStyle(first_name);
		}
		
		if((typeof last_name.value === "undefined")	|| (last_name.value == null) || (last_name.value.length == 0)){
			setErrorStyle(last_name); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_last_name.value + '</li>';					
		} else {
			setNormalStyle(last_name);
		}

		if(
		   ((typeof birth_date_day.value === "undefined")	|| (birth_date_day.value == null) 	|| (birth_date_day.value == 0)) ||
		   ((typeof birth_date_month.value === "undefined")	|| (birth_date_month.value == null) 	|| (birth_date_month.value == 0)) ||
		   ((typeof birth_date_year.value === "undefined")	|| (birth_date_year.value == null) 	|| (birth_date_year.value == 0))
		  ){
			setErrorStyle(birth_date_day); 		 
			setErrorStyle(birth_date_month); 		 
			setErrorStyle(birth_date_year); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_birth_date.value + '</li>';					
		} else {
			setNormalStyle(birth_date_day);
			setNormalStyle(birth_date_month);
			setNormalStyle(birth_date_year);
		}

		if((typeof nation.value === "undefined")	|| (nation.value == null) || (nation.value.length == 0)){

			setErrorStyle(nation); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_nation.value + '</li>';					
		} else {
			setNormalStyle(nation);
		}

		if((typeof zip.value === "undefined")	|| (zip.value == null) || (zip.value.length == 0)){

			setErrorStyle(zip); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_zip.value + '</li>';					
		} else {
			setNormalStyle(zip);
		}

		if((typeof street.value === "undefined")	|| (street.value == null) || (street.value.length == 0)){
			setErrorStyle(street); 		 
			result = false;
//			this.errorMessages = this.errorMessages + '<li>' + error_street.value + '</li>';					
		} else {
			setNormalStyle(street);
		}

		if((typeof city.value === "undefined")	|| (city.value == null) || (city.value.length == 0)){
			setErrorStyle(city); 		 
			result = false;

//			this.errorMessages = this.errorMessages + '<li>' + error_city.value + '</li>';					

		} else {
			setNormalStyle(city);
		}

		if((typeof email.value === "undefined")	|| (email.value == null) || (email.value.length == 0) ||  (!checkEmailAdr(email.value)) ){
			setErrorStyle(email); 		 
			result = false;

//			this.errorMessages = this.errorMessages + '<li>' + error_email.value + '</li>';					
		} else {
			setNormalStyle(email);
		}


		if (result) {
			this.canExecute = true;
		}
		
		if (this.canExecute) {
			this.execute(this.getValues());
		} else	{
		
			var error = dojo.byId("form_error_job");
			
			error.innerHTML = error_general.value;
		}
	},
	
	show: function() {
		var error = dojo.byId("form_error_job");
//		error.innerHTML = '';

		this.reset();
		this.inherited(arguments);
	}
});

// Send to Server
//---------------------------
function sendJob() {

	var position 			= dojo.byId("position");
	var code 			= dojo.byId("code");
	var company 			= dojo.byId("company");
	var location 			= dojo.byId("location");
	var begin_date_day 		= dojo.byId("begin_day");
	var begin_date_month 		= dojo.byId("begin_month");
	var begin_date_year 		= dojo.byId("begin_year");
	var gender 			= dojo.byId("gender");
	var first_name 			= dojo.byId("firstname");
	var last_name 			= dojo.byId("lastname");
	var birth_date_day 		= dojo.byId("birth_day");
	var birth_date_month 		= dojo.byId("birth_month");
	var birth_date_year 		= dojo.byId("birth_year");
	var nation 			= dojo.byId("nationality");
	var country			= dojo.byId("country");
	var zip 			= dojo.byId("zip");
	var street 			= dojo.byId("street");
	var city 			= dojo.byId("city");
	var email 			= dojo.byId("email");
	var phone 			= dojo.byId("phone");
	var mobile 			= dojo.byId("mobil");
	var graduation			= dojo.byId("graduation_text");
	var schooling			= dojo.byId("schooling_text");
	var studies			= dojo.byId("studies_text");
	var internationalexperience 	= dojo.byId("internationalexperience_text");
	var foreign_language_check 	= dojo.byId("foreign_language_check");
	var foreign_language_en 	= dojo.byId("foreign_language_en");
	var foreign_language_fr 	= dojo.byId("foreign_language_fr");
	var foreign_language_sp 	= dojo.byId("foreign_language_sp");
	var foreign_language_other 	= dojo.byId("foreign_language_other");
	var foreign_language_other_text = dojo.byId("foreign_language_other_text");
	var edv 			= dojo.byId("edv_text");
	var qualification 		= dojo.byId("other_qualification_text");
	
	var url = 'index.php?';
	var pars = 'eID=tx_ddjobmatrix_pi1_jobform&position='+  (position.value) + '&code=' + (code.value) +  '&company=' + (company.value) + '&location=' + (location.value);
	pars = pars + '&begin_day=' + (begin_date_day.value) + '&begin_month=' + (begin_date_month.value) + '&begin_year=' + (begin_date_year.value);
	pars = pars + '&gender=' + (gender.value) + '&firstname=' + (first_name.value) + '&lastname=' + (last_name.value);
	pars = pars + '&birth_day=' + (birth_date_day.value) + '&birth_month=' + (birth_date_month.value) + '&birth_year=' + (birth_date_year.value);
	pars = pars + '&nation=' + (nation.value) + '&country=' + (country.value) + '&zip=' + (zip.value) + '&street=' + (street.value) + '&city=' + (city.value) + '&email=' + (email.value) + '&phone=' + (phone.value);
	pars = pars + '&mobile=' + (mobile.value) + '&graduation=' + (graduation.value) + '&schooling=' + (schooling.value) + '&studies=' + (studies.value) + '&internationalexperience=' + (internationalexperience.value);
	pars = pars + '&foreign_language_check=' + (foreign_language_check.value) + '&foreign_language_en=' + (foreign_language_en.value) + '&foreign_language_fr=' + (foreign_language_fr.value);
	pars = pars + '&foreign_language_sp=' + (foreign_language_sp.value) + '&foreign_language_other=' + (foreign_language_other.value) + '&foreign_language_other_text=' + (foreign_language_other_text.value);
	pars = pars + '&edv=' + (edv.value) + '&qualification=' +(qualification.value);
	

	dojo.io.iframe.send({
            url: url + pars,
            method: "post",
            handleAs: "text",
            form: dojo.byId('tx_ddjobmatrix_pi1_form_upload'),
            handle: function(data,ioArgs){
		var dialog = dijit.byId("form_job");
		dialog.hide();
		var dialog = dijit.byId("thanks_job");
		dialog.show();
            }
		
	});
	
}

// Dialog for Seminar Contact
// -------------------------
dojo.declare("seminar.Dialog",dijit.Dialog,{
	canExecute: false,
	errorMessages: '',
	
	_onSubmit: function(e){
		this.canExecute = false;
		this.errorMessages = '';
		
		var gender 		= dojo.byId("gender");
		var lastname 		= dojo.byId("lastname");
		var email 		= dojo.byId("email");
		var company 		= dojo.byId("company");
		var zip 		= dojo.byId("zip");
		var street 		= dojo.byId("street");
		var city 		= dojo.byId("city");
		var phone 		= dojo.byId("phone");
		var fax 		= dojo.byId("fax");
		
		var error_gender	= dojo.byId("error_gender");
		var error_lastname	= dojo.byId("error_last_name");
		var error_email		= dojo.byId("error_email");
		var error_company	= dojo.byId("error_company");
		var error_zip		= dojo.byId("error_zip");
		var error_street	= dojo.byId("error_street");
		var error_city		= dojo.byId("error_city");
		var error_phone		= dojo.byId("error_phone");
		var error_fax		= dojo.byId("error_fax");

		var error_general	= dojo.byId("error_general");
		
		if((typeof gender.value === "undefined")	|| (gender.value == null) || (gender.value == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_gender.value + '</li>';					
		}
		if((typeof lastname.value === "undefined")	|| (lastname.value == null) || (lastname.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_lastname.value + '</li>';					
		}
		if((typeof email.value === "undefined")	|| (email.value == null) || (email.value.length == 0) || (!checkEmailAdr(email.value)) ){
			this.errorMessages = this.errorMessages + '<li>' + error_email.value + '</li>';					
		}
		if((typeof company.value === "undefined")	|| (company.value == null) || (company.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_company.value + '</li>';					
		}
		if((typeof street.value === "undefined")	|| (street.value == null) || (street.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_street.value + '</li>';					
		}
		if((typeof zip.value === "undefined")	|| (zip.value == null) || (zip.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_zip.value + '</li>';					
		}
		if((typeof city.value === "undefined")	|| (city.value == null) || (city.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_city.value + '</li>';					
		}
		if((typeof phone.value === "undefined")	|| (phone.value == null) || (phone.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_phone.value + '</li>';					
		}
		if((typeof fax.value === "undefined")	|| (fax.value == null) || (fax.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_fax.value + '</li>';					
		}

		if (this.errorMessages.length == 0) {
			this.canExecute = true;
		}
		
		if (this.canExecute) {
			this.execute(this.getValues());
		} else	{
		
			var error = dojo.byId("form_error_seminar");
			error.innerHTML = error_general.value + '<ul>' + this.errorMessages + '</ul>';
		}
	},
	
	show: function(seminardate, seminarlocation, seminarset) {
		var error = dojo.byId("form_error_seminar");
		error.innerHTML = '';

		var seminar_date_location = dojo.byId("seminar_date_location");
		seminar_date_location.innerHTML = seminardate + ' ' + seminarlocation;

		var seminar_date = dojo.byId("seminar_date");
		seminar_date.value = seminardate;

		var seminar_location = dojo.byId("seminar_location");
		seminar_location.value = seminarlocation;
		
		var seminar_set = dojo.byId("seminar_set");
		seminar_set.value = seminarset;

		this.reset();
		this.inherited(arguments);
	}
});

// Send to Server
//---------------------------
function sendSeminar() {
	
//	var check1 = '';
	
	var gender 		= dojo.byId("gender");
	var firstname 	= dojo.byId("firstname");
	var lastname 	= dojo.byId("lastname");
	var email 		= dojo.byId("email");
	var company 	= dojo.byId("company");
	var street 		= dojo.byId("street");
	var zip 		= dojo.byId("zip");
	var city 		= dojo.byId("city");
	var country 	= dojo.byId("country");
	var phone 		= dojo.byId("phone");
	var fax 		= dojo.byId("fax");
//	var check1 		= dojo.byId("checkbox1");
	var check2 		= dojo.byId("checkbox2");
	var check3 		= dojo.byId("checkbox3");
	var location 	= dojo.byId("seminar_location");
	var date 		= dojo.byId("seminar_date");
	var seminar_set	= dojo.byId("seminar_set");
	
	var url = 'index.php';
	var pars = 'eID=tx_ddseminarmatrix_pi1_seminarform&gender=' + gender.value + '&firstname=' + firstname.value + '&lastname=' + lastname.value + '&email=' + email.value + '&company=' + company.value;
	pars = pars + '&street=' + street.value + '&zip=' + zip.value + '&city=' + city.value + '&country=' + country.value + '&phone=' + phone.value + '&fax=' + fax.value + '&check2=' + check2.value + '&check3=' + check3.value;
	pars = pars + '&location=' + location.value + '&date=' + date.value + '&seminar_set=' + seminar_set.value;
	var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: showAnswerSeminarAjax}).request();
	
}

// Answer From Server
// ------------------
function showAnswerSeminar(orgRequest) {
	if(window.ActiveXObject){ 
		var xmldoc = new ActiveXObject('Microsoft.XMLDOM');
		xmldoc.loadXML(orgRequest);
	} else {

		parser=new DOMParser();
		xmldoc=parser.parseFromString(orgRequest,"text/xml");
	}
	
	var result = xmldoc.getElementsByTagName('data')[0].firstChild.data;
	
	if (result == 'ok') {
		var dialog = dijit.byId("form_seminar");
		dialog.hide();
		var dialog = dijit.byId("thanks_seminar");
		dialog.show();
	}
}


// Dialog for Person Contact
// -------------------------
dojo.declare("recommend.Dialog",dijit.Dialog,{
	canExecute: false,
	errorMessages: '',
	
	
	_onSubmit: function(e){
		this.canExecute = false;
		this.errorMessages = '';
		
		var mailto 		= dojo.byId("recommend_mailto_name");
		var mailto_address 	= dojo.byId("recommend_mailto_address");
		var mailfrom 		= dojo.byId("recommend_mailfrom_name");
		var mailfrom_address 	= dojo.byId("recommend_mailfrom_address");

		var error_mailto		= dojo.byId("recommend_error_mailto");
		var error_mailto_address	= dojo.byId("recommend_error_mailto_address");
		var error_mailfrom		= dojo.byId("recommend_error_mailform");
		var error_mailfrom_address	= dojo.byId("recommend_error_mailform_address");
		var error_captcha		= dojo.byId("recommend_error_captcha");
		var error_general		= dojo.byId("recommend_error_general");
		
		if((typeof mailto.value === "undefined")	|| (mailto.value == null) || (mailto.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_mailto.value + '</li>';					
		}
		if((typeof mailto_address.value === "undefined")	|| (mailto_address.value == null) || (mailto_address.value.length == 0) || (!checkEmailAdr(mailto_address.value)) ){
			this.errorMessages = this.errorMessages + '<li>' + error_mailto_address.value + '</li>';					
		}
		if((typeof mailfrom.value === "undefined")	|| (mailfrom.value == null) || (mailfrom.value.length == 0)){
			this.errorMessages = this.errorMessages + '<li>' + error_mailfrom.value + '</li>';					
		}
		if((typeof mailfrom_address.value === "undefined")	|| (mailfrom_address.value == null) || (mailfrom_address.value.length == 0) || (!checkEmailAdr(mailfrom_address.value)) ){
			this.errorMessages = this.errorMessages + '<li>' + error_mailfrom_address.value + '</li>';					
		}
		
		if (!jcap()) {
			this.errorMessages = this.errorMessages + '<li>' + error_captcha.value + '</li>';					
			
		}

		if (this.errorMessages.length == 0) {
			this.canExecute = true;
		}
		
		if (this.canExecute) {
			this.execute(this.getValues());
		} else	{
			var error = dojo.byId("recommend_error");
			error.innerHTML = error_general.value + '<ul>' + this.errorMessages + '</ul>';
		}
	},
	
	show: function(pageURL,pageTitle) {

		var error = dojo.byId("recommend_error");
		error.innerHTML = '';

		var captcha = dojo.byId("recommend_captcha");
		captcha.innerHTML = sjcap();

		var pagetitle = dojo.byId("recommend_pagetitle");
		pagetitle.innerHTML = pageTitle;

		var tmp_pageURL = dojo.byId("recommend_tmp_pageURL");
		tmp_pageURL.value = pageURL;

		var tmp_pageTitle = dojo.byId("recommend_tmp_pageTitle");
		tmp_pageTitle.value = pageTitle;

		this.inherited(arguments);
	}
});


// Send to Server
//---------------------------
function sendRecommend(param) {
	var mailto 		= dojo.byId("recommend_mailto_name");
	var mailto_address 	= dojo.byId("recommend_mailto_address");
	var mailfrom 		= dojo.byId("recommend_mailfrom_name");
	var mailfrom_address 	= dojo.byId("recommend_mailfrom_address");

	var tmp_pageURL 	= dojo.byId("recommend_tmp_pageURL");
	var tmp_pageTitle 	= dojo.byId("recommend_tmp_pageTitle");
	
	var url = 'index.php';
	var pars = 'eID=tx_ddpagetoolsgeneralmatrix_pi2_recommend&mailto=' + mailto.value + '&mailto_address=' + mailto_address.value + '&mailfrom=' + mailfrom.value + '&mailfrom_address=' + mailfrom_address.value;
	pars = pars + '&pageurl=' + encode64(tmp_pageURL.value) + '&pagetitle=' + tmp_pageTitle.value;
	var myAjax = new Ajax (url, {method: 'get', data: pars, onComplete: showAnswerRecommendAjax}).request();
}


// Answer From Server
// ------------------
function showAnswerRecommend(orgRequest) {

	if(window.ActiveXObject){ 
		var xmldoc = new ActiveXObject('Microsoft.XMLDOM');
		xmldoc.loadXML(orgRequest);
	} else {

		parser=new DOMParser();
		xmldoc=parser.parseFromString(orgRequest,"text/xml");
	}

	var result = xmldoc.getElementsByTagName('data')[0].firstChild.data;

	var tmp_pageURL = dojo.byId("recommend_tmp_pageURL");
	tmp_pageURL.value = '';

	var tmp_pageTitle = dojo.byId("recommend_tmp_pageTitle");
	tmp_pageTitle.value = '';
	
	if (result == 'ok') {
		var dialog = dijit.byId("form_recommend");
		dialog.hide();
		var dialog = dijit.byId("thanks_recommend");
		dialog.show();
	}
}

// General Functions
// ------------------------------------
function setInputFieldFromChecked(formID, fieldname, fieldnameSet) {
	if ( document.getElementById(formID)  && document.getElementById(fieldname)  && document.getElementById(fieldnameSet) ) {
		if (document.getElementById(fieldname).checked == true){
			document.getElementById(fieldnameSet).disabled=false;
			document.getElementById(fieldnameSet).focus();
		}
		else {
			document.getElementById(fieldnameSet).value = ''; 
			document.getElementById(fieldnameSet).disabled=true;
		}
	}
}

// Form Check Functions
// -------------------------------
  function isDigit( ch )
  {
    if ( (ch >= '0') && (ch <= '9') )
      return true;
    else
      return false;
  }


  function isAlpha( ch )
  {
    if ( ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) )
      return true;
    else
      return false;
  }


  function isAlnum( ch )
  {
    if ( isAlpha( ch ) || isDigit( ch ) )
      return true;
    else
      return false;
  }


  function notIn( str1, str2 )
  {
    var i = 0;
    var j = str2.length;
    for( ; i<j; i++ )
    {
      var str3 =  str2.charAt(i);
      if( str1.indexOf( str3 ) != -1 )
        return false;
    }
    return true;
  }


  function checkUsername( username, mustBeQuoted )
  {
    var i = 0;
    var j = username.length;
    if ( username.charAt(0) != '"' )
    {
      if ( (username.charAt(0) <  ' ') || (username.charAt(0) >  '~')
            || !notIn( mustBeQuoted, username.charAt(0) ) )
        return false;
      for( i=1; i<j; i++ )
      {
        if ( ( (username.charAt(i) < ' ') || (username.charAt(i) >  '~')
              || !notIn ( mustBeQuoted, username.charAt(i) ) )
             && ( username.charAt(i-1) != '\\' ) )
          return false;
      }
    }
    else
    {
      if ( username.charAt( j-1 ) != '"' )
        return false;
      for( i=1; i<j-1; i++ )
      {
        if ( ( (username.charAt(i) == '\n') || (username.charAt(i) == '\r')
              || (username.charAt(i) == '\"') )
            && (username.charAt(i-1) != '\\') )
          return false;
      }

    }
    return true;
  }


  function checkNr ( nr )
  {
    var i=0;
    var j=nr.length;

    if( j < 1 )
      return false;

    for( ; i<j; i++ )
      if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
        return false;

    return true;
  }


  function checkIpnr( ipnr )
  {
    var iL=0;
    var iC=0;
    var i=0;
    var sNr = "";

    for( ; i< ipnr.length; i++ )
    {
      if ( ipnr.charAt(i) == '.' )
      {
        if ( !iL || (iL> 3) || parseInt( sNr,10 ) > 255 )
          return false;
        iC++;
        iL = 0;
        sNr = "";
        continue;
      }
      if ( isDigit ( ipnr.charAt(i) ) )
      {
        iL++;
        sNr = sNr + ipnr.charAt(i);
        continue;
      }
      return false;
    }

    if ( parseInt( sNr,10 ) > 255 )
      return false;
    if ( ( (iC==3) && (iL>=1) && (iL<=3) ) || ( (iC==4) && (!iL) )  )
      return true;
    else
      return false;
  }


  function checkFqdn( fqdn )
  {
    var iL=0;
    var iC=0;
    var i=fqdn.length-1;

    if ( (fqdn.charAt(0) == '.') || (fqdn.charAt(0) == '-') )
      return false;
    if ( fqdn.charAt(i) == '.' )
      i=i-1;

    for( ; i>=0; i-- )
    {
      if ( fqdn.charAt(i) == '.' )
      {
        if ( iL < 2 && iC < 2 )
          return false;
        if ( fqdn.charAt(i-1) == '-' )
          return false;
        iC++;
        iL = 0;
        continue;
      }
      if ( isAlnum ( fqdn.charAt(i) ) )
      {
        iL++;
        continue;
      }
      if ( fqdn.charAt(i) == '-' )
      {
        if ( !iL )
          return false;
        iL++;
        continue;
      }
      return false;
    }

    if ( !iC || ( iL == 1 && iC < 2 ) || ( !iL && iC==1 ) ) {
      return false;
    }

    return true;

  }


  function checkHostname( hostname )
  {
    if ( hostname.charAt(0) == '[' )
    {
      if ( hostname.charAt(hostname.length-1) != ']' )
        return false;
      var ipnr = hostname.substring( 1, hostname.length -1 );
        return checkIpnr( ipnr );
    }

    if ( hostname.charAt(0) == '#' )
    {
      var nr = hostname.substring( 1, hostname.length );
        return checkNr( nr );
    }

    return checkFqdn( hostname );
  }


  function checkEmailAdr( address )
  {
    var status = true;
    var username = "";
    var hostname = "";

    if ( address.length < 8 )
      return false;

    var seperate = address.lastIndexOf("@");
    if ( seperate == -1 )
      return false;

    username = address.substring(0, seperate );
    if ( ! checkUsername( username, "<>()[],;:@\" " ) )
      return false;

    hostname = address.substring(seperate+1, address.length );
    if ( ! checkHostname( hostname ) )
      return false;

    return true;
  }


  function checkEmail( email, allowFullname )
  {
    var existFullname = false;
    var status = true;
    var fullname = "";
    var adress = "";
    if ( email.length < 8 )
      return false;
    var emailBegin = email.indexOf("<");
    var emailEnd = email.lastIndexOf(">");

    if ( (emailBegin == -1) && (emailEnd == -1) )
      return checkEmailAdr( email );

    if ( ( (emailBegin == -1) && (emailEnd != -1) )
        || ( (emailBegin != -1) && (emailEnd == -1) ) )
      return false;

    adress = email.substring( emailBegin+1, emailEnd );

    if ( ! checkEmailAdr( adress ) )
      return false;

    if ( email.length == adress.length + 2 )
      return true;
    else
      if ( ! allowFullname )
        return false;

    if ( emailEnd == email.length - 1 )
    {
      if ( emailBegin == 0 )
        return true;
      if ( email.charAt( emailBegin -1 ) != ' ' )
        return false;
      fullname = email.substring( 0, emailBegin-1 );
      return checkUsername ( fullname, "<>()[],;:@\"" );
    }

    return false ;

  }


  function checkMendatoryInput(field) {
	if((typeof field === "undefined") || (field == null) || (field.length == 0)){
		return false;
	} else {
		return true;
	}

  }

  function checkMendatorySelect(field) {
	if((typeof field === "undefined") || (field == null) || (field == 0)){
		return false;
	} else {
		return true;
	}

  }
  
  function setErrorStyle(domNode){
	domNode.setAttribute("class", "tx_ddcodex_pi1_regform_error");
	domNode.className = "uzin_dialogs_error";	
  }

  function setNormalStyle(domNode){
	domNode.setAttribute("class", "tx_ddcodex_pi1_regform_normal");	
	domNode.className = "uzin_dialogs_normal";	
  }
  

// Base64 Decode
// --------------------------------------------
function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";


   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

