$(document).ready(function() {
			
	$(document).keypress(function(e) 
	{ 
	    if(e.keyCode == 13)  
	    { 
	      if(document.getElementById('mypass').value!='')
	      {
	    	 kullanici_giris();
	      }//end if
	    }//end if 
	}); 
})
		
function kullanici_giris()
{
	if(trim(document.getElementById('myposta').value)=='')
	{
		alert('Lütfen e-mail adresinizi giriniz!');
		document.getElementById('myposta').focus();
	}//end if
	else if(trim(document.getElementById('mypass').value)=='')
	{
		alert('Lütfen şifrenizi giriniz!');
		document.getElementById('mypass').focus();
	}//end if
	else
	{
		var remember='H';
		/*
		if(document.getElementById('remember').checked)
		{
			remember='E';
		}//end if
		*/
		$.ajax
		({
		    type: 'POST',
		    url: SITE_URL + 'ajax/uye-giris.php',
		    data: 'email=' + escape(document.getElementById('myposta').value) + '&sifre=' + escape(document.getElementById('mypass').value) + '&remember=' + remember,
		    success: function(data) 
		    {
		      var returnData=data.split('|');

		      if(returnData[0]=='success')
		      {
		      	if(typeof returnData[2]!='undefined')//cookie set edelim
		      	{
		      		var cookieData=returnData[2].split(':');
		      		setCookie(cookieData[0],cookieData[1],30);
		      	}//end if
		      	
		      	window.location=returnData[1];
		      }//end if
		      else if (returnData[0]=='warning')
		      {
		      	jQuery.fn.colorbox({width:'40%', inline:true, overlayClose:false, href:'#uye_giris_overlay'});
		      }
		      else
		      {
		      	$('#tr_err').css('display','');
	          	$('#td_err').html(returnData[1]);
		      }//end else
		    }
	  	});
	}//endelse
}//end function kullanici_giris

$(document).ready(function() {initMenu();});

function initMenu() 
{
  $('#menu li a').click(function() {
  	$(this).next().slideToggle('normal');
  });
    
  $('#uyelik li a').click(function() {
  	$(this).next().slideToggle('normal');
  });
}//end function initMenu

function set_overlay_link(clasname,omode,odelay)
{
	if(omode=='fadein')
	{
		$('.' + clasname).delay(odelay).fadeIn();
	}//end if
	else
	{
		$('.' + clasname).css('display','');
	}//end else
}//end function set_overlay_link

function submit_filter(formname)
{
	if(formname==undefined)
	{
		formname='masterform';
	}//end if
	
	var inputs=$("#" + formname+ " :input");
	inputs.each(function() 
	{
		var inputClass=$(this).attr('class');
		if(inputClass.indexOf('myfilter')==-1)
		{
			$(this).attr('disabled','true');
		}//end if	
	});
	
	document.masterform.method='get';
	document.masterform.submit();
}//end function submit_filter

function call_gridview_command_page(sender,ajax_url,ajax_type,ajax_data,onsuccess,confirm_text,errdiv)
{
	var parent = $('#' + sender).parent('td').parent('tr');
	
	if(confirm_text=='delete')
	{
		confirm_text='Seçtiğiniz kaydı silmek istediğinize emin misiniz?';
	}//end if
	else if(confirm_text=='state')
	{
		confirm_text='Seçtiğiniz kaydın durumunu(aktif/pasif) değiştirmek istediğinize emin misiniz?';
	}//end elseif
	else if(confirm_text=='onay')
	{
		confirm_text='Seçtiğiniz kaydı onaylamak istediğinize emin misiniz?';
	}//end elseif
	else if(confirm_text=='iptal')
	{
		confirm_text='Seçtiğiniz kaydı iptal etmek istediğinize emin misiniz?';
	}//end elseif
	else if(confirm_text=='arsiv')
	{
		confirm_text='Seçtiğiniz kaydı arşivlemek istediğinize emin misiniz?';
	}//end elseif
	
	if(confirm(confirm_text))
	{
		$.ajax
		({
		    type: ajax_type,
		    url: ajax_url,
		    data: ajax_data,
		    beforeSend:function() {
		    	$("#loading").show(); 
		    },
		    success: function(data) 
		    {
		      	var returnData=data.split('|');

		      	if(returnData[0]=='success')
		      	{
		      	  if(onsuccess=='fadeout')
			      {
			      	  parent.fadeOut('slow',function() 
				      {
			          	parent.remove();
			          });
			      }//end if
			      else if(onsuccess=='redirect')
			      {
			      		window.location=location.href;
			      }//end else
			      else if(onsuccess=='redirect_tab')
			      {
			      		if(location.href.indexOf('ctab')<0)
			      		{
				      		if(location.href.indexOf('?')>0)
				      		{
				      			window.location=location.href + '&ctab=' + document.getElementById('ctab').value;
				      		}//end if
				      		else
				      		{
				      			window.location=location.href + '?ctab=' + document.getElementById('ctab').value;
				      		}//end else
			      		}//end if
			      		else
			      		{
			      			window.location=location.href;
			      		}//end else
			      }//end else
			      else if(onsuccess=='alert')
			      {
		      			window.location=location.href;
			      }//end else
		      	}//end if
		      	else
		      	{
		      		var parent_errdiv='parent_warning';
		      		if(errdiv==undefined)
		      		{
		      			errdiv='warning';
		      		}//end if
		      		else
		      		{
		      			var parent_errdiv='parent_' + errdiv;
		      		}//end else
		      		
		      		$('#' + parent_errdiv).css('display','block');
		          	$('#' + errdiv).html(returnData[1]);
		      	}//end else
		    }
	  	});
	}//end if
}//end function call_gridview_command_page

