var orjContent = "";
var newCustomerId = 0;
var realCustomerId = 0;

//var base = document.location.toString().indexOf("localhost")*1<0?"/":"duyurumatik/";

function ClearText(){	
	$('#txtgsmno').val('');
	$('#txtcontrolno').val('');
	$('#txtBusName').val("");
	$("#txtTaxOffice").val("");
	$("#txtTaxNo").val("");
	$("#txtAuthPerName").val("");
	$("#txtAuthPerSurname").val("");
	$("#txtAuthPerEmail").val("");
	$("#txtAuthName").val("");
	$("#txtAuthSurname").val("");
	$("#txtAuthEmail").val("");
	$("#txtAdress").val("");
	$("#drpCITY").val(-1);
}
function ControlGSM(cgsm)
{
    var sgsm = "";
      
 	if (cgsm == "" || cgsm.length < 2)
        sgsm = $.trim(cgsm);
    if (cgsm.substring(0, 2) == "90")
    	sgsm = $.trim(cgsm);
    else if (cgsm.substring(0, 1) == "0")
      	sgsm = "9"+$.trim(cgsm);
    else
    	sgsm = "90"+$.trim(cgsm);
      
    var sfirstfour = sgsm.substring(0, 4);
      if (sgsm.length != 12 || (sfirstfour != "9050" && sfirstfour != "9053" && sfirstfour != "9054" && sfirstfour != "9055"))
      {
          return "Girilen GSM No hatalı bulundu!";
      }
      return "";
}

function linkClose(){
	$('#tableProducts').html(orjContent);
}
function Kapat()
{
	$('#divarkaplan2').hide();
	$('#divgeneral').hide();
}
function Kapat2()
{
	var bReturn = confirm("İletişim Bilgilerini Kaydetmediğiniz İçin 25 kontör kazanamayacaksınız!");
	if(bReturn)
	{
		$('#divarkaplan1').hide();
		$('#divgeneral').hide();
	}
}
function InsertNewRecord(_step){
	switch(_step){
		case 1:
			$.ajax(
				{
					type		: "POST",
					url			: "index.php/sisteme-kayit-ol",
					data		: "",
					dataType	: "html",	
					success		: function(data){
						ClearText();
						var nleft = (screen.width - 758) / 2;
						$('#divarkaplan2').show().css({"height":$(document).height()});
						$('#divgeneral').show();
						$('#divgeneral').html(data).css('left',nleft);
						$('#divGSM').show();
						$('#divControlGSM').hide();
						$('#divCustomerInfo').hide();
						$('#divCong').hide();		
						
						window.setTimeout(function(){
							$('#radTip0').bind("click",function(){
								$('#divPer').fadeOut(150,function(){
									$('#divBus').fadeIn(150);
								});
								$.each($(':input'),function(i,v){
									SetInputClass($(v).attr("id"),false);
								});
							});
							$('#radTip1').bind("click",function(){
								$('#divBus').fadeOut(150,function(){
									$('#divPer').fadeIn();
								});
								$.each($(':input'),function(i,v){
									SetInputClass($(v).attr("id"),false);
								});
							});
							$('#login_form').formtooltip();
						},500);
					},
				error		: function(event, request, settings){
					}
				}
			);
		break;
	}
}

