var $j = jQuery.noConflict();
$j(document).ready(function(){
    
    $j('form#posfind').submit(formKontrol);
    
    $j('input#adres').focus();

});

function toolTip() 
{
	$j('div#orta-alt a').each(function(){
		var _this = $j(this);
		var _href = _this.attr('href');
		_this.removeAttr('title').attr('title', _href);
	});
}

function formKontrol() 
{
    var adres   = $j('input#adres').val();
    var kelime  = $j('input#kelime').val();
    var sonuc   = $j('select#sonuc').val();
    var lisan   = $j('select#lisan').val();
    var uid   = $j('input#uid').val();


    var http = new RegExp("^(http[s]?://)");

    if( http.test(adres) === false || adres === 'http://' ) {
        alert('Please enter "http://" to your URL !');
        $j('input#adres').focus();
        return false;
    }
    
    if( kelime.length < 3 ) {
        alert('Keyword must be at least 3 character-length!');
        $j('input#kelime').focus();
        return false;
    }
    
    $j('div#orta-alt div.kutu-ort').html('<p id="loading"></p>');
    $j('div#orta-alt').fadeIn('slow');
    $j('button#gonder').css('cursor','wait').attr('disabled','disabled');


    $j.ajax({


        type: 'POST',
        url: $j('form#posfind').attr('action'), /*http://www.googleposition.com/modules/mod_posfind/sonuc.php*/
        data: 'adres='+encodeURIComponent(adres)+'&kelime='+encodeURIComponent(kelime)+'&uid='+encodeURIComponent(uid)+'&sonuc='+encodeURIComponent(sonuc)+'&lisan='+encodeURIComponent(lisan),
        success: function(ajaxCevap){
            $j('div#orta-alt div.kutu-ort').html(ajaxCevap).fadeIn('slow');
            $j('button#gonder').css('cursor','pointer').removeAttr('disabled');
            toolTip();
        },
        error: function(){
            $j('div#iletisimSonuc').html('<p class="hata">An error occured. Please try again.</p>').fadeIn('slow');
            $j('button#gonder').css('cursor','pointer').removeAttr('disabled');
        }
    });

    return false;  
}

