var maxOptions = 9;

/* ----------- STARTSEITE --------------- */

function clickJobs() {

	redirect("files/mFrage_Stellenausschreibung_Sales.pdf");
	return;

}	

function clickCreatePoll() {
	
		if (DetectMobileQuick()) {	
			redirect("createpoll.html");
			return;
		}
	
	 	Lightview.show({
    		href: 'createpoll.html',
    		rel: 'iframe',
    		title: 'Kostenlose SMS-Abstimmung erstellen',
    		options: {
      			width: 380,
				height: 700,
				overlayClose: false
    	}});

}	

function clickBackend() {
	
		window.location.href = "http://www.mfrage.de/backend";

}	

function clickAGB() {
	
		if (DetectMobileQuick()) {	
			redirect("agb.html");
			return;
		}	
	
	 	Lightview.show({
    		href: 'agb.html',
    		rel: 'iframe',
    		title: 'mFrage.de - AGB bzw. Nutzunngsbedingungen',
    		options: {
      			width: 380,
				height: 700,
				overlayClose: true
    	}});
}	

function clickFAQ() {
	
		if (DetectMobileQuick()) {	
			redirect("faq.html");
			return;
		}	
	
	 	Lightview.show({
    		href: 'faq.html',
    		rel: 'iframe',
    		title: 'mFrage.de - Fragen &amp; Antworten',
    		options: {
      			width: 380,
				height: 700,
				overlayClose: true
    	}});
}	

function clickKontakt() {
	
		if (DetectMobileQuick()) {	
			redirect("kontakt.html");
			return;
		}		
	
	 	Lightview.show({
    		href: 'kontakt.html',
    		rel: 'iframe',
    		title: 'mFrage.de - Kontakt',
    		options: {
      			width: 380,
				height: 700,
				overlayClose: true
    	}});
}	

function clickPreise() {
	
		if (DetectMobileQuick()) {	
			redirect("preise.html");
			return;
		}		
	
	 	Lightview.show({
    		href: 'preise.html',
    		rel: 'iframe',
    		title: 'mFrage.de - Preise',
    		options: {
      			width: 577,
				height: 700,
				overlayClose: true
    	}});
}	

/* ----------- CREATE POLL --------------- */

var options = 2;
var datasend = false;

function cleanInput(input) {
	if(input.value.startsWith('z.B.')) {
		input.value="";
	}
	input.style.color="black";	
	return true;
}

function addOption() {
	if (options>=maxOptions) {
		alert("Mehr als 9 Optionen sind mit diesem Generator nicht moeglich. Bitte kontaktieren Sie das mFrage-Team (info@mfrage.de) fuer SMS-Abstimmungen mit mehr als 9 Optionen.");
		return;
	}
	options++;
	$("opt"+options).style.display="block";
}

function remOption(opt) {
	
	for (var i=(opt+1); i<=options; i++) {
		$("opt"+(i-1)+"_val").value = $("opt"+i+"_val").value;		
	}
	
	$("opt"+options).style.display="none";
	$("opt"+options+"_val").value="";
	options--;	

}

function checkForm() {
		
	/* -- FRAGE -- */
	
	if ($('question').value.startsWith('z.B.')) {
		alert("Bitte geben sie eine Frage fuer die Abstimmung ein.");
		return false;
	}
	
	/* -- OPTIONEN -- */	
	
	var optionsOK = true;
	if ($('opt1_val').value.startsWith('z.B.')) { optionsOK=false; }	
	if ($('opt2_val').value.startsWith('z.B.')) { optionsOK=false; }	
	if ($('opt1_val').value.trim()=="") { optionsOK=false; }			
	if ($('opt2_val').value.trim()=="") { optionsOK=false; }	
	if (!optionsOK) {
		alert("Bitte tragen sie Werte in alle Antwortfelder ein.");
		return false;		
	}
	
	/* -- AGBs -- */	
	
	if(!$('agb').checked) {
		alert("Bitte stimmen sie noch den AGBs zu.");
		return false;
	}	
	
	$('button_submit').value="Bitte warten ...";
	$('button_submit').disabled=true;	
		
	datasend = true;	
		
	return true;
} 

function closing() {
	if (datesend) {
		alert("Doing something");
	}
	alert("Doing something d");
}


function redirect(newPage){
	szURL = document.URL;
	componentList = szURL.split('/');
	newURL = componentList[0];
	for (i=1;i<(componentList.length - 1);i++) { newURL +=  "/"+componentList[i]; }
	newURL += "/"+newPage;
	window.location.href = newURL;
}