function InsertNewRecordOperations(_step){
	
	$('#spn1').hide();
	$('#spn2').hide();
	$('#spn3').hide();
	switch(_step){
		case 1:
			var formSend = true;
			var formParams = [];
			var errorDesc = [];
			var _id= "";
			// ortak kontroller
			
			// gsmno
			var p1 = $.trim($('#txtgsmno').val());
			_id = 'txtgsmno';
			if(p1=="" || p1.length<10 || ControlGSM(p1) !=""){
				formSend = false;
				SetInputClass(_id,true);
				errorDesc.push("Gsm Numarası eksik veya hatalı");
			} else {
				formParams.push("gsm="+p1);
				SetInputClass(_id,false);
				$('#txtgsmno').css({backgroundColor:"#fff"});
			}	
			if(formSend){
				$('#spn1').show();
				// ajax post
				$.ajax(
					{
						type		: "POST",
						url			: "index.php/sisteme-kayit-ol-islemler",
						data		: formParams.join("&"),
						dataType	: "json",	
						success		: function(_response){
							$('#spn1').hide();
							if(_response.rcode == "00"){
								if(_response.rdata!=0){
										newCustomerId = _response.rdata;								
										$('#divGSM').hide();
										$('#divControlGSM').show();
										$('#divCustomerInfo').hide();
										$('#divCong').hide();
								} else{
									alert('Günlük işlem hakkınız bitmiştir.');
								}
							} else {
								$('#a1').hide();
								$('#a2').show().bind("click",function(){
									RetrySendSMS(_response.rdata);
								});
							}
						},
						error		: function(event, request, settings){
						}
					}
				);
				
				
			} else {
				alert(errorDesc.join("\n"));
			}
		break;
		case 2:
			var formSend = true;
			var formParams = [];
			var errorDesc = [];
			var _id= "";
			// ortak kontroller
			
			// gsmno
			var p1 = $.trim($('#txtcontrolno').val());
			_id = 'txtcontrolno';
			if(p1=="" || p1.length<10){
				formSend = false;
				SetInputClass(_id,true);
				errorDesc.push("Kontrol Numarası hatalı");
			} else {
				formParams.push("controlcode="+p1);
				formParams.push("precustomerid="+newCustomerId);
				formParams.push("gsm="+$.trim($('#txtgsmno').val()));
				
				SetInputClass(_id,false);
				$('#txtcontrolno').css({backgroundColor:"#fff"});
			}
			if(formSend){
				$('#spn2').show();
				// ajax post
				$.ajax(
					{
						type		: "POST",
						//url			: "pages/controlsecuritycode.php",
						url 		: "index.php/sisteme-kayit-ol-guvenlik-kodu-kontrol",
						data		: formParams.join("&"),
						dataType	: "json",	
						success		: function(_response){
							$('#spn2').hide();
							if(_response.rcode == "00"){
								$responsearr = _response.rdata.split('|');					
								if($responsearr.length >1 && $responsearr[0] != "") {						
									realCustomerId = $responsearr[1];
									$('#txtusercode').val($.trim($('#txtgsmno').val()));
									$('#txtpassword').val($responsearr[0]);
									$('#divGSM').hide();
									$('#divControlGSM').hide();
									$('#divCustomerInfo').show();
									$('#divCong').hide();
									$('#divarkaplan1').css({"height":$(document).height()});
								} else{
									alert("Hatalı Kod Girdiniz");
								}
							} else{
								alert(_response.rdata);
							}
						},
						error		: function(event, request, settings){
							
						}
					}
				);
			} else {
				alert(errorDesc.join("\n"));
			}
			break;
		case 3:
			var formSend = true;
			var formParams = [];
			var errorDesc = [];
			var _id= "";
			// ortak kontroller	
			formParams.push("customerid="+newCustomerId);
			formParams.push("realcustomerid="+realCustomerId);	
			var p1 = $.trim($('#txtgsmno').val());
			_id = 'txtgsmno';
			if(p1=="" || p1.length<10){
				formSend = false;
				SetInputClass(_id,true);
				errorDesc.push("Gsm Numarası eksik veya hatalı");
			} else {
				formParams.push("gsm="+p1);
				SetInputClass(_id,false);
				$('#txtgsmno').css({backgroundColor:"#fff"});
			}
			// adres
			p1 = $.trim($('#txtAdress').val());
			_id = 'txtAdress';
			if(p1=="" || p1.length<5){
				formSend = false;
				SetInputClass(_id,true);
				errorDesc.push("Adres alanı 5 karakterden az olamaz");
			} else {
				SetInputClass(_id,false);
				formParams.push("adr="+p1);
			}
			// city
			p1 = $('#drpCITY').val();
			_id = 'drpCITY';
			if(p1<0){
				formSend = false;
				SetInputClass(_id,true);
				errorDesc.push("Şehir seçmelisiniz");
			} else {
				formParams.push("city="+p1);
				SetInputClass(_id,false);
			}
			// ayrı kontroller
			var radC = $('#radTip0').attr("checked");
			if(radC){
				formParams.push("reqtype=1");
				p1 = $.trim($('#txtBusName').val());
				_id = 'txtBusName';
				if(p1=="" || p1.length<5){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Şirket ünvanı 5 karakterden az olamaz");
				} else {
					formParams.push("firmname="+p1);
					SetInputClass(_id,false);
				}
				
				p1 = $.trim($('#txtTaxOffice').val());
				_id = 'txtTaxOffice';
				if(p1=="" || p1.length<5){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Vergi dairesi 5 karaktarden az olamaz");
				} else {
					formParams.push("taxoffice="+p1);
					SetInputClass(_id,false);
				}
				p1 = $.trim($('#txtTaxNo').val());
				_id = 'txtTaxNo';
				if(p1=="" || p1.length<10){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Vergi numarası 10 rakamdan az olamaz");
				} else {
					formParams.push("taxnumber="+p1);
					SetInputClass(_id,false);
				}
				
				p1 = $.trim($('#txtAuthPerName').val());
				_id = 'txtAuthPerName';
				if(p1=="" || p1.length<2){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Kişi adı 2 karakterden az olamaz");
				} else {
					formParams.push("authname="+p1);
					SetInputClass(_id,false);
				}
				p1 = $.trim($('#txtAuthPerSurname').val());
				_id = 'txtAuthPerSurname';
				if(p1=="" || p1.length<2){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Kişi soyadı 2 karakterden az olamaz");
				} else {
					formParams.push("authsurname="+p1);
					SetInputClass(_id,false);
				}
				
				p1 = $.trim($('#txtAuthPerEmail').val());
				_id = 'txtAuthPerEmail';
				if(p1=="" || p1.length<5 || !dmForms.Validation.isEmail('txtAuthPerEmail')){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Geçerli e-mail adresi girmelisiniz");
				} else {
					formParams.push("authemail="+p1);
					SetInputClass(_id,false);
				}
				
			} else {
				formParams.push("reqtype=0");
				p1 = $.trim($('#txtAuthName').val());
				_id = 'txtAuthName';
				if(p1=="" || p1.length<2){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Kişi adı 2 karakterden az olamaz");
				} else {
					formParams.push("authname="+p1);
					SetInputClass(_id,false);
				}
				p1 = $.trim($('#txtAuthSurname').val());
				_id = 'txtAuthSurname';
				if(p1=="" || p1.length<5){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Kişi soyadı 2 karakterden az olamaz");
				} else {
					formParams.push("authsurname="+p1);
					SetInputClass(_id,false);
				}
				
				p1 = $.trim($('#txtAuthEmail').val());
				_id = 'txtAuthEmail';
				if(p1=="" || p1.length<5 || !dmForms.Validation.isEmail('txtAuthEmail')){
					formSend = false;
					SetInputClass(_id,true);
					errorDesc.push("Geçerli e-mail adresi girmelisiniz");
				} else {
					formParams.push("authemail="+p1);
					SetInputClass(_id,false);
				}
			}	
			if(formSend){
				$('#spn3').show();
				// ajax post		
				$.ajax(
					{
						type		: "POST",
						//url			: "pages/update_customer.php",
						url 		: "index.php/sisteme-kayit-ol-musteri-bilgilerini-guncelle",
						data		: formParams.join("&"),
						dataType	: "json",	
						success		: function(_response){
							$('#spn3').hide();
							if(_response.rcode == "00"){
								$('#divGSM').hide();
								$('#divControlGSM').hide();
								$('#divCustomerInfo').hide();
								$('#divCong').show();
							} else {
								
							}
						},
						error		: function(event, request, settings){
							
						}
					}
				);		
				
			} else {
				alert(errorDesc.join("\n"));	
			}
			break;
	}
}

