﻿function regKontrol(pattern, value) 
{ 
   r = new RegExp(pattern, "g"); 
   return r.test(value); 
} 

str_form_zorunlu_uyari=" ";
str_form_eposta_uyari=" ";
function formKontrolZorunlu(form_name,ad,alan) 
{ 
    document.getElementById("h"+ad).innerHTML = "";
    form = document.getElementById(form_name);
    for(i=0; i<=form.length-1; i++) {
        form.elements[i].style.backgroundColor='#FFFFFF';
	}

if (document.getElementById(ad).value==""){ 
	document.getElementById("h"+ad).innerHTML =alan + str_form_zorunlu_uyari;
	document.getElementById(ad).focus(); 
	document.getElementById(ad).style.background='#FFCCCC';
	return false; 
	}
	return true;
}
 
function formKontrol(form_name,ad,tur,alan) 
{ 
    document.getElementById("h"+ad).innerHTML = "";
    form = document.getElementById(form_name);
    for(i=0; i<=form.length-1; i++) {
        form.elements[i].style.backgroundColor='#FFFFFF';
	}
	if(tur=="sayi"){
	     patternEposta   = "^"+"([0-9\.]+)"+"$"; 
		 uyari=alan + str_form_fiyat_uyari
     }else if(tur=="sifre"){
	     patternEposta   = "^"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"$";            
	     uyari=str_form_sifre_uyari
     }else if(tur=="url"){
	     //patternEposta   = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";    
	     patternEposta   = "^(file|ldap|http|https|ftp)://(([-a-z0-9])+\.)+([a-z]{2,6}|([a-z/]+[a-z/]{2,6}))$";
	     uyari=str_form_url_uyari
     }else if(tur=="email"){
	     patternEposta   = "^"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"@"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"[\.]"+"([abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0-9_\.\-]+)"+"$"; 
	     uyari=str_form_eposta_uyari;
      }
     if ( !regKontrol(patternEposta,document.getElementById(ad).value)) 
     { 
	  	  
	  	  document.getElementById("h"+ad).innerHTML = uyari;
    	  

          document.getElementById(ad).focus(); 
          document.getElementById(ad).style.background='#FFCCCC';
          return false; 
     }
     return true; 
} 


function kontrol(form_adi){
	deger=formKontrolZorunlu(form_adi,'ADSOYAD','');
	if(!deger)
		return deger;
	deger=formKontrolZorunlu(form_adi,'TEL','');
	if(!deger)
		return deger;
	deger=formKontrol(form_adi,'EMAIL','email','');
	if(!deger)
		return deger;
	deger=formKontrolZorunlu(form_adi,'strCAPTCHA','');
	if(!deger)
		return deger;


	if(deger){
	document.getElementById(form_adi).submit();
	}
}


