/*function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
*/
function selectStart()
{
    //window.event.cancelBubble = true;
    //window.event.returnValue = false;
    return false;
}
//-----------------------------------------------------------------------------
// window.onload'da çalışacak komutlar
//-----------------------------------------------------------------------------
var loadActions = new Array();

function addLoadAction(action){
    loadActions[loadActions.length] = action;
}

function runLoadActions(){
    var i;
    for(i=0; i<loadActions.length; i++){
        eval(loadActions[i]);
    }
}

window.onload = runLoadActions;

//-----------------------------------------------------------------------------
// bir frameden başka bir framin location`ının değiştirmek
//-----------------------------------------------------------------------------
function changeLocation(frameAd,url){
        window.parent.frames.item(frameAd).document.location.href=url;
}

//-----------------------------------------------------------------------------
// bir frameden başka bir frami reload etmek
//-----------------------------------------------------------------------------
function reloadPage(frameAd){
        window.parent.frames.item(frameAd).location.reload();
}

//-----------------------------------------------------------------------------
// bir formda değişiklik olduğunda
//-----------------------------------------------------------------------------
var formChanged=false;

function whenFormChanged(){
        if(!formChanged) {
                eval(whenFormChangedScript);
                formChanged = true;
        }
}

function assignOnChangeEvents(form){
        eval('f = document.'+form+'.elements;');
        for(i=0;i<f.length;i++){
                if(!f[i].onchange) f[i].onchange=whenFormChanged;
        }
        return false;
}

//-----------------------------------------------------------------------------
// document.writeln için kısayol
//-----------------------------------------------------------------------------
function echo(str){
        document.writeln(str);
}

//-----------------------------------------------------------------------------
// formu göndermeden önce şekil koymak... (validation)
//-----------------------------------------------------------------------------
function checkGroupChecker(inputname){
        checkGroup = document.getElementsByName(inputname);
        for(cSayac=0; cSayac< checkGroup.length ; cSayac++){
                if(checkGroup[cSayac].checked){
                        return false;
                }
        }
        return true;
}

function submitForm(f){
        for(i=0;i<f.elements.length;i++){
                input = f.elements[i];
                if(input.getAttribute('alert')!=null){
                        if(input.getAttribute('condition')==null){
                                if(input.tagName=='SELECT'){
                                        input.condition = "input.selectedIndex==0";
                                        //input.condition = "input.value=='' || input.value<1";
                                }
                                if(input.tagName=='TEXTAREA' || input.type=='text' || input.type=='password' || input.type=='file'){
                                        input.condition = "input.value==''";
                                }

                                if(input.type=='checkbox' || input.type=='radio'){
                                        input.condition = "checkGroupChecker('" + input.name +"')";
                                }
                        }

                        result = false;
                        eval('result=('+input.condition+');');

                        //input.alert  \n\r replace edilecek
                        if(result==true){
                                alert(input.alert);
                                input.focus();
                                //input.style.backgroundColor = '#FF0000';
                                return false;
                        }
                }
        }

        for(i=0;i<f.elements.length;i++){
                input = f.elements[i];
                if(input.className=='number') input.value = input.getValue();
                if(input.className=='date') input.value = input.getValue();
        }

        return true;
}

//-----------------------------------------------------------------------------
function paraBicim(deger,tur){
    var bicimli;
    bicimli = numberFormat(deger) + tur;
    //bicimli = deger + " TL";
    return bicimli;
}

//-----------------------------------------------------------------------------
function numberFormat(deger){
        var strDeger = deger + "";
        var retval="";
        if(strDeger.length > 3){
                retval = numberFormat(strDeger.substr(0,strDeger.length-3)) + "." + strDeger.substr(strDeger.length-3,3);
        }else{
                retval = strDeger;
        }
        return retval;
}