function RetrySendSMS(i){
	// SMS gönderilemedi , tekrar dene
	$('#spn11').show();
	$.ajax(
		{
			type		: "POST",
			url			: "index.php/sisteme-kayit-ol-islemler",
			data		: "i="+i+"&r=true",
			dataType	: "json",	
			success		: function(_response){
				$('#spn11').hide();
				if(_response.rcode=="00"){
						newCustomerId = _response.rdata;								
						$('#divGSM').hide();
						$('#divControlGSM').show();
						$('#divCustomerInfo').hide();
						$('#divCong').hide();
				} else{
					alert(_response.rdata);
				}
			},
			error		: function(event, request, settings){
				
			}
		}
	);	
}

function YeniKayit2(){
	$.get("pages/new_record_form.php",{rnd:Math.random()},function(data){
		$('#divCommonDialog').html(data).dialog({
			modal:true,
			title : 'Duyurumatik Kayıt Formu',
			position:['center',10],
			width:750,			
			buttons : {
				'Kapat':function(){
					$(this).dialog('destroy');
				},
				'Kaydet':function(){
					Kaydet();
				}
			}
		}).dialog("open");
		
		window.setTimeout(function(){
			$('#radTip0').bind("click",function(){
				$('#divPer').fadeOut(150,function(){
					$('#divBus').fadeIn(150);
				});
				$.each($(':input'),function(i,v){
					SetInputClass($(v).attr("id"),false);
				});
			});
			$('#radTip1').bind("click",function(){
				$('#divBus').fadeOut(150,function(){
					$('#divPer').fadeIn();
				});
				$.each($(':input'),function(i,v){
					SetInputClass($(v).attr("id"),false);
				});
			});
			$('#login_form').formtooltip();
		},150);
		
	},"html");
}