function call_combobox_engine(sender,target,map,type,asenkronize)
{
	var options = '';
	
	if(asenkronize==undefined)
	{
		asenkronize=true;
	}//end if 
	
	$.ajax
	({
   		type: 'POST',
   		url: SITE_URL + 'combobox-engine.php',
   		data: sender + '=' + $('#' + sender).val() + '&map=' + map + '&type=' + type,
   		dataType: 'json',
   		async:asenkronize, 
   		beforeSend:function() {
		   	$("select#" + target).html("<option value=''>Lütfen Bekleyiniz...</option>"); 
		},
   		success: function(jsonData,jsonStatus)
   		{
   			 try
   			 { 
	   			 $.each(jsonData, function()
	   			 {
	   			 	options += "<option value='" + this.optionValue + "'>" + this.optionDisplay + "</option>";	
	             });
   			 }
   			 catch(err){}

             $('select#' + target).html(options);
   		},
   		error:function(xhr, ajaxOptions, thrownError)
   		{
   			alert('XHR:' + xhr.status + ' => ERROR:' + thrownError); 
   		}
 	});	
}//end function call_combobox_engine

function reset_depent_combobox_option(target,option_label)
{
	 var depent_options = "<option value=''>"+ option_label + "</option>";	
	 $('select#'+target).html(depent_options); 
}//end function reset_depent_combobox_option
	
function valid_keys(e, keys)
{
	var key, keychar,valids;

	key = getkey(e);
	
	if (key == null) 
	{
		return true;
	}//end if
	
	//get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	valids = keys.toLowerCase();
	
	//check valid keys
	if (valids.indexOf(keychar) != -1)
	{
		return true;
	}//end if
	
	//control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27)
	{
	   return true;
	}//end if
	
	return false;
}//end function valid_keys

function invalid_keys(e, keys)
{
	var key, keychar,invalids;

	key = getkey(e);
	
	if (key == null) 
	{
		return true;
	}//end if
	
	//get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	invalids = keys.toLowerCase();
	
	//check invalid keys
	if (invalids.indexOf(keychar) != -1)
	{
		return false;
	}//end if
	
	return true;
}//end function invalid_keys

function getkey(e)
{
	if (window.event)
	{
	   return window.event.keyCode;
	}//end if
	else if (e)
	{
	   return e.which;
	}//end elseif
	else
	{
	   return null;
	}//end else
}//end function getkey

function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,'');
}//end function trim

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value) +  ";expires="+exdate.toUTCString();
}//end function 

function getCookie(c_name)
{
	  if (document.cookie.length>0)
	  {
	  	c_start=document.cookie.indexOf(c_name + "=");
	  	if (c_start!=-1)
	    {
		    c_start=c_start + c_name.length+1;
		    c_end=document.cookie.indexOf(";",c_start);
		    if (c_end==-1) c_end=document.cookie.length;
		    
		    alert (unescape(document.cookie.substring(c_start,c_end)));
	    }//end if
	  }//end if
	  
	return "";
}//end function 