//-----------------------------------------------------------------------------
function trim (strValue){
        retVal = "";
        for(i=0; i < strValue.length ; i++ ){
                if(strValue.charAt(i) == ' '){
                        ;
                }else{
                        retVal = retVal +  strValue.charAt(i);
                }
        }

        return retVal;
}
function clearChar(strValue,what) {
        retVal = "";
        for(i=0; i < strValue.length ; i++ ){
                if(strValue.charAt(i) == what){
                        ;
                }else{
                        retVal = retVal +  strValue.charAt(i);
                }
        }

        return retVal;
}
//-----------------------------------------------------------------------------
function strpos(str, aranan) {
        return str.indexOf(aranan);
        /*
        for (var i = 0; i < str.length - aranan.length; i++)
                if (str.substring(i, i+aranan.length) == aranan) return i;
        return -1;
        */
}
function strposWord(str, aranan) {
        //return str.indexOf(aranan);
        
        for (var i = 0; i < str.length - aranan.length; i++)
                if (str.substring(i, i+aranan.length) == aranan) return i;
        return -1;
        
}
//-----------------------------------------------------------------------------
function winopen(href,w,h){
        openWin(href, w, h, true);
}

//-----------------------------------------------------------------------------
function openWin(url, win_width, win_height, center){
    if(center == true ){
        win_left = (screen.width  - win_width ) / 2;
        win_top  = (screen.height - win_height) / 2;
        prop = ",top=" + win_top + ",left=" + win_left + ",scrollbars=yes,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no";
    }else{
        prop = ",scrollbars=yes,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no";
    }

    openWinEx(url, win_width, win_height, prop);
}
function PopUpWin(url, win_width, win_height, center,winname){
    if(center == true ){
        win_left = (screen.width  - win_width ) / 2;
        win_top  = (screen.height - win_height) / 2;
        prop = ",top=" + win_top + ",left=" + win_left + ",scrollbars=yes,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no";
    }else{
        prop = ",scrollbars=no,menubar=no,resizable=yes,status=yes,titlebar=no,toolbar=no";
    }

    openWinEx(url, win_width, win_height, prop,winname);
}
function openWinEx(url, win_width, win_height, prop,winname){
    window.open(url, winname, "width=" + win_width + ", height=" + win_height + prop);
}

//-----------------------------------------------------------------------------
function openPopUp(url, width, height){
        var sFeatures = "center:yes;scroll:yes;status:no;help:no;dialogHeight:" + height + "px;dialogWidth:" + width + "px;";
        window.showModalDialog(url, "", sFeatures);
}// end of openPopUp



//-----------------------------------------------------------------------------
function checkAll(newvalue,checkBoxName){
        var checkBoxs = document.getElementsByName(checkBoxName);
        for(var i=0; i < checkBoxs.length; i++ ){
                checkBoxs[i].checked = newvalue;
        }
}

//-----------------------------------------------------------------------------
function checkForAll(checkBoxName, checkBoxNameAll){
        var allIsChecked   = true;
        var allIsUnChecked = true; // Belki gerekir.

        var checkBoxs = document.getElementsByName(checkBoxName);
        for(var i=0; i < checkBoxs.length; i++ ){
                if(checkBoxs[i].checked){
                        allIsUnChecked = false;
                }else{
                        allIsChecked   = false;
                }
        }

        if(allIsChecked){
                document.getElementsByName(checkBoxNameAll)[0].checked=true;
        }else{
                document.getElementsByName(checkBoxNameAll)[0].checked=false;
        }
}

function checkBoxAll(checkBoxName, checkBoxNameAll){
	var checkAll = document.getElementsByName(checkBoxNameAll)[0];
	var checkSimple = document.getElementsByName(checkBoxName);
	if(checkAll.checked==true){
        for(var i=0; i < checkSimple.length; i++ ){
			checkSimple[i].checked = true;
        }
	}else{
        for(var i=0; i < checkSimple.length; i++ ){
			checkSimple[i].checked = false;
        }
	}
}

function isNumeric(s) {
    var numbers = "0123456789";
    var i;

    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (numbers.indexOf(c) == -1){
            return false;
        }
    }

    return true;
}

function isEmailReg (s) {
    var emailexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/
    if (emailexp.test(s)) return true; else return false;
}

function loadimages(){
    var tmpimg = new Image();
    //tmpimg.src = "/images/imgname.";
    
}
function pagePrint(frameName) {
	if ( frameName !="parent" ) {
		window.parent.frameName.focus();	    
	}
bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print();
}
function printIt(obj) {
     winId=window.open('','printwin','width=1024,height=300,scrollbars=yes,menubar=no,resizable=yes,status=no,titlebar=no,toolbar=no');
	 winId.document.writeln('<link rel="stylesheet"	  href="/_css/default.css">');
     winId.document.writeln(obj.innerHTML);
	 winId.document.writeln('\n<br><a href="javascript:window.print();">Yazdır</a>');
     winId.document.close();
	 winId.focus();
}