function SetInputClass(id,isError){
	var bg = "#fff";
	if(isError){
		bg = "#e0eeef";
	}
	$('#'+id).css({backgroundColor:bg});
}



function Kaydet(){
	var formSend = true;
	var formParams = [];
	var errorDesc = [];
	var _id= "";
	// ortak kontroller
	
	// gsmno
	var p1 = $.trim($('#txtgsmno').val());
	_id = 'txtgsmno';
	if(p1=="" || p1.length<10){
		formSend = false;
		SetInputClass(_id,true);
		errorDesc.push("Gsm Numarası eksik veya hatalı");
	} else {
		formParams.push("gsm="+p1);
		SetInputClass(_id,false);
		$('#txtgsmno').css({backgroundColor:"#fff"});
	}
	// adres
	p1 = $.trim($('#txtAdress').val());
	_id = 'txtAdress';
	if(p1=="" || p1.length<5){
		formSend = false;
		SetInputClass(_id,true);
	} else {
		SetInputClass(_id,false);
		formParams.push("adr="+p1);
	}
	// city
	p1 = $('#drpCITY').val();
	_id = 'drpCITY';
	if(p1<0){
		formSend = false;
		SetInputClass(_id,true);
	} else {
		formParams.push("city="+p1);
		SetInputClass(_id,false);
	}
	
	
	// ayrı kontroller
	var radC = $('#radTip0').attr("checked");
	if(radC){
		formParams.push("reqtype=1");
		p1 = $.trim($('#txtBusName').val());
		_id = 'txtBusName';
		if(p1=="" || p1.length<5){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("firmname="+p1);
			SetInputClass(_id,false);
		}
		
		p1 = $.trim($('#txtTaxOffice').val());
		_id = 'txtTaxOffice';
		if(p1=="" || p1.length<5){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("taxoffice="+p1);
			SetInputClass(_id,false);
		}
		p1 = $.trim($('#txtTaxNo').val());
		_id = 'txtTaxNo';
		if(p1=="" || p1.length<10){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("taxnumber="+p1);
			SetInputClass(_id,false);
		}
		
		p1 = $.trim($('#txtAuthPerName').val());
		_id = 'txtAuthPerName';
		if(p1=="" || p1.length<2){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authname="+p1);
			SetInputClass(_id,false);
		}
		p1 = $.trim($('#txtAuthPerSurname').val());
		_id = 'txtAuthPerSurname';
		if(p1=="" || p1.length<2){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authsurname="+p1);
			SetInputClass(_id,false);
		}
		
		p1 = $.trim($('#txtAuthPerEmail').val());
		_id = 'txtAuthPerEmail';
		if(p1=="" || p1.length<5 || !dmForms.Validation.isEmail('txtAuthPerEmail')){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authemail="+p1);
			SetInputClass(_id,false);
		}
		
	} else {
		formParams.push("reqtype=0");
		p1 = $.trim($('#txtAuthName').val());
		_id = 'txtAuthName';
		if(p1=="" || p1.length<5){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authname="+p1);
			SetInputClass(_id,false);
		}
		p1 = $.trim($('#txtAuthSurname').val());
		_id = 'txtAuthSurname';
		if(p1=="" || p1.length<5){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authsurname="+p1);
			SetInputClass(_id,false);
		}
		
		p1 = $.trim($('#txtAuthEmail').val());
		_id = 'txtAuthEmail';
		if(p1=="" || p1.length<5 || !dmForms.Validation.isEmail('txtAuthEmail')){
			formSend = false;
			SetInputClass(_id,true);
		} else {
			formParams.push("authemail="+p1);
			SetInputClass(_id,false);
		}
	}
	
	if(formSend){
		// ajax post
		//console.log("send params: "+formParams.join("&"));
		$.ajax(
			{
				type		: "POST",
				url			: "pages/insert_record.php",
				data		: formParams.join("&"),
				dataType	: "html",	
				success		: function(_response){
					
				},
				error		: function(event, request, settings){
					
				}
			}
		);
		
		
	} else {
		//console.log("hata bilgilerini yazdır "+errorDesc);	
	}
}


