function swapImg(on,img,name) { if(name == false) name = img; if(document.images) { var image = "/graphics/" + img + ((on)?'-over.gif':'.gif'); document.images[name].src= image; } } // - - - - - - - - - - - - - - - - - - - - - - - - // Lägg in annons var text = ""; var error = false; function frmAd() { error = false; if(document.frm.c_place.value == ""){ error = true; text += "Du har glemt og velge Region" + "\n"; return false; } if(document.frm.c_name.value == ""){ error = true; text += "Du har glemt og fylle inn ditt Navn" + "\n"; } if(document.frm.c_email.value == ""){ error = true; text += "Du har glemt og fylle inn E-postadressen" + "\n"; } else if(document.frm.c_email.value != "") { if(!document.frm.c_email.value.isValidEmail()) { error = true; text += "Din e-postadresse er inte gyldig, prøv igjen" + "\n"; } } if(document.frm.c_phone.value == ""){ error = true; text += "Du har glemt og fylle inn Telefon/mobilnummer" + "\n"; } if(document.frm.c_category.value == ""){ error = true; text += "Du har glemt og velge Kategori" + "\n"; } if(document.frm.c_headline.value == ""){ error = true; text += "Du har glemt og skrive en Annonstittel" + "\n"; } if(document.frm.c_year) { if(document.frm.c_year.value == ""){ error = true; text += "Velg år" + "\n"; } } if(document.frm.c_mile) { if(document.frm.c_mile.value == ""){ error = true; text += "Velg Km" + "\n"; } } if(document.frm.c_text.value == ""){ error = true; text += "Du har glemt og skrive en Beskrivelse" + "\n"; } if(document.frm.c_password.value == ""){ error = true; text += "Password is a mandatory field" + "\n"; }else if(document.frm.c_password.value != ""){ if(!(isValidString(document.frm.c_password.value))){ error = true; text += "Ditt passord inneholder ugyldige tegn." + "\n"; } } if(document.frm.c_password.value != document.frm.c_retype.value){ error = true; text += "Passordet stemmer ikke" + "\n"; } if(document.frm.c_password.value != ""){ if(document.frm.c_password.value.length < 5){ error = true; text += "Ditt passord er for kort (minst 5 tegn)" + "\n"; } if(document.frm.c_password.value.length > 10){ error = true; text += "Ditt passord er for långt (max 10 tegn)" + "\n"; } } if(error) { alert(text); text = ""; error=false; return false; } } // - - - - - - - - - - - - - - - - - - - - - - - - // Svara på annons function answerForm() { if(document.frm.c_name.value == ""){ text += "Du har glemt og fylle inn ditt Navn" + "\n"; error = true; } if(document.frm.c_email.value == ""){ text += "Du har glemt og fylle inn E-postadressen" + "\n"; error = true; } else if(document.frm.c_email.value != "") { if(!document.frm.c_email.value.isValidEmail()) { text += "Din e-postadresse er inte gyldig, prøv igjen" + "\n"; error = true; } } if(document.frm.c_subject.value == ""){ text += "Du har glemt og skrive en Annonstittel" + "\n"; error = true; } if(document.frm.c_text.value == ""){ text += "Du har glemt og skrive en Beskrivelse"; error = true; } if(error) { alert(text); text = ""; error=false; return false; } } // - - - - - - - - - - - - - - - - - - - - - - - - // Svara på annons function checkFile(obj) { if(obj.c_image.value != ""){ if(!obj.c_image.value.match(/(\.gif|\.jpg|\.png|\.jpe|\.jpeg)$/i)){ alert("Du kan bare laste opp bilder i følgende format: .jpg, .jpeg, .png, eller .gif."); return false; } return true; } } // - - - - - - - - - - - - - - - - - - - - - - - - // Funktion för att kontrollera epost String.prototype.isValidEmail = function(){ return !!this.match(/^([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})@([a-zA-Z0-9]{1}([a-zA-Z0-9\.\-\_]*)[a-zA-Z0-9]{1})\.([a-zA-Z]{2,4})$/) } function isValidString(string){ var validChars = "0123456789ABCDEFTGHIJKLMOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; var character; var valid = true; // test strString consists of valid characters listed above for (i = 0; i < string.length && valid == true; i++) { character = string.charAt(i); if (validChars.indexOf(character) == -1) { valid = false; } } return valid; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // function MaxLen(TA, Size) { if(TA.value.length > Size-1){TA.value = TA.value.substring(0, Size -1)} }