function gecerliEposta(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){return false;}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if (str.indexOf(at,(lat+1))!=-1){return false;}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if (str.indexOf(dot,(lat+2))==-1){return false;}
	if (str.indexOf(" ")!=-1){return false;}
	return true;					
}

function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
}

function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){ 
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;
}

function adreseGit(adres){
	window.location.href = adres;
}

function yazdir(){
	window.print();
}

function favorilerimeEkle() {
	url=document.location.href;
	title=document.title;
	if (window.sidebar){ window.sidebar.addPanel(title, url,""); }
	else if( window.external ) { window.external.AddFavorite( url, title); }
}

function karakterKontrol(id,span,limit){
	
	
	var textLength=$("#"+id).attr("value").length;
	
	var text=$("#"+id).val();

	var result=limit-textLength;

	if (textLength>limit-1){

		var newText=text.substr(0,limit);

		$("#"+id).val(newText);

	}

	$("#"+span).html(result);
	
}


function pausecomp(millis){
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); }
	while(curDate-date < millis);
}

/* Error div functions */
$(document).ready(function(){

/* Error Div Back Set */
	var doHeight=$(document).width();
	var scWidth=$(window).width();
	var scHeight=$(window).height();
	var eDivWidth= $("#errorDiv").width();
	var eDivHeight= $("#errorDiv").height();	
	var eDivLeft=(scWidth-eDivWidth)/2;
	var eDivTop=(scHeight-eDivHeight)/2;
	
	$("#errorBackDiv").css("height",doHeight).css("width",scWidth);
	$("#errorDiv").css("top",eDivTop+'px').css("left",eDivLeft+'px');
	
	$(".formSubmit").click(function(){
		$("#formSabit").submit();
	});
	
	$('.sehirSec').change(function() {
						
		var ilceSec = $(this).attr('ilceSec');
		var semtSec = $(this).attr('semtSec');
		var secID 	= $(this).attr('secID');
		var yukleID = $(this).attr('yukleID');
				
		$("#"+semtSec).empty().append('<option value="">Seçiniz</option>');		
		$("#"+ilceSec).empty();
		
		$.ajax({
			type: "POST",
			url: SiteAdi + '?p=ilceYukle&sehirID='+$(this).val(),
			success: function(msg){
				
				$("#"+ilceSec).append(msg);
				
				var data = $('#'+ilceSec).html();
				var selected = '';
				
				var semtSec	= $('#'+ilceSec).attr('semtSec');
				var id 		= $('#'+ilceSec).attr('id');
				var name 	= $('#'+ilceSec).attr('name');				
				var yukleID	= $('#'+ilceSec).attr('yukleID');
								
				if ( $('#'+ilceSec).attr('secID') != undefined ){
					selected = 'secID = "' + $('#'+ilceSec).attr('secID') + '"';
				}
				
				$('#'+yukleID).html('<select semtsec="' + semtSec + '" id="' + id + '" name="' + name + '" yukleID="' + yukleID + '" class="ilceSec" '+ selected + ' >' + data + '</select>');
				
				if (secID){
					$("#"+ilceSec).val(secID);
				}
				
				$('#' + ilceSec).selectbox();
				
				var data2 = $('#'+semtSec).html();
				var selected2 = '';
				
				var id2 		= $('#'+semtSec).attr('id');
				var name2 		= $('#'+semtSec).attr('name');				
				var yukleID2	= $('#'+semtSec).attr('yukleID');							
				
				if ( $('#'+semtSec).attr('secID') != undefined ){
					selected2 = 'secID = "' + $('#'+semtSec).attr('secID') + '"';
				}
				
				$('#' + yukleID2 ).html('<select id="' + id2 + '" name="' + name2 + '" yukleID = "' + yukleID2 + '" class="semtSec" '+ selected + '>' + data2 + '</select>');				
				$('#' + semtSec).selectbox();
				
				$('#' + ilceSec).bind('change', function() {
					
					var semtSec = $(this).attr('semtSec');
					var secID = $(this).attr('secID');
					var id2 		= $('#'+semtSec).attr('id');
					var name2 		= $('#'+semtSec).attr('name');				
					var yukleID2	= $('#'+semtSec).attr('yukleID');					
					
					$.ajax({
						type: "POST",
						url: SiteAdi + '?p=semtYukle&ilceID='+$(this).val(),
						success: function(msg){
							$("#"+semtSec).empty().append(msg);													
							var data = $('#'+semtSec).html();				
							$('#'+yukleID2).html('<select id="' + id2 + '" name="' + name2 + '" yukleID = "' + yukleID2 + '" class="semtSec">' + data + '</select>');
							if (secID){
								$("#"+semtSec).val(secID);
							}
							$('#' + semtSec).selectbox();
						}
					});					
				});
				
				if ( selected ){
					$('#' + ilceSec).change();
				}
			}
		});
	});	
});


function errorDivStart(message){
	setTimeout("errorDivShow('"+message+"')",500);
}

function errorDivShow(message){
	$("#errorMain").html(message);
	$("#errorBackDiv").show();
	$("#errorDiv").fadeIn("slow");	
	setTimeout("errorDivHide()",2000);
	
}

function errorDivHide(){
	$("#errorDiv").fadeOut("slow");
	$("#errorBackDiv").hide();
}

function selectYukle(url,loadID,secID,divID){	
	$("#"+loadID).empty();
	$.ajax({
		type: "POST",
		url: SiteAdi + url,
		success: function(msg){
			$("#"+loadID).append(msg);			
			if (secID){				
				$("#"+loadID).val(secID);
			}					
		}
	});
}