function ControlGsmNumber(){
	var l = $('#txtgsmno').val();
	if(l.length==10){
		$('#txtgsmno').css({background:'transparent url(jetimg/loading.gif) right center no-repeat'});
		$.ajax(
			{
				type		: "POST",
				url			: "pages/check_gsm.php",
				data		: "gsm="+l,
				dataType	: "json",	
				success		: function(_response){
					if(_response.rcode=="99"){
						alert(_response.rdata);
					}
					$('#txtgsmno').css({background:''});
				},
				error		: function(event, request, settings){
					
				}
			}
		);
	}

}
function ChangePassword()
{//control aynılık ve boşluk
	var formParams = [];	
	var p1 = $.trim($('#txtpasswordold').val());	
	var p2 = $.trim($('#txtpasswordnew').val());
	var p3 = $.trim($('#txtpasswordnew2').val());
	var sReturn = ControlPassword(p1,p2,p3);
	if(!sReturn){
		return;
	}
	formParams.push("oldp="+p1);		 
	formParams.push("newp="+p2);	
	formParams.push("newp2="+p3);
	$.ajax(
		{
			type		: "POST",
			url			: base+"index.php/sifremi-guncelle",
			data		: formParams.join("&"),
			dataType	: "json",	
			success		: function(_response){
				if(_response.rcode=="00"){
					$('#divWorkingPass').css({color:'#006600'}).html(_response.rdata).show();
					$(':input').val('');
					window.setTimeout(function(){
						$('#divWorkingPass').hide(1000);
					},1500);
				} else {
					$('#divWorkingPass').css({color:'#dd0000'}).html(_response.rdata).show();
				}			
			},
			error		: function(event, request, settings){
				
			}
		}
	);
}
function ControlPassword(p1,p2,p3) {
	var ret = true;
	var sReturn = "";
	$('#divWorkingPass').html("").hide();
	if(p1=="" || p2 =="" || p3=="")
	{
		sReturn ="Lütfen şifre alanlarını doldurunuz!";
		ret = false;
	} if(p2!=p3)
	{
		sReturn ="Girdiğiniz şifreler aynı olmalıdır!";
		ret = false;
	} else if(p2.length<6 || p3.length<6) {
		sReturn ="En az 6 karakterden oluşmalı!";
		ret = false;
	}
	$('#divWorkingPass').css({color:'#dd0000'}).html(sReturn).show();
	return ret;
}
function SaveTitle()
{
	var formParams = [];	
	var p1 = $.trim($('#txtmessagetitle').val());	
	if(p1=="")
	{
		$('#divWorking').html("Mesaj başlığı alanını doldurmalısınız").css({color:'#dd0000'}).show();
		SetInputClass("txtmessagetitle",true);
		return;
	}	
	formParams.push("title="+p1);
	$('#divWorking').css({color:'#006600'}).html("Mesaj başlığınız kaydediliyor..").show();
	$.ajax(
			{
				type		: "POST",
				url			: base+"/index.php/mesaj-basligi-ekle",
				data		: formParams.join("&"),
				dataType	: "json",	
				success		: function(_response){
					if(_response.rcode=="00"){
						$('#divWorking').css({color:'#006600'}).html(_response.rdata);
					} else {
						$('#divWorking').css({color:'#dd0000'}).html(_response.rdata);
					}
					$('#txtmessagetitle').val("");
					SetInputClass("txtmessagetitle",false);	
					window.setTimeout("ListTitle()",1500);
				},
				error		: function(event, request, settings){
					
				}
			}
		);
}

