// JScript File

	/*<![CDATA[*/

    
// validation
    
    function addNewError(msg,input_element)
    {
       var error = [];
       error.input_element = input_element;
       error.msg = msg;
       errorArray.push(error);
    }
     
    function validateEmail(objValue)
    {
        var email = objValue.value;
        if(email === '') {return true;}
        var splitted = email.match("^(.+)@(.+)$");
        if(splitted === null)
        {
            addNewError(emailError,objValue); 
            return false;
        }
        if(splitted[1] !== null )
        {
          var regexp_user=/^\"?[\w-_\.]*\"?$/;
          if(splitted[1].match(regexp_user) === null) {return false;}
        }
        if(splitted[2] !== null)
        {
          var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
          if(splitted[2].match(regexp_domain) === null) 
          {
	        var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	        if(splitted[2].match(regexp_ip) === null) 
	        {
	        	addNewError(emailError,objValue);        
	            return false;
	        }

          }// if
          return true;
        }
        addNewError(emailError,objValue);
        return false;
    }
    function requiredInput(objValue,msg)
    {
     var ret = true;
     var val = objValue.value;
     val = val.replace(/^\s+|\s+$/g,"");//trim
        if(val.length === 0) 
        {
           addNewError(msg,objValue);  
           ret=false; 
        }//if 
    return ret;
    }
    
    function show_div_msg(msgstring)
    {
	    if(divname.length<=0) {return false;}

	    if(document.layers)
	    {
		    divlayer = document.layers[divname];
            if(!divlayer){return;}
		    divlayer.document.open();
		    divlayer.document.write(msgstring);
		    divlayer.document.close();
	    }
	    else
	    if(document.all)
	    {
		    divlayer = document.all[divname];
            if(!divlayer){return;}
		    divlayer.innerHTML=msgstring;
	    }
	    else
	    if(document.getElementById)
	    {
		    divlayer = document.getElementById(divname);
            if(!divlayer){return;}
		    divlayer.innerHTML =msgstring;
	    }
	    divlayer.style.visibility="visible";	
	    return false;
    }
    function div_clearmsg(msgs)
    {
        for(i=0, len = msgs.length; i<len ;i++)
        {
            show_div_msg("");
        }
    }
    function sb_div_showmsg(msgs)
    {
	    var whole_msg="<ul>\n";
	    var first_elmnt=null;
	    for(var m=0, len = msgs.length ;m < len ;m++)
        {
            if(null === first_elmnt)
            {
                first_elmnt = msgs[m].input_element;
            }
            whole_msg += "<li>" + msgs[m].msg + "</li>\n";
        }
	    whole_msg += "</ul>";
	    show_div_msg(whole_msg);
	    if(null !== first_elmnt)
        {
            first_elmnt.focus();
        }
    }
    function textCounter(field, countfield, maxlimit) 
    {
        if (field.value.length > maxlimit)
            {field.value = field.value.substring(0, maxlimit);}
        else 
           { countfield.value = maxlimit - field.value.length;}
    }
    //Server Communication
    function ReceiveServerData(arg)
    {
        document.getElementById('CommentView').removeChild(document.getElementById('loadingImage'));
        document.getElementById('CommentView').innerHTML = arg + document.getElementById('CommentView').innerHTML;
        Effect.ScrollTo('CommentView'); 
        document.getElementById('btnSend').disabled = false;
        return false;
    }
    
    function CallSrv(yourChoise)
    {
	document.getElementById('btnSend').disabled = true;
        this.divname = 'aspnetForm_errorloc';
        this.errorArray = [];
        var emailInput = document.getElementById('ctl00_ContentPlaceHolder1_Email');
        var nameInput = document.getElementById('ctl00_ContentPlaceHolder1_Name');
        var isMailValid = validateEmail(emailInput);
        var isNameEntered = requiredInput(nameInput,nameError);
        var isCommentEntered = requiredInput(document.getElementById('ctl00_ContentPlaceHolder1_CommentText'),commentError); 
        if ((isMailValid) && (isNameEntered) && (isCommentEntered))
        { 
            div_clearmsg(errorArray);   
            document.getElementById('CommentView').innerHTML =  '<img id=loadingImage src=slike/loading.gif alt=loading //>'+ document.getElementById('CommentView').innerHTML;
            CallServer(nameInput.value + '|'+ emailInput.value + '|'+ document.getElementById('ctl00_ContentPlaceHolder1_CommentText').value); 
        }
        else
        {
             sb_div_showmsg(errorArray);
        }
    }
