function ajax(inControl, inURL){
var xmlhttp = null;
document.body.style.cursor = 'wait';
if (window.XMLHttpRequest) { // Firefox, Opera, Safari och Netscape
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Internet Explorers olika versioner
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { alert("Din webbläsare stödjer inte Ajax"); }
}
}
if (xmlhttp){
var url = inURL
//xmlhttp.open("GET",url,false);
xmlhttp.open("POST",url,false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(null);
var docObj = document.getElementById(inControl);
/* Kontrollerar om vi ska skriva till value eller innerHTML */
with(docObj){
var objType = docObj.type;
switch(objType){
case "text":
case "button":
docObj.value = xmlhttp.responseText;
break;
default:
docObj.innerHTML = xmlhttp.responseText;
break;
}
}
xmlhttp.abort();
}
document.body.style.cursor = 'auto';
}
function isString(strValue){
return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));
}
function isNumber(strValue){
return (!isNaN(strValue) && strValue != '');
}
function isEmail(strValue){
var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
return (strValue != '' && objRE.test(strValue));
}
function skicka_epost(form, url, fel_id){
with(form){
isOkey = true;
errorTextArray = new Array();
errorText = '';
urlstring = '';
if(!isString(namn.value)){
errorTextArray.push('You have to fill in a name');
isOkey = false;
}else{
urlstring += '&namn='+namn.value;
}
urlstring += '&foretag='+foretag.value;
if(!isNumber(telefon.value)){
errorTextArray.push('Only digits allowed in phonenumber');
isOkey = false;
}else{
urlstring += '&telefon='+telefon.value;
}
if(epost.value != '' && !isEmail(epost.value)){
errorTextArray.push('Wrong email');
isOkey = false;
}else if(epost.value != '' && isEmail(epost.value)){
urlstring += '&epost='+epost.value;
}
if(meddelande.value == ''){
errorTextArray.push('You have to fill in a message');
isOkey = false;
}else if(meddelande.value != ''){
urlstring += '&meddelande='+escape(meddelande.value);
}
if(isOkey){
//alert(url+'templates/doMail.php?action=skicka'+urlstring);
//ajax('skicka_epost', url+'templates/doMail.php?action=skicka'+urlstring);
//document.location.href = 'http://www.wisesite2.se/kontakt-en/?action=skicka'+urlstring;
document.getElementById('action').value = 'skicka';
document.getElementById('form').submit();
}else{
i = 0;
while(i < errorTextArray.length){
errorText += errorTextArray[i] + '
';
i++;
}
document.getElementById(fel_id).innerHTML = '
'+errorText+'
'; } } } function skicka_bokning(form, url, fel_id){ with(form){ isOkey = true; errorTextArray = new Array(); errorText = ''; urlstring = ''; if(!isString(namn.value)){ errorTextArray.push('You have to fill in a name'); isOkey = false; }else{ urlstring += '&namn='+namn.value; } if(!isString(adress1.value)){ errorTextArray.push('Address 1 must exist'); isOkey = false; }else{ urlstring += '&adress1='+adress1.value; } if(adress2.value != ''){ urlstring += '&adress2='+adress2.value; } if(foretag.value != ''){ urlstring += '&foretag='+foretag.value; } if(!isNumber(telefon.value)){ errorTextArray.push('Only digits allowed in phonenumber'); isOkey = false; }else{ urlstring += '&telefon='+telefon.value; } if(epost.value != '' && !isEmail(epost.value)){ errorTextArray.push('Wrong email'); isOkey = false; }else if(epost.value != '' && isEmail(epost.value)){ urlstring += '&epost='+epost.value; }else if(epost.value == ''){ errorTextArray.push('Email must exist'); isOkey = false; } /*if(meddelande.value == ''){ errorTextArray.push('You have to fill in a message'); isOkey = false; }else if(meddelande.value != ''){}*/ if(meddelande.value != ''){ urlstring += '&meddelande='+escape(meddelande.value); } if(isOkey){ //alert(url+'templates/doMail.php?action=skicka'+urlstring); //ajax('skicka_epost', url+'templates/doMail.php?action=skicka'+urlstring); //document.location.href = 'http://www.wisesite2.se/kontakt-en/?action=skicka'+urlstring; document.getElementById('action').value = 'skicka'; document.getElementById('form').submit(); }else{ i = 0; while(i < errorTextArray.length){ errorText += errorTextArray[i] + ''+errorText+'
'; } } }