function ListTitle(){
	$("#divList").html("");
	$('#divWorking').css({color:'#006600'}).html("Mesaj başlığınız getiriliyor..").show();
	$.ajax(
		{
			type		: "POST",
			url			: base+"index.php/onayli-mesaj-basliklarim",
			data		: "",
			dataType	: "html",	
			success		: function(_response){
				$("#divList").html(_response);
				$('#divWorking').hide();
			},
			error		: function(event, request, settings){
			}
		}
	);
}


// ugur yeni  fonksiyonlar
function loginForm(){
	$.ajax(
		{
			type		: "POST",
			url			: "index.php/sistem-girisi",
			data		: "",
			dataType	: "html",	
			success		: function(data){
				var nleft = (screen.width - 758) / 2;
	            $('#divarkaplan2').show();
				$("#divLoginForm").css({left:nleft,width:758,height:309}).html(data).show();
				window.setTimeout(function(){
					$('#txtUser').focus();
				},100);
			},
		error		: function(event, request, settings){
			}
		}
	);
}

function CloseLogin(){
	$('#divarkaplan2').hide();
	$("#divLoginForm").hide();
}

function HandleLogin(){
	//login_check.php 
	// txtUser ,txtPass
	
	$('#divLoginResult').html("Kullanıcı adınız ve şifreniz kontrol ediliyor");
	$.ajax(
		{
			type		: "POST",
			url			: "index.php/sifre-kontrol",
			data		: "u="+$('#txtUser').val()+"&p="+$('#txtPass').val()+"&c="+$('#txtCaptcha').val(),
			dataType	: "json",	
			success		: function(_response){
				if(_response.rcode=="00"){
					$('#divLoginResult').html(_response.rdata).css({color:"#006600"});
					window.setTimeout(function(){
						CloseLogin();
						document.location = "https://www.duyurumatik.com/index.php/duyurumatik";
					},2000);
				} else {
					$('#divLoginResult').html(_response.rdata).css({color:"#dd0000"});
					window.setTimeout("loginForm()",1000);
				}
			},
			error		: function(event, request, settings){
			}
		}
	);
}

function ShowAlert(message){
	$("#spnAlertMessage").html(message);
	$("#divAlert").css({margin:"0 auto",zIndex:10000});
	window.setTimeout(function(){
		$("#divAlert").fadeOut(500);
	},3000);
}
	
function ShowWarn(message){
	$("#spnWarnMessage").html(message);
	$("#divAlert").css({margin:"0 auto",zIndex:10000});
	window.setTimeout(function(){
		$("#divWarn").fadeOut(500);
	},3000);
}

