// JavaScript Document
function ChangeSrc(s) {
document.pic.src="pics/"+s+".jpg";	
}

function MsgLength() {
	document.form1.hm.value=1;
	if ((document.form1.msg.value.length<11)||(document.form1.msg.value.length>300))
	{
	   document.form1.hm.value=0;
 //      alert("The length of your message should be between 11 and 300 characters long! It is currently "+document.form1.msg.value.length+" characters.");
	}
}

function CheckEmail() {
	n=0; a=true; dot=true; dash=true; underscore=true; frbddn=false; t=0; pos=41; brt=0; tpos=0; fch=0; minl=0; tdom=0; tire=0; brtire=0; tirepos=0; brd=0; dpos=0; d=0;
	document.form1.he.value=0;
	l=document.form1.email.value.length;
	for (i=0; i<l; i++) { 
		if (!(((document.form1.email.value.charAt(i)>='a') && (document.form1.email.value.charAt(i)<='z')) || 
((document.form1.email.value.charAt(i)>='A') && (document.form1.email.value.charAt(i)<='Z')) ||
((document.form1.email.value.charAt(i)>='0') && (document.form1.email.value.charAt(i)<='9')) ||
(document.form1.email.value.charAt(i)=='@') || (document.form1.email.value.charAt(i)=='.') || (document.form1.email.value.charAt(i)=='-') || (document.form1.email.value.charAt(i)=='_'))) { //dopustimi simwoli: a-z;A-Z;0-9;@;.;-;_
			fch=1; break;
		}
		if (l<6) { //e-maila min 6 simwola
			minl=1; break;
		}
		if (document.form1.email.value.charAt(i)=='@') {
			n=n+1; pos=i;
		}
		if (document.form1.email.value.charAt(i)=='.') {
			brt=brt+1; tpos=i;
			
			if ((document.form1.email.value.charAt(i-1)=='-')||(document.form1.email.value.charAt(i-1)=='_')||(document.form1.email.value.charAt(i+1)=='-')||(document.form1.email.value.charAt(i+1)=='_')) {
				frbddn=true; break;
			}
			
			if (t==0) {
				t=1;
			}
			else {
				t=1;
				break; //kraj t->1
			}
		} //end if .
		else {
			   t=0;
			  }
			  if (document.form1.email.value.charAt(i)=='.') {
			brt=brt+1; tpos=i;
		}
		if (document.form1.email.value.charAt(i)=='-') {
			brtire=brtire+1; tirepos=i;
			
if ((document.form1.email.value.charAt(i-1)=='_')||(document.form1.email.value.charAt(i+1)=='_')) {
				frbddn=true; break;
			}
			
			if (tire==0) {
				tire=1;
			}
			else {
				tire=1;
				break; //kraj tire->1
			}
		} //end if .
		else {
			   tire=0;
			  }	
		if (document.form1.email.value.charAt(i)=='_') {
			brd=brd+1; dpos=i;
			if (d==0) {
				d=1;
			}
			else {
				d=1;
				break; //kraj tire->1
			}
		} //end if .
		else {
			   d=0;
			  }		  
	} //end for		
			if ((tpos==(l-3))||(tpos==(l-4))||(tpos==(l-5))) { //last dot in position l-3;l-4 or l-5, t.e. top level domain 2-4 characters
			tdom=1;
		}
	if ((n>1)||(n==0)||(pos==0)) { //0 || >1 @
		a=false;
	}
	if (brt==0) {
		dot=false;
	}
	if (t==1) { //sysedni . || krajna .
		dot=false;
	}
		if (tire==1) { //sysedni - || krajno -
		dash=false;
	}
			if (d==1) { //sysedni _ || krajno _
		underscore=false;
	}
		if ((document.form1.email.value.charAt(pos+1)=='.')||(document.form1.email.value.charAt(pos+1)=='-')||(document.form1.email.value.charAt(pos+1)=='_')||(document.form1.email.value.charAt(pos-1)=='.')||(document.form1.email.value.charAt(pos-1)=='-')||(document.form1.email.value.charAt(pos-1)=='_')||(document.form1.email.value.charAt(0)=='.')||(document.form1.email.value.charAt(0)=='-')||(document.form1.email.value.charAt(0)=='_')) { // @. || .@ || .111111@11111.111
			dot=false;
		}
		if (tpos<pos) {
			dot=false;
		}
	if ((a)&&(dot)&&(dash)&&(underscore)&&(!(frbddn))&&(fch==0)&&(minl==0)&&(tdom==1)) {
		document.form1.he.value=1;
	}
//	alert("question "+document.form1.hm.value+" email "+document.form1.he.value);
} //end function

function CheckPh()
{
// --- START PROVERKA TELEFON ---
t=1;
d1=document.form1.ph.value.length;
     	for(k1=0; k1<d1; k1++) {
		if ((document.form1.ph.value.charAt(k1)<"0")||(document.form1.ph.value.charAt(k1)>"9")){
			t=0;
			break;
		}//end if
	}//end for
	if (d1<5) {
                t=0;
               }
	document.form1.hph.value=t;
	//	alert("hph "+t);

//--- END PROVERKA TELEFON ---	
}
