// JavaScript Document
function ajx(sPage,action,id,type,veri)
{
	//alert('Page : '+sPage+' action: '+action+' id: '+id+' type: '+type+' veri: '+veri);
    var myRandom=parseInt(Math.random()*99999999);
	load_on();
	$.ajax({
    url: sPage,
    type: 'POST',
    dataType: 'html',
    timeout:60000,
    data: "action="+action+"&rand="+myRandom+'&'+veri,
    error: function(){
        alert('Bir Hata Oluştu Lütfen Yöneticiyi Uyarınız');
		load_off();
    },
    success: function(html){
        if (type=='hide')
        {
            $("#"+id).hide("slow");
            $("#"+id).html(html);
            $("#"+id).show("slow");
        }
        else if (type=='fade')
        {
            $("#"+id).fadeOut("slow",function(){
            $("#"+id).html(html);
            });
            $("#"+id).fadeIn("slow");
        }
        else if (type=='toggle')
        {
            $("#"+id).slideToggle("slow",function(){
            $("#"+id).html(html);
            });
        }
        else if (type=='fadeto')
        {
            $("#"+id).fadeTo("slow",0.3);    
            $("#"+id).html(html);
        }
        else if (type=='down')
        {
            $("#"+id).slideDown("slow",function(){
            $("#"+id).html(html);
            });
        }
        else if (type=='up')
        {
            $("#"+id).slideUp("slow",function(){
            $("#"+id).html(html);
            });
        }
        else if (type=='css')
        {
            $("#"+id).css();
        }

		load_off();
    }
    });

}

function load_on() 

{
    var width_cont = document.documentElement.scrollWidth;
    var height_cont = document.documentElement.scrollHeight;
    var div = document.createElement('DIV');
    div.id = 'loading';
    div.style.width = width_cont;
    div.style.height = height_cont;
    div.style.filter = 'Alpha(opacity = 30)';
    div.style.position = 'absolute';
    div.style.left = '0';
    div.style.top = '0';
    document.body.appendChild(div);
    var div = document.createElement('DIV');
    div.id = 'bekle';
    div.style.width = '200';
    div.style.height = '48';
    div.style.position = 'absolute';
    div.style.left = 500+"px";
    div.style.top = 600+"px";
	//div.style.background="#069";
    div.innerHTML = '<img src="img/loading.gif" /> Lütfen Bekleyiniz...';
    document.body.appendChild(div);

}

function load_off()
{
	var div = document.getElementById('bekle');
	document.body.removeChild(div);
	var div = document.getElementById('loading');
	document.body.removeChild(div);
}

function formVeri(fname)
{
	var x=document.getElementById(fname);
	var str="";
	for (var i=0;i<x.length;i++)
	{
			//alert(x.elements[i].type+'  '+x.elements[i].name+'  '+x.elements[i].value);
	   if((str!="")&&(x.elements[i-1].type!='radio')) str=str+"&";
	   if (x.elements[i].type!='radio')
	   {
	   		str=str+x.elements[i].name.substring(2)+"="+x.elements[i].value;
	   }
	   else
	   {
		   if(x.elements[i].checked)
		   	str=str+x.elements[i].name.substring(2)+"="+x.elements[i].value+"&";	
		   }
	}
	return str;
}

function checkform(fname)
{
    var formvalues = validate(fname);
    if (formvalues)
    {
		//alert(formVeri(fname));
        return formVeri(fname);
    }   else 
        {
            return false; 
        }
}

function validate(fname)
{
	var tform = document.getElementById(fname);
	for (i=0;i<tform.length;i++) {
		var tempobj=tform.elements[i];
			if (tempobj.name.substring(0,2) == 'n_' && tempobj.value == '' ) {
					tempobj.style.border = '1px solid #FF0000';
					tempobj.focus();
					return false;
			}
			else if (tempobj.name.substring(0,2) == 'n_' && tempobj.value != '' )
			{
				//alert(tempobj.name);
				if (tempobj.name == 'n_email')
				{
						apos = tempobj.value.indexOf('@');
						dotpos = tempobj.value.lastIndexOf('.');
						if (apos<1||dotpos-apos<2 || tempobj.value.length <= dotpos+1)
						{
							tempobj.style.border = '1px solid #FF0000';
							tempobj.focus();
							return false;
						}
				}
				tempobj.style.border = '1px solid #DDDDDD';
			}
	}
	return true;
}
function resim_ac(resim,id)
{
	var div=document.getElementById(id);
	div.innerHTML='<img src="'+resim+'">';
}