function GetPage(pp){
	//
	console.log(pp);
	var showMain = true;
	var _url = "";
	var _runFunc = [];
	switch(pp){
		case "title":
			_url = "pages/title.php";
			showMain = false;
		break;
		case "pass":
			_url = "pages/changepassword.php";
			showMain = false;
		break;
		case "report":
			var whStr  = "";
			console.log("/"+base+"smsgate/report_webclient.php");
			window.open(base+"smsgate/report_webclient.php",'DM_Raporlar',whStr + ',status=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes,hotkeys=no',false);
		break;
		case "credit":
			_url = "pages/credit.php";
			showMain = false;
		break;
		case "iletisim":
			_url = "pages/contact.php";
			showMain = false;
		break;
		case "mediacatalog":
			_url = "pages/media_catalog_manager.php";
			showMain = false;
			_runFunc.push("SetUploader()");
		break;
	}
	_url += "?pt="+pp;
	if(!showMain){
		
			$.ajax(
				{
					type		: "POST",
					url			: _url,
					data		: "",
					dataType	: "html",	
					success		: function(_response){
						$("#divPart1").html(_response).show(100,function(){
							$("#divMainPage").hide(50);
							if(_runFunc.length>0){
								$.each(_runFunc,function(i,v){
									if(eval(v)){
										v;
									}
								});
							}
						});
					},
					error		: function(event, request, settings){
						
					}
				}
			);
		
		
	} else {
		$('#divMainPage').show();
		$('#divPart1').hide();
	}
}
function GetSubCity(){
	$('#spanSUBCITY').html("");	
	$.ajax(
		{
			type		: "POST",
			url			: base+"index.php/telefon-kodlari",
			data		: {type:1,code:$('#drpCITY').val()},
			dataType	: "html",	
			success		: function(_response){
				$('#spanSUBCITY').html(_response);
			},
			error		: function(event, request, settings){
				
			}
		}
	);
}
function GetDetailList(realexcelname,type){	
	$('#divDetailListAlt').html("");	
	$.ajax(
		{
			type		: "POST",
			url			: base+"index.php/detayli-gosterim",
			data		: {type:type,realexcelname:realexcelname},
			dataType	: "html",	
			success		: function(_response){				
				$('#divDetailListAlt').html(_response);
				$('#divDetailList').dialog({
					modal:true,
					title : 'Detaylı Gönderilecekler Listesi',
					position:['center',10],
					width:750,
					minheight:200,
					height:600,
					buttons : {
						'Kapat':function(){
							$(this).dialog('destroy');
						}
					}
				}).dialog("open");
			},
			error		: function(event, request, settings){
				
			}
		}
	);
	
}
function SetUploader(){
	$("#uploadify").uploadify({
		'uploader'       : 'js/uploadify.swf',
		'script'         : 'pages/uploader.php',
		'cancelImg'      : 'img/cancelUPLOAD.png',
		'folder'         : 'media_catalog',
		'queueID'        : 'fileQueue',
		'auto'           : false,
		'multi'          : true,
		'method'		 : 'post',
		'onError'		: function(event,queueId,fileObj,errorObj){
			console.log(event);
			console.log(queueId);
			console.log(fileObj);
			console.log(errorObj);
		},
		'onComplete':function(event,queueId,fileObj,response,data){
			console.log(event);
			console.log(queueId);
			console.log(fileObj);
			console.warn(response);
			console.log(data);
			
		}
	});
}

function linkProd(prod){
	$.get("pages/products.php",{p:prod},function(data){
		$('#divMainPage').hide();
		$('#divPart1').html(data).show();
	},"html");
}

function OpenHelp(){
	var whStr  = "";
	window.open(helpUrl+"&inpagecss=1",'DM_Yardim',whStr + ',status=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes,hotkeys=no',false);
}
//daha sonra dm_voice den çağırılacak geçici buraya konulan fonksiyonlar
function showVoice()
{	
	$('#divVoice').dialog({
		modal:true,
		title : 'Ses Dosyası',
		position:['center',10],
		width:750,
		buttons : {
			'Kapat':function(){
				$(this).dialog('destroy');
			}
		}
	}).dialog("open");
}
function print()
{
	window.print();
}

