
function formCheck() 
{
    if(document.kayit_formu.txtAd.value=='') 
    {
        alert('Please enter your name.');
        document.kayit_formu.txtAd.focus();
        return false;
    }
    if(document.kayit_formu.txtSoyad.value=='') 
    {
        alert('Please enter your surname.');
        document.kayit_formu.txtSoyad.focus();
        return false;
    }
    if(document.kayit_formu.txtEposta.value=='') 
    {
        alert('Please enter your e-mail.');
        document.kayit_formu.txtEposta.focus();
        return false;
    }
    if(document.kayit_formu.txtMesaj.value=='') 
    {
        alert('Please enter your message.');
        document.kayit_formu.txtMesaj.focus();
        return false;
    }
    if((document.kayit_formu.txtEposta.value!='') && (emailCheck(stringTrim(document.kayit_formu.txtEposta.value))==false)) 
    {
        alert('Please check your e-mail.');
        document.kayit_formu.txtEposta.focus();
        return false;
    }
    document.kayit_formu.action='mesaj_kaydet.asp';
    document.kayit_formu.submit();
}

function stringTrim(str) 
{
	var i;
	bos = new RegExp(" ", "g")

	if(str.replace(bos, "")=="") 
		return "";

	//left trim
	i = 0
	while(str.charAt(i)==" " && i<str.length) 
		++i;
	if(i<str.length) 
		str = str.substring(i);

	//right trim
	i = str.length-1
	while(str.charAt(i)==" " && i>=0) 
		--i;
	if(i>=0) 
		str = str.substring(0, i+1)
		
	return str;
}

function emailCheck(str) 
{
	var	i, ch;
	if(str.length==0)
		return(false);
	
	//check for invalid chars
	for(i=0;i<str.length;i++) {
		if(
			(str.charCodeAt(i)<48 || str.charCodeAt(i)>57)  &&   // "0"-"9" 'un disinda ise
			(str.charCodeAt(i)<64 || str.charCodeAt(i)>90)  &&   // "@" ve "A"-"Z" disinda ise
			(str.charCodeAt(i)<97 || str.charCodeAt(i)>122)  &&  // "a"-"z" disinda ise			
			(str.charCodeAt(i)<45 || str.charCodeAt(i)>46)  &&   // "-" ve "." disinda ise						
			(str.charCodeAt(i)!=95)                              // "_" dan farkli ise
		) 
		return(false)	
	}

	if(str.length<5) return(false)
	if(str.indexOf(" ")>-1) return(false)
	if(str.indexOf(".")<1) return(false)  
	if(str.indexOf("@")<1) return(false)
	if(str.indexOf("@.")>-1) return(false)  
	if(str.indexOf("..")>-1) return(false)  
	if(str.indexOf("@")!=str.lastIndexOf("@")) return(false)  
	if(str.length-str.lastIndexOf(".")-1<=1) return(false)
		
	return(true)
}
