function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_showHideImage(me) { 
	MM_findObj('Layer1').style.backgroundImage = "url('"+me+"')";
}

function toggleVisibility(me){
	var nesnem = document.getElementById(me);
		if (nesnem.style.display=="none"){
			nesnem.style.display = "";
			}
		else 
			nesnem.style.display = "none";	
}

function search_check(){

	if (document.search.text.value.length < 3){
		alert ("En Az 3 Harf...");
		document.search.text.focus();
		return false;  
	 }

}
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 IsValidChar(sText)
{
	var ValidChars = ";(){}%#^'?*_<>[]\",/:!$=\\";
	for (i = 0; i < sText.length; i++) 
	{ 
		if (ValidChars.indexOf(sText.charAt(i)) >-1) 
			return i;
	}
	return -1;
}

function Kontrol() {
	var mesaj 	= ", Doldurulması Zorunlu Alandır!";
	
	firmaadi		= trim(document.uyekayitform.firmaadi.value);
	yetkili_kisi	= trim(document.uyekayitform.yetkili_kisi.value);
	yetkili_gorevi 	= trim(document.uyekayitform.yetkili_gorevi.value);
	il				= trim(document.uyekayitform.n_il.value);
	ilce			= trim(document.uyekayitform.n_ilce.value);
	adres			= trim(document.uyekayitform.adres.value);
	telefon1 		= trim(document.uyekayitform.telefon1.value);
	telefon2 		= trim(document.uyekayitform.telefon2.value);
	telefon3 		= trim(document.uyekayitform.telefon3.value);
	alankodu 		= trim(document.uyekayitform.alankodu.value);
	faks     		= trim(document.uyekayitform.faks.value);
	eposta			= trim(document.uyekayitform.eposta.value);
	semt			= trim(document.uyekayitform.n_semt.value);
	yeni_semt		= trim(document.uyekayitform.yeni_semt.value);
	

	if(firmaadi == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Firma Adı' + mesaj + '</B></font>'; return;	
	}

	nv = IsValidChar(firmaadi);
	if(nv>-1)
	{
		alert('Bu karakterin kullanilmasina izin verilmemektedir!');
		document.uyekayitform.firmaadi.value = firmaadi.substring(0,nv);
	}
	if(firmaadi.length>50)
	{
		alert('Firma Adi 50 karakterden büyük olamaz!');
		document.uyekayitform.firmaadi.value = firmaadi.substring(0,49);
	}
		
	
	/*if(document.getElementById("adkontrol").innerHTML != ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Firma Adı Geçersiz!</B></font>';  return;	
	}*/
	
	if(yetkili_kisi == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Yetkili Kişi' + mesaj + '</B></font>'; return;
	}
	if(yetkili_gorevi == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Yetkili Görevi' + mesaj + '</B></font>'; return;
	}
	if(il == "0"){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>İl' + mesaj + '</B></font>'; return;
	}
	if(ilce == "0"){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>İlçe' + mesaj + '</B></font>'; return;
	}
	if(semt == "0" || (semt == "-1" && (yeni_semt == "" || yeni_semt == "Semt Giriniz") ) ){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Semt' + mesaj + '</B></font>'; return;
	}
	if(adres == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Adres' + mesaj + '</B></font>'; return;
	}
	
	/* alan kodu check */
	if(alankodu == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Alan kodu' + mesaj + '</B></font>'; return;
	}
	if(alankodu.length != 3){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Alan kodu 3 haneli olmak zorundadir!</B></font>'; return;
	}
	if(!IsNumeric(alankodu)){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Alan kodu rakamlardan oluşmalidir!</B></font>'; return;
	}
	/* end of alan kodu check */
	
	/* telefon chech */
	if(telefon1 == "" || telefon1 == "Telefon"){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Telefon' + mesaj + '</B></font>'; return;
	}
	if(telefon1.length!=7){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Lütfen 7 haneli telefon numaralari giriniz!</B></font>'; return;
	}
	if(!IsNumeric(telefon1)){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Telefon numaralari rakamlardan olusmalidir!</B></font>'; return;
	}
	
	if(telefon2 != "Telefon" && telefon2 != "")
	{
		if(telefon2.length!=7 ){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Lütfen 7 haneli telefon numaralari giriniz!</B></font>'; return;
		}
		if(!IsNumeric(telefon2)){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Telefon numaralari rakamlardan olusmalidir!</B></font>'; return;
		}
	}
	if(telefon3 != "Telefon" && telefon3 != "")
	{
		if(telefon3.length!=7 ){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Lütfen 7 haneli telefon numaralari giriniz!</B></font>'; return;
		}
		if(!IsNumeric(telefon3)){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Telefon numaralari rakamlardan olusmalidir!</B></font>'; return;
		}
	}
	
	
	/* end of telefon chech */
	
	if(faks != ""){

		if(faks.length!=7){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Lütfen 7 haneli faks numarasi giriniz!</B></font>'; return;
		}
		if(!IsNumeric(faks)){
			document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>Faks numarasi rakamlardan olusmalidir!</B></font>'; return;
		}
	}
	
	if(eposta == ""){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>E-posta' + mesaj + '</B></font>'; return;
	}
	if (eposta.indexOf('@') == -1){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>E-posta adresi @ karakteri içermelidir!</B></font>'; return;
	}
	
	
	
	sayac=0;
	for(i=0; i<document.uyekayitform.elements.length; i++)
	{
		if (document.uyekayitform.elements[i].checked){
			sayac++;
		}
	}
	
	if (sayac == 0 || sayac >10){
		document.getElementById("gonder").innerHTML='<font color=red style="font-size: 10px"><B>En az 1, en fazla 10 faaliyet alani tane seçmelisiniz!</B></font>';
		document.getElementById("buton").disabled = true;
		return;
	}
	
	
	document.getElementById("buton").disabled = false;
	document.getElementById("gonder").innerHTML='<font color=green style="font-size: 10px"><B>Tamam</B></font>';
}
function buton_tikla()
{
	document.getElementById("buton").disabled = true;
	document.getElementById("gonder").innerHTML='<font color=green style="font-size: 10px"><B>İşleminiz gerçekleştiriliyor</B></font>';
	document.uyekayitform.submit();
}