function getPopup(StepId,err)
{	
	if(err!="")
	{
		alert(err);
		return;
	}
	switch(StepId)
	{
		case 1:
			$('#divStep1').dialog({
				modal:true,
				title : 'Proje Adı Belirleme',
				position:['center',10],
				width:750,
				buttons : {
					'Kapat':function(){
						$(this).dialog('destroy');
					}
				}
			}).dialog("open");
			break;
		case 2:
			$('#divStep2').dialog({
				modal:true,
				title : 'Ses Dosysı Upload Etme',
				position:['center',10],
				width:750,
				buttons : {
					'Kapat':function(){
						$(this).dialog('destroy');
					}
				}
			}).dialog("open");
			break;
		case 3:
			$('#divStep3').dialog({
				modal:true,
				title : 'Excel Upload Etme',
				position:['center',10],
				width:750,
				buttons : {
					'Kapat':function(){
						$(this).dialog('destroy');
					}
				}
			}).dialog("open");
			break;	
		case 4:			
			//$('#divStep4').show();fillDropDowns();
			$('#divStep4').dialog({				
				modal:true,
				title : 'Sesin Okunacağı Tarihleri Belirleme',
				position:['center',10],
				width:750,
				buttons : {
					'Kapat':function(){
					 $(this).dialog('destroy');
					 clearDropDowns();
					}
				},
				open:function(){
					$("#ui-datepicker-div").css("z-index",
					$(this).parents(".ui-dialog").css("z-index")+1); 

					window.setTimeout("fillDropDowns()",200);
				}
			}).dialog("open");
			
			break;
		case 5:
			$('#divCaller').dialog({
				modal:true,
				title : 'Ses Dosysı Upload Etme',
				position:['center',10],
				width:750,
				buttons : {
					'Kapat':function(){
						$(this).dialog('destroy');
					}
				}
			}).dialog("open");
			break;
		case 22:
			$('#divStep1_2').dialog({
				modal:true,
				title : 'Şablon Seçme',
				position:['center',10],
				width:800,
				buttons : {
					'Kapat':function(){
						$(this).dialog('destroy');
					}
				}
			}).dialog("open");
			break;
	}
}

// ugur 2009-12-04
var dm = {
	warning_timeout: 2000,
	ShowWarn : function(message,msc){
		$("#divCommonWarnings")
		.attr({"class":'alertCommon'})
		.css({border:'.3em solid #ffbb00',backgroundColor:'#fffbcc'})
		.html(message)
		.centerInClient({forceAbsolute:true})
		.fadeIn(100,function(){
				var $this = $(this);
				window.setTimeout(function(){
					$this.fadeOut();
				},msc?msc:dm.warning_timeout);
			}).bind('click',function(){
				$(this).fadeOut();
			});
	},
	ShowAlert : function(message,msc){
		$('#divCommonWarnings')
			.attr({"class":'alertCommon'})
			.css({border:'.3em solid #dd0000',backgroundColor:'#FFEFEF'})
			.html(message)
			.centerInClient({forceAbsolute:true})
			.fadeIn(100,function(){
				var $this = $(this);
				window.setTimeout(function(){
					$this.fadeOut();
				},msc?msc:dm.warning_timeout);
			}).bind('click',function(){
				$(this).fadeOut();
			});
	},
	ShowInfo : function(message,msc){
		$('#divCommonWarnings')
			.attr({"class":'alertCommon'})
			.css({border:'.3em solid #006600',backgroundColor:'#EFFFEF'})
			.html(message)
			.centerInClient({forceAbsolute:true})
			.fadeIn(100,function(){
				var $this = $(this);
				window.setTimeout(function(){
					$this.fadeOut();
				},msc?msc:dm.warning_timeout);
			}).bind('click',function(){
				$(this).fadeOut();
			});
	}
}