function VirgulHane(val,a,numDec){
	var ret = String(Math.round(val*a)/a)
	numDec++
	dot = ret.indexOf(".");
	if (dot == 0) {
		ret = "0"+ret;
	}
	else if (dot > 0) {
		while (ret.length < dot + numDec) ret = ret+"0";
	}
	return ret
}


/*----------------------------------------------------------------------------\
|                                Table Sort                                   |
|-----------------------------------------------------------------------------|
|                         Created by Erik Arvidsson                           |
|                  (http://webfx.eae.net/contact.html#erik)                   |
|                      For WebFX (http://webfx.eae.net/)                      |
|-----------------------------------------------------------------------------|
| A DOM 1 based script that allows an ordinary HTML table to be sortable.     |
|-----------------------------------------------------------------------------|
|                  Copyright (c) 1998 - 2002 Erik Arvidsson                   |
|-----------------------------------------------------------------------------|
| This software is provided "as is", without warranty of any kind, express or |
| implied, including  but not limited  to the warranties of  merchantability, |
| fitness for a particular purpose and noninfringement. In no event shall the |
| authors or  copyright  holders be  liable for any claim,  damages or  other |
| liability, whether  in an  action of  contract, tort  or otherwise, arising |
| from,  out of  or in  connection with  the software or  the  use  or  other |
| dealings in the software.                                                   |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| This  software is  available under the  three different licenses  mentioned |
| below.  To use this software you must chose, and qualify, for one of those. |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Non-Commercial License          http://webfx.eae.net/license.html |
| Permits  anyone the right to use the  software in a  non-commercial context |
| free of charge.                                                             |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| The WebFX Commercial license           http://webfx.eae.net/commercial.html |
| Permits the  license holder the right to use  the software in a  commercial |
| context. Such license must be specifically obtained, however it's valid for |
| any number of  implementations of the licensed software.                    |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
| Permits anyone the right to use and modify the software without limitations |
| as long as proper  credits are given  and the original  and modified source |
| code are included. Requires  that the final product, software derivate from |
| the original  source or any  software  utilizing a GPL  component, such  as |
| this, is also licensed under the GPL license.                               |
|-----------------------------------------------------------------------------|
| 1998-??-?? | First version                                                  |
|-----------------------------------------------------------------------------|
| Created 1998-??-?? | All changes are in the log above. | Updated 2001-??-?? |
\----------------------------------------------------------------------------*/


var dom = (document.getElementsByTagName) ? true : false;
var ie5 = (document.getElementsByTagName && document.all) ? true : false;
var arrowUp, arrowDown;

if (ie5 || dom)
	initSortTable();

function initSortTable() {
	arrowUp = document.createElement("SPAN");
	var tn = document.createTextNode("5");
	arrowUp.appendChild(tn);
	arrowUp.className = "arrow";

	arrowDown = document.createElement("SPAN");
	var tn = document.createTextNode("6");
	arrowDown.appendChild(tn);
	arrowDown.className = "arrow";
}



function sortTable(tableNode, nCol, bDesc, sType) {
	var tBody = tableNode.tBodies[0];
	var trs = tBody.rows;
	var trl= trs.length;
	var a = new Array();
	
	for (var i = 0; i < trl; i++) {
		a[i] = trs[i];
	}
	
	var start = new Date;
	window.status = "Sorting data...";
	a.sort(compareByColumn(nCol,bDesc,sType));
	window.status = "Sorting data done";
	
	for (var i = 0; i < trl; i++) {
		tBody.appendChild(a[i]);
		window.status = "Sıralanan satır " + (i + 1) + " / " + trl +
						" (Sıralama Süresi: " + (new Date - start) + "ms)";
	}
	
	// check for onsort
	if (typeof tableNode.onsort == "string")
		tableNode.onsort = new Function("", tableNode.onsort);
	if (typeof tableNode.onsort == "function")
		tableNode.onsort();
}

function CaseInsensitiveString(s) {
	return String(s).toUpperCase();
}

