// Title: Tigra Form Validator PRO
// URL: http://www.softcomplex.com/products/tigra_form_validator_pro/
// Version: 1.3
// Date: 04/05/2005 (mm/dd/yyyy)
// Notes: Registration needed to use this script legally. Visit official site for details.
var TV0=/^(\d{1,2})\-(\d{1,2})\-(\d{4})$/,TV1=/^(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/,TV2={'alpha':/^[a-zA-Z\.\-]*$/,'alphanum':/^\w+$/,'unsigned':/^\d+$/,'integer':/^[\+\-]?\d*$/,'real':/^[\+\-]?\d*\.?\d*$/,'email':/^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/,'phone':/^[\d\.\s\-]+$/,'date':function(TV3){if(!TV0.test(TV3))return false;if(RegExp.$1>31||RegExp.$2>12)return false;var TV4=new Date(RegExp.$3,Number(RegExp.$2-1),RegExp.$1);if(TV4.getMonth()!=Number(RegExp.$2-1))return false;return true;},'time':function(TV6){if(!TV1.test(TV6))return false;if(RegExp.$1>23||RegExp.$2>59||RegExp.$3>59)return false;return true;}};function TV7(){this.alert=0;this.alert_class=[];this.to_disable=[];this.messages={'setup':['No form name passed to validator construction routine','No array of "%form%" form fields passed to validator construction routine','Form "%form%" can not be found in this document','Can not find area for error message box (id="error_%form%")','Incomplete "%n%" form field descriptor entry. Attribute "%attr%" is missing','Can not find form field "%n%" in the form "%form%"','Can not find label tag (id="%t%")','Can not verify match. Field "%m%" was not found'],'fill':['"%l%" je obvezno polje','"%v%" ni veljaven vnos za"%l%"','Value for "%l%" must be %mn% characters or more','Value for "%l%" must be no longer than %mx% characters','"%l%" must match "%ml%"'],'boxes':['<table cellpadding="0" cellspacing="0" border="0" width="100%">'+'<tr><td bgcolor="#CCCC33"><table cellpadding="15" cellspacing="1" border="0" width="100%">'+'<tr><td bgcolor="#FFFFCC" style="color: red;">%error%</td></tr>'+'</table></td></tr><tr><td height="10">&nbsp;</td></tr></table>','<table cellpadding="0" cellspacing="0" border="0" width="100%">'+'<tr><td bgcolor="#CCCC33"><table cellpadding="15" cellspacing="1" border="0" width="100%">'+'<tr><td bgcolor="#FFFFCC" style="color: green; font-weight: bold;">Posredujem podatke...</td></tr>'+'</table></td></tr><tr><td height="10">&nbsp;</td></tr></table>'],'confirm':['The "%form%" form is to be submitted. Are you sure?']}}function validator(TV8,TV9,TVA){this.TVB=TVC;var TVD=new TV7();TVE(TVA,TVD);this.TVA=TVD;this.TVF=TVD.alert;this.TVG=this.TVF&4?function(TVH){alert(TVH);return false}:function(){return false};this.TVI=TVD.alert_class;if(!TV8)return this.TVG(this.TVB('setup',0));this.TV8=TV8;if(!TV9||typeof(TV9)!='object')return this.TVG(this.TVB('setup',1));this.TV9=TV9;this.TVJ=TVD.to_disable;this.exec=TVK;}function TVK(){var TVL=document.forms[this.TV8];if(!TVL)return this.TVG(this.TVB('setup',2));var TVM=TVN('error_'+this.TV8),TVO=document.body&&document.body.innerHTML;if((this.TVF&2)||(this.TVF&8)){if(TVO&&!TVM)return this.TVG(this.TVB('setup',3));if(TVO){TVM.style.display='none';TVM.innerHTML='';}}var TVP=['l'];for(var TVQ in this.TV9){this.TV9[TVQ]['n']=TVQ;for(TVR in TVP)if(!this.TV9[TVQ][TVP[TVR]])return this.TVG(this.TVB('setup',4,this.TV9[TVQ],{'attr':TVP[TVR]}));TVS=TVL.elements[TVQ];if(!TVS)return this.TVG(this.TVB('setup',5,this.TV9[TVQ]));this.TV9[TVQ].TVS=TVS;}if(TVO)for(var TVQ in this.TV9)if(this.TV9[TVQ]['t']){var TVT=this.TV9[TVQ]['t'],TVU=TVN(TVT);if(!TVU)return this.TVG(this.TVB('setup',6,this.TV9[TVQ]));this.TV9[TVQ].TVV=TVU;TVU.className=this.TVI[1];}for(var TVQ in this.TV9){TVS=this.TV9[TVQ].TVS;this.TV9[TVQ]['v']=null;if(TVS.type=='checkbox'){if(TVS.checked&&TVS.value)this.TV9[TVQ]['v']=TVS.value;}else if(TVS.value)this.TV9[TVQ]['v']=TVS.value;else if(TVS.options&&TVS.selectedIndex>-1)this.TV9[TVQ]['v']=TVS.options[TVS.selectedIndex].value;else if(TVS.length>0)for(var TVW=0;TVW<TVS.length;TVW++)if(TVS[TVW].checked){this.TV9[TVQ]['v']=TVS[TVW].value;break;}}var TVX=0,TVY,TVZ,TV_,TVa;for(var TVQ in this.TV9){TVb=this.TV9[TVQ];TV_=TVb['f']?(TV2[TVb['f']]?TV2[TVb['f']]:TVb['f']):null;TVa=(TV_+'').indexOf('function')>-1;TVb.TVc=null;if(TVb['r']&&!TVb['v']){TVb.TVc=1;TVX++;}else if(TVb['mn']&&String(TVb['v']).length<TVb['mn']){TVb.TVc=3;TVX++;}else if(TVb['mx']&&String(TVb['v']).length>TVb['mx']){TVb.TVc=4;TVX++;}else if(TV_&&((TVa&&(TVY=TV_(TVb['v'],TVL))!=true)||(!TVa&&TVb['v']&&!TV_.test(TVb['v'])))){TVb.TVc=typeof(TVY)!='string'?2:TVY;TVX++;}else if(TVb['m']){for(var TVd in this.TV9)if(TVd==TVb['m']){TVZ=TVd;break;}if(TVZ==null)return this.TVG(this.TVB('setup',7,TVb));if(this.TV9[TVZ]['v']!=TVb['v']){TVb['ml']=this.TV9[TVZ]['l'];TVb.TVc=5;TVX++;}}}var TVe='',TVf='',TVg;if(TVX){for(var TVQ in this.TV9){var TVh=this.TV9[TVQ].TVc,TVi='';if(TVh){TVi=this.TVB('fill',TVh-1,this.TV9[TVQ]);if(!TVi)TVi=TVh;}if(TVi){if(!TVg)TVg=TVL.elements[TVQ];TVe+=TVi+'<br>';TVf+=TVi+"\n";if(TVO&&this.TVI&&this.TV9[TVQ].TVV)this.TV9[TVQ].TVV.className=this.TVI[0];}}TVe=this.TVB('boxes',0,{'error':TVe});if(typeof(this.TVF)!='function'){if(this.TVF&1)alert(TVf);if(TVO&&(this.TVF&2)){TVM.innerHTML=TVe;TVM.style.display='block';}if(TVg.focus&&TVg.type!='hidden')TVg.focus();return false;}}if(typeof(this.TVF)=='function')return this.TVF(TVf,TVe,TVM);else{if((this.TVF&16)&&!confirm(this.TVB('confirm',0)))return false;if(TVO&&(this.TVF&8)){TVM.innerHTML=this.TVB('boxes',1);TVM.style.display='block';}for(TVQ in this.TVJ){var TVj=TVN(this.TVJ[TVQ]);if(TVj&&TVj.disabled!=null)TVj.disabled=true;}}return true;}function TVE(TVk,TVl){for(var TVm in TVk)if(TVk[TVm]!=null){if(typeof(TVk[TVm])=='object'){if(typeof(TVl[TVm])!='object')alert("Type mismatch ("+TVm+"). Array in place of scalar.");TVE(TVk[TVm],TVl[TVm]);}else{if(typeof(TVl[TVm])=='object')alert("Type mismatch ("+TVm+"). Scalar in place of array.");TVl[TVm]=TVk[TVm];}}}function TVC(TVn,TVW){var TVm=this.TVA.messages[TVn][TVW],TVo=2,TVp;if(!TVm)return false;if(typeof(TVm)=='function')TVm=TVm(this.TV8);for(;TVo<arguments.length;TVo++)for(TVp in arguments[TVo])TVm=TVm.replace('%'+TVp+'%',arguments[TVo][TVp]);TVm=TVm.replace('%form%',this.TV8);return TVm}function TVN(TVq){return(document.all?document.all[TVq]:(document.getElementById?document.getElementById(TVq):null));}

function anything(Value)
{
	return true;
}
function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original:  Torsten Frey (tf@tfrey.de) -->
<!-- Web Site:  http://www.tfrey.de -->

function check_date(DateValue){
var checkstr = "0123456789";
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
     return true;
   }
   /* Error-message if err != 0 */
   else {
   	return false;
   }
}
// form fields description structure
var a_fields = {
	'naziv':{'l':'Naziv','r':true,'f':anything,'t':'t_naziv'},
	'naslov':{'l':'Naslov','r':true,'f':anything,'t':'t_naslov'},
	'eposta':{'l':'E-mail','r':true,'f':'email','t':'t_email'},
	'telefon':{'l':'Telefon','r':true,'f':anything,'t':'t_telefon'},
	'posta':{'l':'Posta','r':true,'f':anything,'t':'t_posta'}
}

var o_config = {
	'to_disable' : ['Submit', 'Reset'],
	// 1 - fill error dialog,
	// 2 - fill error HTML box,
	// 4 - debug alert,
	// 8 - submit ok HTML box
	// 16 - submit confirmation dialog,
	// function - custom function(array of messages)
	'alert' : 2 + 8,
	'alert_class' : ['inputHighlighted', 'inputNormal']
}

