//Window Adı
self.name="masters";

//Üzerine gelince..
function listRow (listname, action, oldclass){
	switch (action){
		case "out":
		if (oldclass == "gridRowOver"){
			var a = "gridRow";
		}else{
			var a = oldclass;
		}
		break;
		case "select":
		if (oldclass == "rowSelected"){
			var a = "gridRow";
		}else{
			var a = "rowSelected";
		}
		break;
		default:
		if (oldclass == "rowSelected"){
			var a = "rowSelected";
		}else{
			var a = "gridRowOver";
		}
	}

	for(var i=1; i < 10; i++){
		if (document.getElementById(listname + '-' + i)){
			document.getElementById(listname + '-' + i).className = a;
		}else{
			break;
		}
	}
}

//Change Action
function changeAction (formName, newAction){
	var x = eval('document.' + formName);
	x.action = newAction;
}

//Trim
function trim (pString){
	pString=pString.replace(/^[\s]+/ , '');
	pString=pString.replace(/[\s]+$/ , '');
	return pString;
}

//Büyük Küçük Harf
function buyut (formName){
	if (document.forms[formName]){
		var f = document.forms[formName];

		for(var i=0; i < f.elements.length; i++){
			tempObject = f.elements[i];
			if (tempObject && tempObject.type && (tempObject.type.toLowerCase() == 'text' || tempObject.type.toLowerCase() == 'textarea')){
				tempObject.value=trim(tempObject.value);
				tempObject.value=tempObject.value.replace(/i/g,"İ");
				tempObject.value=tempObject.value.toUpperCase();
			}
		}
	}
}

//Sadece rakam
function onlynum (s, t){
	if (navigator.appName!='Netscape'){
		var deger = s;
	}else{
		var deger = t;
	}

	var numbers = new Array(12);
	numbers[8]  = 8;
	numbers[46] = 46;
	numbers[48] = 48;
	numbers[49] = 49;
	numbers[50] = 50;
	numbers[51] = 51;
	numbers[52] = 52;
	numbers[53] = 53;
	numbers[54] = 54;
	numbers[55] = 55;
	numbers[56] = 56;
	numbers[57] = 57;

	if (!numbers[deger]){
		return false;
	}else{
		return true;
	}
}

//Popups
function popup(url, width, height) {
	window.open(url,"popup","width="+ width +",height="+ height +",resizable=no,status=no,scrollbars=yes")
}
function popup2(url, width, height) {
	window.open(url,"popup","width="+ width +",height="+ height +",resizable=yes,status=no,scrollbars=yes")
}
function dialog(url, width, height) {
	showModalDialog(url, window.dialogArguments, "dialogWidth: "+ width +"px; dialogHeight: "+ height +"px; help: 0; status: 0; resizable:0; center:1")
}

//Değerleri çeker
function getvalues (path){
	var all = path.elements;
	var values = "";
	for(var i=0; i < all.length; i++){
		if((all[i].type == "hidden") || (all[i].type == "text") || (all[i].type == "textarea") || (all[i].type == "select-one") || (all[i].type == "checkbox")){
			values += "&" + all[i].name +"="+ all[i].value;
		}
	}
	return values;
}

//Boş olanları kontrol eder #Geçici olarak devre dışı#
function checkempties(location, fields, names){
	var total = fields.length;
	var message = "";
	for(var i=0; i < total; i++){
		if(location.fields[i].value == ""){
			message += "- " + names[i];
		}
	}
	message = "Aşağıdaki alanları boş bırakmayınız:\n" + message;
	alert(message);
	return false;
}

//Checkbox seçimleri

function checkthis(checkbox, listname){
	if(checkbox.checked){
		for(var i=1; i < 10; i++){
			if (document.getElementById(listname + '-' + i)){
				document.getElementById(listname + '-' + i).className = "rowSelected";
			}else{
				break;
			}
		}
	}else{
		for(var i=1; i < 10; i++){
			if (document.getElementById(listname + '-' + i)){
				document.getElementById(listname + '-' + i).className = "gridRow";
			}else{
				break;
			}
		}
	}
}

function checkAll(all, formName){
	if (document.forms[formName]){
		var path = document.forms[formName];
	}else{
		return false;
	}
	var y = 1;

	for(var i=0; i < path.elements.length; i++){
		if((i > 0) & (path.elements[i].type == "checkbox") & (path.elements[i].name != all.name)){
			if(all.checked){
				path.elements[i].checked = true;

				//Liste adı
				listname = formName+y;

				for(var t=1; t < 10; t++){
					if (document.getElementById(listname + '-' + t)){
						document.getElementById(listname + '-' + t).className = "rowSelected";
					}else{
						break;
					}
				}

				//tr.className = "rowSelected";
			}else{
				path.elements[i].checked = false;

				//Liste adı
				listname = formName+y;

				for(var t=1; t < 10; t++){
					if (document.getElementById(listname + '-' + t)){
						document.getElementById(listname + '-' + t).className = "gridRow";
					}else{
						break;
					}
				}
				//tr = eval(formName+y);
				//tr.className = "";
			}
			y++;
		}
	}
}

function checkIfAll(all, formName){
	if (document.forms[formName]){
		var path = document.forms[formName];
	}else{
		return false;
	}

	var x = 0;
	var y = 0;

	for(var i=0; i < path.elements.length; i++){
		if(path.elements[i].type == "checkbox"){
			if((path.elements[i].checked) & (path.elements[i].id != "checkall")){
				x++;
			}
			if((path.elements[i].id != "checkall")){
				y++;
			}
		}
	}

	if(y == x){
		document.getElementById("checkall").checked = true;
	}else{
		document.getElementById("checkall").checked = false;
	}
}

function checkFields(formName){
	var path = formName;
	for(var i=0; i < path.elements.length; i++){
		if(path.elements[i].type == "checkbox"){
			if(path.elements[i].checked){
				if(confirm('Silmek istediğinize emin misiniz?')){
					return true;
				}else{
					return false;
				}
			}
		}
	}
	alert ('Seçim yapmalısınız!');
	return false;
}

//Editörden gelen verileri aktaralım

function html2hidden (hiddenName, editName){
	var h = document.getElementById(hiddenName);
	h.value = eval(editName).getHTMLBody();
}

//Takvim
// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the showCalendar function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}

/**
* Adds a select item(s) from one list to another
*/
function addSelectedToList(frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList(frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function selectList(formName, tmpName) {
	sourceList = formName;
	tmpList = tmpName;
	for(var i = 0; i < sourceList.options.length; i++) {
		if (sourceList.options[i] != null){
			sourceList.options[i].selected = true;
		}
		tmpName.value += sourceList.options[i].value + ",";
	}
	return true;
}

//Textarea sınırlama
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	}else{
		countfield.value = maxlimit - field.value.length;
	}
}