function adkontrol(deger){

	$.ajax({
		type: 'get',
		url: '/top/firma_adi_kontrol.asp',
		data: 'firma_adi='+deger,
		success: function(sonuc) 
		{
			document.getElementById("adkontrol").innerHTML=sonuc;
			Kontrol();
		}
	});
}



function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
} 

 

function buyut(gelen)
{
		gelen = gelen.toUpperCase();
}   

function MM_setTextOfTextfield(objName,newText) { //v3.0
	var obj = MM_findObj(objName); 
	if(obj.value == ''){
		if (obj) {
			obj.value = newText;
		}
	}
}

function CreateBookmarkLink()
{
	title = "İnşaat Firmalarım"; 
	url = "http://www.insaatfirmalarim.com";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external ){ // IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print){ // Opera Hotlist
		return true;
	}
}



function yorum_dogrula()
{
    var form = document.yorum;


     if (trim(form.ad.value).length < 1 || trim(form.email.value).length < 1 || trim(form.metin.value).length < 1)
     {
           alert ("Lütfen tüm alanlari doldurup tekrar deneyin.");
           return false;
     }
}


function SehirGetir(tur,id)
{
	document.uyekayitform.yeni_semt.value='Semt Giriniz';
	
	document.getElementById('yeni_semt').style.display='none';
	$.ajax({
		type: "POST",
		dataType: 'json',
		url: '/top/ilce-semt.asp',
		data: tur+'='+id, 	  	
		success: function(JSON){ 
		
			if(JSON[0]>0)
			{	  				
				$('#'+tur+'_select').text('');
				if(JSON[0]==1)
				{
					$('#semt_select').text('');
					$('#semt_select').append('<option value="0" selected="selected">semt seçiniz</option>');
				}
				$('#'+tur+'_select').append(JSON[1]).show('fast');	   			
			}
			else {
				$('#ilce_select').text('');
				$('#semt_select').text('');
			}
		}
	});
}

