//Submit form without confirmation
function submitForm(option){
	document.getElementById('option').value = option;
	document.getElementById('form').submit();
}

//Submit form to specific action
function submitFormTo(action){
	document.getElementById('form').action = action;
	document.getElementById('form').submit();
}

//Submit form with confirmation
function submitConfirmForm(option, caption){
	caption = caption.replace("[return]", "\n");
	var agree=confirm(caption);
	if (agree){
		document.getElementById('option').value = option;
		document.getElementById('form').submit();
	}
}

//Activate SEO settings
function activateSeoSettings(caption){
	caption = caption.replace("[return]", "\n");
	var personalize = document.getElementById('personalize').checked;
	if(personalize == false){
		alert(caption);
	}
	if(personalize == true){
		document.getElementById('option').value = 'personalize';
		document.getElementById('form').submit();
	}
}

//Activate template
function activateTemplate(caption){
	caption = caption.replace("[return]", "\n");
	var personalize = document.getElementById('personalize').checked;
	if(personalize == false){
		alert(caption);
	}
	if(personalize == true){
		document.getElementById('option').value = 'personalize';
		document.getElementById('form').submit();
	}
}

//Change visibility for payment methods
function switchPayMethode(elementid){
	obj = document.getElementById(elementid);
	if (obj.options[obj.selectedIndex].value == 'ID') {
		document.getElementById('field_ideal').style.display = "block";
		document.getElementById('field_credit_card').style.display = "none";
	} else if (obj.options[obj.selectedIndex].value == 'CC') {
		document.getElementById('field_ideal').style.display = "none";
		document.getElementById('field_credit_card').style.display = "block";
	} else {
		document.getElementById('field_ideal').style.display = "none";
		document.getElementById('field_credit_card').style.display = "none";
	}
}

//Save job changes
function confirmEditJob(websiteid, action, job){
	document.getElementById('websiteid').value = websiteid;
	document.getElementById('userid').value = '';
	document.getElementById('option').value = job;
	document.getElementById('download').value = '';
	document.getElementById('filename').value = '';
	document.getElementById('form').action = action;
	document.getElementById('form').submit();
}

//Ask permission to delete job
function confirmDeleteJob(caption){
	caption = caption.replace("[return]", "\n");
	var agree=confirm(caption);
	if (agree){
		document.getElementById('option').value = 'delete';
		document.getElementById('download').value = '';
		document.getElementById('filename').value = '';
		document.getElementById('form').action = '';
		document.getElementById('form').submit();
	}
}

//Ask permission to stop tracking
function confirmStopTrack(caption){
	caption = caption.replace("[return]", "\n");
	var agree=confirm(caption);
	if (agree){
		document.getElementById('option').value = 'stop-tracker';
		document.getElementById('form').action = '';
		document.getElementById('form').submit();
	}
}

//Change visibility of elements to select or enter countries
function changeCountryCodeOptions(countrycodeid, divid, countryid) {
	if(document.getElementById(countrycodeid).value=='XX'){
		document.getElementById(divid).style.display = 'block';
	} else {
		document.getElementById(divid).style.display = 'none';
		document.getElementById(countryid).value = '';
	}
}

//Swich visibility between parts of the form
function switchVisibility(elementid, blockelemetid){

	//Show the selected element id
	changeVisibility(elementid);

	//Check if string ends on delimiter
	if(blockelemetid.endswith != ","){blockelemetid = blockelemetid+',';}

	//Create array of id's
	var count = 0;
	var temparray = Array();
	var delimiter = ',';
	while (blockelemetid.indexOf(delimiter)>0) {

		//Get element from delimiter and add it to array
		elementfound = blockelemetid.substr(0,blockelemetid.indexOf(delimiter));
		if (elementfound!=null){
			temparray[count] = elementfound;
			blockelemetid = blockelemetid.substr(blockelemetid.indexOf(delimiter)+1,blockelemetid.length-blockelemetid.indexOf(delimiter)+1);
			count = count + 1;
		}
	}

	//Hide all id's from array
	if (temparray!=null ){
    	for (i=0; i<temparray.length; i++) {
   			document.getElementById(temparray[i]).style.display = 'none';
    	}
	}
}

//Validate an url adress
function ValidateUrlLive(sourceid, targetid) {
	if (document.getElementById(sourceid).value.indexOf('.') < 0) {
		document.getElementById(targetid).style.color = "red";
	} else {
		document.getElementById(targetid).style.color = "";
	}
}

//Validate an email adress
function ValidateEmailLive(sourceid, targetid) {
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if (!pattern.test(document.getElementById(sourceid).value)) {
		document.getElementById(targetid).style.color = "red";
	} else {
		document.getElementById(targetid).style.color = "";
	}
}

//Validate a password
function ValidatePasswordLive(sourceid, targetid) {
	if (document.getElementById(sourceid).value.length < 4) {
		document.getElementById(targetid).style.color = "red";
	} else {
		document.getElementById(targetid).style.color = "";
	}
}

//Validate a value
function ValidateValueLive(sourceid, targetid) {
	if (document.getElementById(sourceid).value.length == 0) {
		document.getElementById(targetid).style.color = "red";
	} else {
		document.getElementById(targetid).style.color = "";
	}
}