﻿function checkMail(strEmail) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(strEmail)) 
		return true;
	else 
		return false;
}

// Alan boş geçilemez
function RequiredValidator (obj, Mesaj) {
	if (Trim(obj.value).length < 2) {
		alert(Mesaj);
		obj.focus();
		return false;
	}
}


// Select seçilmeli
function SelectValidator(obj, Mesaj) {
	if (obj[obj.selectedIndex].value == "0") {
		alert(Mesaj);
		obj.focus();
		return false;
	}
}

function checkTheKey(btnID)
{
    fnTrapKD(btnID, event)
}

// Enter'da hangi buton'a clikleneceğini söyle
function fnTrapKD(btnID, event) {
	btn = findObj(btnID);
	if (document.all){
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById) {
		if (event.which == 13) {
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
	else if (document.layers) {
		if (event.which == 13) {
			event.returnValue=false;
			event.cancel = true;
			btn.focus();
			btn.click();
		}
	}
}

// Nesneyi bul
function findObj(n, d) { 
	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 = findObj(n,d.layers[i].document);
	if (!x && d.getElementById) 
		x = d.getElementById(n); 
	return x;
}

// Popup sayfa aç
function Ac(Sayfa,En,Boy,Ust,Yan) {
	window.open(Sayfa, 'Baslik', "height="+Boy+",width="+En+",top="+Ust+",left="+Yan+",status=yes,toolbar=no,menubar=no,location=no");
}

// Popup sayfa aç
function Ac2(Sayfa,En,Boy) {
	window.open(Sayfa, 'Baslik', "height="+Boy+",width="+En+",top=200,left=200,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

// Modal sayfa aç
function ModalAc(Sayfa,En,Boy) {
    if (window.showModalDialog) {
        window.showModalDialog(Sayfa, "", "dialogHeight:"+Boy+"px; dialogWidth:"+En+"px;help:no;scroll:no");
    } 
    else {
        window.open(Sayfa,"","height=" + Boy + ",width=" + En + ",toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes");
    }
}

function ModalAcScroll(Sayfa,En,Boy) {
    if (window.showModalDialog) {
        window.showModalDialog(Sayfa, "", "dialogHeight:"+Boy+"px; dialogWidth:"+En+"px;help:no;scroll:yes");
    } 
    else {
        window.open(Sayfa,"","height=" + Boy + ",width=" + En + ",toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no ,modal=yes");
    }
}

// Boşlukları kaldır
function Trim(s) {
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
		s = s.substring(1,s.length);
	}

	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
		s = s.substring(0,s.length-1);
	}
	
	return s;
}

// Scroll lu Modal sayfa aç
function ModalAc2(Sayfa,En,Boy) {
	window.showModalDialog(Sayfa, "", "dialogHeight:"+Boy+"px; dialogWidth:"+En+"px;help:no;scroll:yes");
}

// Upload edilen resmin türünü kontrol eder
function DosyaKontrol(obj) {
	var ext = document.getElementById(obj).value;
	if (ext != "") {
		ext = ext.substring(ext.length - 3, ext.length);
		ext = ext.toLowerCase();
		if ((ext != 'jpg') && (ext != 'gif'))
			return false; 
		else
			return true;
	}
	else
		return true;
	
}



