function ValidateForm (currentTabId) { var errorMsg = ''; var notFilledRequiredFields = CheckRequiredFields (currentTabId); var notValidFilledFieds = CheckFields (currentTabId); var translates = { 'js_fill_required_fields' : 'Täytä seuraavat pakolliset kentät', 'js_fill_valid_fields' : 'Virhe kentässä/kentissä' }; if (notFilledRequiredFields) { //Required errorMsg = translates.js_fill_required_fields + ":\n"; errorMsg = errorMsg + notFilledRequiredFields.substr(0, notFilledRequiredFields.length - 2) + "\n\n"; } if (notValidFilledFieds) { //Valid errorMsg = errorMsg + translates.js_fill_valid_fields + ":\n"; errorMsg = errorMsg + notValidFilledFieds.substr(0, notValidFilledFieds.length - 2) + "\n\n"; } if (currentTabId == 'confirm') { if (!document.getElementById('id_confirm').checked) { alert (translates.js_contract_not_confirmed); return false; } } if (errorMsg) { alert (errorMsg); return false; }else{ return true; } } function CheckRequiredFields (tabId) { var tab = document.getElementById(tabId); var errorFields = ''; var elms = tab.getElementsByTagName("*"); for(var i = 0, maxI = elms.length; i < maxI; ++i) { var elm = elms[i]; if (IsVisible(elm)) { switch(elm.type) { case "text": case "textarea": case "hidden": case "select-one": case "select-multiple": case "password": case "file": if (elm.getAttribute('required') == 1 && elm.value == '') { errorFields = errorFields + elm.title + ', '; } break; case "checkbox": if (elm.getAttribute('required') != null && elm.getAttribute('required').substr(0, 1) == 1 && !elm.checked) { errorFields = errorFields + elm.title + ', '; } break; case "button": case "reset": case "submit": case "image": case "radio": } } } return errorFields; } function IsVisible (elem) { return elem.style.display!="none"; } function CheckFields (tabId) { var tab = document.getElementById(tabId); var errorFields = ''; var elms = tab.getElementsByTagName("*"); for(var i = 0, maxI = elms.length; i < maxI; ++i) { var elm = elms[i]; if (elm.value != '' && IsVisible(elm)) { switch(elm.name) { case 'email': if (!IsValidEmail(elm.value)) { errorFields = errorFields + elm.title + ', '; } break; } } } return errorFields; } function ShowField (elemId) { ShowElement (elemId); ShowElement ('fs_' + elemId); //fieldset area } function HideField (elemId) { HideElement (elemId); HideElement ('fs_' + elemId); //fieldset area } function ShowElement (elemId) { if (document.getElementById(elemId)) { document.getElementById(elemId).style.display = ''; } } function HideElement (elemId) { if (document.getElementById(elemId)) { document.getElementById(elemId).style.display = 'none'; } } function GetElemValue (elemId) { if (document.getElementById(elemId)) { return document.getElementById(elemId).value; } } function ShowPopup (page, width, height) { if (!width) width='600px'; if (!height) height = '800px'; var newWindow = window.open ('?action=show_popup&page=' + page, 'newWindow', 'width=' + width + ', height=' + height + ', scrollbars=yes'); newWindow.focus(); } function FillField (targetId, sourceIds) { var value = ''; for (var i in sourceIds) { var elemId = sourceIds[i]; if (document.getElementById(elemId)) { var elem = document.getElementById(elemId); value = value + elem.value + ' '; } } if (value) { if (document.getElementById(targetId)) { document.getElementById(targetId).value = value.substr(0, value.length - 1); } } } function IsValidEmail (email){ var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i if (filter.test(email)){ return true; }else{ return false; } } function CalcCheckLetter(num){ var rivi = "0123456789ABCDEFHJKLMNPRSTUVWXY"; return rivi.substring(num % 31, num % 31 +1); } function IsDate(val,format) { var date=getDateFromFormat(val,format); if (date==0) { return false; } return true; } function compareDates(date1,dateformat1,date2,dateformat2) { var d1=getDateFromFormat(date1,dateformat1); var d2=getDateFromFormat(date2,dateformat2); if (d1==0 || d2==0) { return -1; } else if (d1 > d2) { return 1; } return 0; } function formatDate(date,format) { format=format+""; var result=""; var i_format=0; var c=""; var token=""; var y=date.getYear()+""; var M=date.getMonth()+1; var d=date.getDate(); var E=date.getDay(); var H=date.getHours(); var m=date.getMinutes(); var s=date.getSeconds(); var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k; // Convert real date parts into formatted versions var value=new Object(); if (y.length < 4) {y=""+(y-0+1900);} value["y"]=""+y; value["yyyy"]=y; value["yy"]=y.substring(2,4); value["M"]=M; value["MM"]=LZ(M); value["MMM"]=MONTH_NAMES[M-1]; value["NNN"]=MONTH_NAMES[M+11]; value["d"]=d; value["dd"]=LZ(d); value["E"]=DAY_NAMES[E+7]; value["EE"]=DAY_NAMES[E]; value["H"]=H; value["HH"]=LZ(H); if (H==0){value["h"]=12;} else if (H>12){value["h"]=H-12;} else {value["h"]=H;} value["hh"]=LZ(value["h"]); if (H>11){value["K"]=H-12;} else {value["K"]=H;} value["k"]=H+1; value["KK"]=LZ(value["K"]); value["kk"]=LZ(value["k"]); if (H > 11) { value["a"]="PM"; } else { value["a"]="AM"; } value["m"]=m; value["mm"]=LZ(m); value["s"]=s; value["ss"]=LZ(s); while (i_format < format.length) { c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } if (value[token] != null) { result=result + value[token]; } else { result=result + token; } } return result; } function _isInteger(val) { var digits="1234567890"; for (var i=0; i < val.length; i++) { if (digits.indexOf(val.charAt(i))==-1) { return false; } } return true; } function _getInt(str,i,minlength,maxlength) { for (var x=maxlength; x>=minlength; x--) { var token=str.substring(i,i+x); if (token.length < minlength) { return null; } if (_isInteger(token)) { return token; } } return null; } function getDateFromFormat(val,format) { val=val+""; format=format+""; var i_val=0; var i_format=0; var c=""; var token=""; var token2=""; var x,y; var now=new Date(); var year=now.getYear(); var month=now.getMonth()+1; var date=1; var hh=now.getHours(); var mm=now.getMinutes(); var ss=now.getSeconds(); var ampm=""; while (i_format < format.length) { // Get next token from format string c=format.charAt(i_format); token=""; while ((format.charAt(i_format)==c) && (i_format < format.length)) { token += format.charAt(i_format++); } // Extract contents of value based on format token if (token=="yyyy" || token=="yy" || token=="y") { if (token=="yyyy") { x=4;y=4; } if (token=="yy") { x=2;y=2; } if (token=="y") { x=2;y=4; } year=_getInt(val,i_val,x,y); if (year==null) { return 0; } i_val += year.length; if (year.length==2) { if (year > 70) { year=1900+(year-0); } else { year=2000+(year-0); } } } else if (token=="MMM"||token=="NNN"){ month=0; for (var i=0; i11)) { month=i+1; if (month>12) { month -= 12; } i_val += month_name.length; break; } } } if ((month < 1)||(month>12)){return 0;} } else if (token=="EE"||token=="E"){ for (var i=0; i12)){return 0;} i_val+=month.length;} else if (token=="dd"||token=="d") { date=_getInt(val,i_val,token.length,2); if(date==null||(date<1)||(date>31)){return 0;} i_val+=date.length;} else if (token=="hh"||token=="h") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<1)||(hh>12)){return 0;} i_val+=hh.length;} else if (token=="HH"||token=="H") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<0)||(hh>23)){return 0;} i_val+=hh.length;} else if (token=="KK"||token=="K") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<0)||(hh>11)){return 0;} i_val+=hh.length;} else if (token=="kk"||token=="k") { hh=_getInt(val,i_val,token.length,2); if(hh==null||(hh<1)||(hh>24)){return 0;} i_val+=hh.length;hh--;} else if (token=="mm"||token=="m") { mm=_getInt(val,i_val,token.length,2); if(mm==null||(mm<0)||(mm>59)){return 0;} i_val+=mm.length;} else if (token=="ss"||token=="s") { ss=_getInt(val,i_val,token.length,2); if(ss==null||(ss<0)||(ss>59)){return 0;} i_val+=ss.length;} else if (token=="a") { if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";} else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";} else {return 0;} i_val+=2;} else { if (val.substring(i_val,i_val+token.length)!=token) {return 0;} else {i_val+=token.length;} } } // If there are any trailing characters left in the value, it doesn't match if (i_val != val.length) { return 0; } // Is date valid for month? if (month==2) { // Check for leap year if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year if (date > 29){ return 0; } } else { if (date > 28) { return 0; } } } if ((month==4)||(month==6)||(month==9)||(month==11)) { if (date > 30) { return 0; } } // Correct hours value if (hh<12 && ampm=="PM") { hh=hh-0+12; } else if (hh>11 && ampm=="AM") { hh-=12; } var newdate=new Date(year,month-1,date,hh,mm,ss); return newdate.getTime(); } function StripSignStr(s) { var nosign, i; if (s != '') { nosign = ''; for (i = 0; i < s.length; i++) { if (s.substr(i,1) != '-') { nosign = nosign + s.charAt(i) ; } } return nosign; } return ''; } var tabIds = new Array ('tab1'); var elemOrigHTML = new Array; var stepImgs = new Array (); function Tabbar (imgDir, formTarget) { var currentTabId; this.imgDir = imgDir; this.formTarget = formTarget; this.Show = Show; this.Hide = Hide; this.HideAllTabs = HideAllTabs; this.Next = Next; this.Prev = Prev; this.SetActive = SetActive; this.SetClass = SetClass; this.SetInnerHTML = SetInnerHTML; this.SetFocusToFirstElement = SetFocusToFirstElement; this.GetTabObject = GetTabObject; this.GetFirstTabId = GetFirstTabId; this.GetTabIndex = GetTabIndex; this.GetTabId = GetTabId; function Show (tabId) { this.HideAllTabs (); var tab = this.GetTabObject(tabId); //tab.style.display = ''; $("#"+tabId).show(); this.SetActive(tabId); this.SetFocusToFirstElement(tabId); } function Hide (tabId) { var tab = this.GetTabObject(tabId); tab.style.display = 'none'; } function HideAllTabs () { if (tabIds.length > 1) { for (var i = 0; i < tabIds.length; i++) { this.Hide(tabIds[i]); this.SetClass ('a_' + tabIds[i], 'steps'); this.SetInnerHTML (tabIds[i], 'disable'); $("#a_"+tabIds[i]).parent().removeClass('active'); //Bootstrap } } } function Next () { switch (this.currentTabId) { case 'tab11': xajax_XajaxFillSummary(xajax.getFormValues('id_frm_dlpm')); break; default:break; } var currentTabIndex = this.GetTabIndex (this.currentTabId); var nextTabId = this.GetTabId (currentTabIndex + 1); if (nextTabId) { if (isNextAllowed) { this.Show(nextTabId); } }else{ DisableBtn('next'); var form = document.getElementById("id_frm_dlpm"); if (this.formTarget == 'newWindow') { form.setAttribute ('target', 'newWindow'); form.submit(); newWindow.focus(); }else{ form.setAttribute ('target', this.formTarget); form.submit(); } } } function Prev () { HideElement ("errorMsg"); if (this.currentTabId == 'tab3') { if (GetCookie('top_view_exists') == '1' && GetCookie('product_view') == 'base') { xajax_XajaxResetRcrProducts(null, 'top_product', GetElemValue('id_location')); return true; } } var currentTabIndex = this.GetTabIndex (this.currentTabId); var prevTabId = this.GetTabId (currentTabIndex - 1); if (prevTabId) { this.Show(prevTabId); }else{ var backUrl = ''; if (backUrl) { window.location = backUrl; }else{ history.back(); } } } function SetActive (tabId) { this.currentTabId = tabId; // save to global variable if (tabIds.length > 1) { $("#a_"+tabId).addClass('stepsActive'); $("#a_"+tabId).parent().addClass('active'); //Bootstrap this.SetInnerHTML (tabId, 'active'); } } function SetInnerHTML (tabId, state) { var tabIndex = this.GetTabIndex(tabId); var imgFileName = tabIndex+'_'+state+'.png'; var imgSrc = this.imgDir+'/'+imgFileName; var imgExists = false; var elem = document.getElementById('a_' + tabId); if (!elemOrigHTML[tabIndex]) { elemOrigHTML[tabIndex] = elem.innerHTML; } for (i=0; i < stepImgs.length; i++) { if (stepImgs[i] === imgFileName) { imgExists = true; } } if (imgExists) { elem.innerHTML = ''; }else{ elem.innerHTML = elemOrigHTML[tabIndex]; } } function SetFocusToFirstElement (tabId) { if (document.getElementById(tabId)) { var tab = document.getElementById(tabId); var elms = tab.getElementsByTagName("*"); for(var i = 0, maxI = elms.length; i < maxI; ++i) { var elm = elms[i]; if (elm.type == 'text') { if (elm.value == '') { elm.focus(); return true; } } } } } function SetClass (elemId, className) { var elem = this.GetTabObject(elemId); if (elem != null) { elem.className = className; } } function GetTabObject (tabId) { return document.getElementById(tabId); } function GetFirstTabId () { return tabIds[0]; } function GetTabIndex (tabId) { for (var i = 0; i < tabIds.length; i++) { if (tabIds[i] == tabId) { return i; } } return false; } function GetTabId (tabIndex) { for (var i = 0; i < tabIds.length; i++) { if (i == tabIndex) { return tabIds[i]; } } return false; } }