/*Javascript Library by anders.turesson@edgeguide.com. All rights reserved */ /* ****************************************************************** This is Edgeguide's standard javascript library. It should be used in all projects and it should be includen in all pages. Remove explanations from this file before implementing in for a customer. ****************************************************************** */ // Check for browser version var ie4 = (document.all) ? true : false; var ns4 = (document.layers) ? true : false; var ns6 = (document.getElementById && !document.all) ? true : false; //openWin function. Opens a popup window (no toolbars, menubar etc) // calling syntax: openWin('http://www.edgeguide.com','newwindowname',300,200,'yes') // yes makes the window scollable, no disables scrollbars function openWin(URL,name,width,height,scroll) { self.name = "main"; newWin = window.open(URL,name, 'width='+width+',height='+height+',status=no,toolbar=no,menubar=no,scrollbars='+scroll); newWin.focus(); } //popUp function. Opens a popup window with a message // calling syntax: popUp('Your message goes here','width=200,height=200,left=80,top=80,screenX=80,screenY=80') // where width and height is the size and left,top,screenX,screenY is the position of the popup window for both IE and NN function popUp(message,props) { msg=window.open('','msg',props); msg.document.write(' '); msg.document.write(''); msg.document.write(''); msg.document.write('',message,''); msg.document.write(''); } // Trims spaces from a textfield. Syntax: function trim(field) { while(''+field.value.charAt(0)==' ')field.value=field.value.substring(1,field.value.length); while(''+field.value.charAt(field.value.length-1)==' ')field.value=field.value.substring(0,field.value.length-1); } // HideLayer. Syntax: hidelayer('yourlayername') function hidelayer(lay) { if (ie4) {document.all[lay].style.visibility = "hidden";} if (ns4) {document.layers[lay].visibility = "hide";} if (ns6) {document.getElementById([lay]).style.display = "none";} } // ShowLayer. Syntax: hidelayer('yourlayername') function showlayer(lay) { if (ie4) {document.all[lay].style.visibility = "visible";} if (ns4) {document.layers[lay].visibility = "show";} if (ns6) {document.getElementById([lay]).style.display = "block";} } // WriteToLayer. Syntax: writetolayer('yourlayername','the text you want in the layer') function writetolayer(lay,txt) { if (ie4) { document.all[lay].innerHTML = txt; } if (ns4) { document[lay].document.write(txt); document[lay].document.close(); } if (ns6) { over = document.getElementById([lay]); range = document.createRange(); range.setStartBefore(over); domfrag = range.createContextualFragment(txt); while (over.hasChildNodes()) { over.removeChild(over.lastChild); } over.appendChild(domfrag); } } // Highlight a table row. IE only. Syntax hiLightTR(this,'#cccccc');" onMouseout="hiLightTR(this,'#ffffff');" function hiLightTR(tr, changeTo) { tr.className = changeTo; } // Expand layer in IE. If NS4, open remote controll window. // Syntax: expandIt('layername','remotecontrolurl,40,100') function expandIt(whichEl,URL,width,height) { if (ns4) {openWin(URL,'remotecontroll',width,height,'no');} else if (document.all[whichEl].style.display == "none") {document.all[whichEl].style.display = "";} else {document.all[whichEl].style.display = "none";} } // Show AltText for links. Make sure the following code is on the page: //
// Syntax: onMouseOver="showAlt('Some text','#cccccc','300')" onMouseOut="hideAlt()" var old,skn,iex=(document.all),yyy=-1000; function initAltText(xx,yy) { Xoffset=xx; Yoffset=yy; if (ns4) skn=document.AltText else if (ns6) skn=document.getElementById("AltText").style else if (ie4) skn=document.all.AltText.style if(ns4)document.captureEvents(Event.MOUSEMOVE); else{ skn.visibility="visible" skn.display="none" } document.onmousemove=get_mouse; } function showAlt(msg,bak,width){ var content="
"+msg+"
"; yyy=Yoffset; if(ns4){skn.document.write(content);skn.document.close();skn.visibility="visible"} if(ns6){document.getElementById("AltText").innerHTML=content;skn.display=''} if(ie4){document.all("AltText").innerHTML=content;skn.display=''} } function get_mouse(e){ var x=(ns4||ns6)?e.pageX:event.x+document.body.scrollLeft; skn.left=x+Xoffset; var y=(ns4||ns6)?e.pageY:event.y+document.body.scrollTop; skn.top=y+yyy; } function hideAlt(){ yyy=-1000; if(ns4){skn.visibility="hidden";} else if (ns6||ie4) skn.display="none" } // Hightligt text in a field and if IE, copy it to the clipboard // 0=no, 1=yes (Only for IE) var copytoclip=1 function HighlightAll(theField) { var tempval=eval("document."+theField) tempval.focus() tempval.select() if (document.all&©toclip==1){ therange=tempval.createTextRange() therange.execCommand("Copy") window.status="Texten är kopierad till urklipp" setTimeout("window.status=''",1800) } } // Set cookie // syntax: javascript:setCookie('anderskaka','dajm',365) function setCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)) var expires = "; expires="+date.toGMTString() } else expires = "" document.cookie = name+"="+value+expires+"; path=/" } // Get cookie // syntax: javascript:getCookie('anderskaka') function getCookie(name) { var nameEQ = name + "=" var ca = document.cookie.split(';') for(var i=0;i Field.lastIndexOf(".") || Field.indexOf(".") == -1 || Field.indexOf("@.") != -1 || Field.indexOf("@hotmai.") != -1 || Field.indexOf("@hotmil.") != -1) {return true;} } /*Validate if field is a Swedish phonenumber (2 to 4 digits-5 to 10 digits) */ function notPhone(Field, Optional) { if (Field == '' && Optional !==''){return false;} else phone2 = Field.split("-"); phone3 = phone2[0]; phone4 = phone2[1]; if (Field == ''|| Field.substring(0,1)!=='0' || Field.indexOf("-") == -1 || Field.indexOf("-") !== Field.lastIndexOf("-") || reNoDigits.test(phone3) || phone3.length < 2 || phone3.length > 4 || reNoDigits.test(phone4) || phone4.length < 5 || phone4.length > 10 ) {return true;} } /*Validate if field is a Swedish zip code (nnnnn) */ function notZipcode(Field, Optional) { if (Field == '' && Optional !==''){return false;} else if (Field.length !==5 || reNoDigits.test(Field)) {return true;} } /*Validate if field contains characters other than a-z, 0-9, _ - */ function notAlfaNumerial(Field, Optional) { if (reAlfaNumber.test(Field)|| Field == '' && Optional =='') {return true;} } /*Validate if field contains characters other than a-ö, 0-9, _ - */ function notSwedishAlfaNumerial(Field, Optional){ if (reAlfaNumberSwe.test(Field) || Field == '' && Optional =='') {return true;} } /*Validate if field is numeric */ function notNumber(Field, Optional) { if (reNoDigits.test(Field) || Field == '' && Optional =='') {return true;} } /*Validate if field is a correct date (åååå-mm-dd) */ function notDate(Field, Optional) { if (Field == '' && Optional !==''){return false;} else var strArray = Field.split("-"); stringyear = (strArray[0]); stringmonth = (strArray[1]); stringday = (strArray[2]); var numyear = parseFloat(strArray[0]); var nummonth = parseFloat(strArray[1]); var numday = parseFloat(strArray[2]); /* Kontroll av värden i formulär */ if (stringyear.length !==4 || stringmonth.length !==2 || stringday.length !==2 || nummonth > 12 || numday > 31) {return true;} } /*Validate if radiobutton or checkbox is checked */ function notChecked(Field) { if (!Field.length) {if (Field.checked==false ) {return true;}} else { var radioSelected = false; for (i = 0; i < Field.length; i++) { if (Field[i].checked) {radioSelected = true; radiovalue=Field[i].value;} } if (!radioSelected) {return true;} }} /*Validate Swedish personnummer (ååmmdd-nnnn) checknumber must bu right*/ function notPnumber(Field, Optional){ if (Field == '' && Optional !==''){return false;} else // figure out what the last digit is Original=Field Field=(Field.substring(0,6)+Field.substring(7,10)) var b=-1 var c=1 var klar=0 var sista=0 for(var d=1;d<=9;d++){ nu=0 b++ c++ nu=Field.charAt(b) nu=parseInt(nu) if(c==1){ klar+=nu } if(c==2){ nu=nu*c if(nu>=10){ nu=nu.toString() nu=nu.charAt(1) nu=parseInt(nu) nu=1+nu} nu=parseInt(nu) klar+=nu c=0 } } while(klar>=10){ klar-=10 } sista=10-klar Field=Field.substring(0,6)+'-'+Field.substring(6,9) if (sista=='10') {sista='0'} Field=Field+sista // Do all the if statments if(Field.length !== 11 || Field.substring(6,7)!="-" || reNoDigits.test(Field.substring(0,6)+Field.substring(7,12)) || Field !== Original){return true;} } /*Check if person is too old based on birthdate*/ function isTooOld(Field, Optional, Age) { if (notDate(Field, Optional)){return true;} else if (Optional ==''){ var AgeArray = Field.split("-"); var ageyear = parseFloat(AgeArray[0]); var agemonth = parseFloat(AgeArray[1]); var ageday = parseFloat(AgeArray[2]); if (year-Age > ageyear || year-ageyear == Age && month > agemonth || year-ageyear == Age && agemonth == month && day < ageday) {return true;}} } /*Check if person is too young based on birthdate*/ function isTooYoung(Field, Optional, Age) { if (notDate(Field, Optional)){return true;} else if (Optional ==''){ var AgeArray = Field.split("-"); var ageyear = parseFloat(AgeArray[0]); var agemonth = parseFloat(AgeArray[1]); var ageday = parseFloat(AgeArray[2]); if (year-Age < ageyear || year-ageyear == Age && month < agemonth || year-ageyear == Age && agemonth == month && day < ageday) {return true;}} } /*Validate if filename contains characters other than a-z, 0-9, _ - . */ function notGoodFileName(Field, Optional) { pos = Field.lastIndexOf( '\\' ) ; tot = Field.length; filename = Field.substr( pos+1, tot ); if (reFileName.test(filename)|| filename == '' && Optional =='') {return true;} }