function parseDate(s) {
	return Date.parse(s.replace(/\-/g, '/'));
}

/* alternative to number function
 * This one is slower but can handle non numerical characters in
 * the string allow strings like the follow (as well as a lot more)
 * to be used:
 *    "1,000,000"
 *    "1 000 000"
 *    "100cm"
 */

function toNumber(s) {
    return Number(s.replace(/[^0-9\.]/g, ""));
}

function compareByColumn(nCol, bDescending, sType) {
	var c = nCol;
	var d = bDescending;
	
	var fTypeCast = String;
	
	if (sType == "Number")
		fTypeCast = Number;
	else if (sType == "Date")
		fTypeCast = parseDate;
	else if (sType == "CaseInsensitiveString")
		fTypeCast = CaseInsensitiveString;

	return function (n1, n2) {
		if (fTypeCast(getInnerText(n1.cells[c])) < fTypeCast(getInnerText(n2.cells[c])))
			return d ? -1 : +1;
		if (fTypeCast(getInnerText(n1.cells[c])) > fTypeCast(getInnerText(n2.cells[c])))
			return d ? +1 : -1;
		return 0;
	};
}

function sortColumnWithHold(e) {
	// find table element
	var el = ie5 ? e.srcElement : e.target;
	var table = getParent(el, "TABLE");
	
	// backup old cursor and onclick
	var oldCursor = table.style.cursor;
	var oldClick = table.onclick;
	
	// change cursor and onclick	
	table.style.cursor = "wait";
	table.onclick = null;
	
	// the event object is destroyed after this thread but we only need
	// the srcElement and/or the target
	var fakeEvent = {srcElement : e.srcElement, target : e.target};
	
	// call sortColumn in a new thread to allow the ui thread to be updated
	// with the cursor/onclick
	window.setTimeout(function () {
		sortColumn(fakeEvent);
		// once done resore cursor and onclick
		table.style.cursor = oldCursor;
		table.onclick = oldClick;
	}, 100);
}

function sortColumn(e) {
	var tmp = e.target ? e.target : e.srcElement;
	var tHeadParent = getParent(tmp, "THEAD");
	var el = getParent(tmp, "TD");

	if (tHeadParent == null)
		return;
		
	if (el != null) {
		var p = el.parentNode;
		var i;

		// typecast to Boolean
		el._descending = !Boolean(el._descending);

		if (tHeadParent.arrow != null) {
			if (tHeadParent.arrow.parentNode != el) {
				tHeadParent.arrow.parentNode._descending = null;	//reset sort order		
			}
			tHeadParent.arrow.parentNode.removeChild(tHeadParent.arrow);
		}

		if (el._descending)
			tHeadParent.arrow = arrowUp.cloneNode(true);
		else
			tHeadParent.arrow = arrowDown.cloneNode(true);

		el.appendChild(tHeadParent.arrow);

			

		// get the index of the td
		var cells = p.cells;
		var l = cells.length;
		for (i = 0; i < l; i++) {
			if (cells[i] == el) break;
		}

		var table = getParent(el, "TABLE");
		// can't fail
		
		sortTable(table,i,el._descending, el.getAttribute("type"));
	}
}


function getInnerText(el) {
	if (ie5) return el.innerText;	//Not needed but it is faster
	
	var str = "";
	
	var cs = el.childNodes;
	var l = cs.length;
	for (var i = 0; i < l; i++) {
		switch (cs[i].nodeType) {
			case 1: //ELEMENT_NODE
				str += getInnerText(cs[i]);
				break;
			case 3:	//TEXT_NODE
				str += cs[i].nodeValue;
				break;
		}
		
	}
	
	return str;
}

function getParent(el, pTagName) {
	if (el == null) return null;
	else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())	// Gecko bug, supposed to be uppercase
		return el;
	else
		return getParent(el.parentNode, pTagName);
}
/*
String Default. Compare the string values as it is. 
CaseInsensitiveString Compare the string values but 'a' and 'A' are treated equally. 
Number Casts the text to a number before doing the comparison 
Date Casts the text to a date before doing the comparison. Warning! The JS Date object does not handle strings representing dates correctly. I guess an american designed the Date class :-( If you get into trouble with dates try creating your own parseDate function and replace the current one. 
*/