var isDHTML=0;
var isID=0;
var isAll=0;
var isLayers=0;
var isIE=0;
if(navigator.appName.indexOf('Microsoft')!=-1)isIE=1;
if (document.getElementById){
	isID=1;
	isDHTML=1;
}else{
	if(document.all){
		isAll=1;
		isDHTML=1;
	}else{
		if((navigator.appName.indexOf('Netscape')!=-1)
									  //&&(browserVersion>=4)
									  ){
			isLayers=1;
			isDHTML=1;
		}
	}		
}

function findDom(objectID,withStyle){
	if (withStyle==1){
		if(isID){ return (document.getElementById(objectID).style);}
		else{
			if (isAll){return(document.all[objectID].style);}
			else{if(isLayers)return (document.layers[objectID]);}
		}
	}else{
		if(isID){ return (document.getElementById(objectID));}
		else{
			if (isAll){return(document.all[objectID]);}
			else{if(isLayers)return (document.layers[objectID]);}
		}
	}
}

if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } 
else { http = new XMLHttpRequest(); }
	  
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_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_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 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 doBlink() {
  var blink = document.all.tags("blink")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  if (document.all)
    setInterval("doBlink()",800)
}
window.onload = startBlink;

function pencereAc(link,pencere,w,h) {
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	mytop = mytop - 150;
	ayarlar="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
	//ayarlar= ayarlar + ",top=" + mytop + ",left=" + myleft;
	window.open(link,pencere,ayarlar);
}

function pdfGoruntule(link,pencere,w,h) {
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	mytop = mytop - 150;
	ayarlar="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	//ayarlar= ayarlar + ",top=" + mytop + ",left=" + myleft;
	window.open(link,pencere,ayarlar);
}

//girilen verinin sayi olup olmadığını kontrol için kullanılır
function numerikSonuc(nField){
	var currStr = nField.value;
	if (!/^\d+$/.test(currStr)){
		currStr = currStr.substring(0,currStr.length-1);
		nField.value = currStr;
	}
} 

function alpha(cur,which){
	if (which==0) cur.filters.alpha.opacity=100
	else cur.filters.alpha.opacity=50
}


function isNumeric(fld,e,toplamUz,decimalPart){

//<input type=text name=test length=15 onKeyPress="return(currencyFormat(this,',','.',event))">
  var sep = 0;
  var key = '';
  var i = j = k = m = n = 0;
  var len = len2 = 0;
  var strCheck = '0123456789.';
  var decSep = '.';
  var tamSayiAlan = 0;
  var aux = '';
  //var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCode = (document.all) ? e.keyCode : e.which;
  
  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key  
  
  len = fld.value.length;  
  if(key == '.') k = 1; else k = 0;
  for(i=0; i < len; i++){ 
  	if(m > 0) m = m + 1;
  	if (fld.value.charAt(i) == decSep){ k = k + 1;	m = k; }	
  }
  if(k > 1) return false;  
  tamSayiAlan = toplamUz - decimalPart; //tam sayi alan uzunlugu
  if(k == 0 && len == tamSayiAlan ) { fld.value = fld.value+'.'; } //eger tam sayi alani belirtilenden fazla olacak ise . koy 
  if(len == 0 && key == '.')  { fld.value = '0.'; key = ''; } //ilk olarak noktaya basiliyor ise
  //if(len - m == decimalPart + 1) key = ''; // eger decimal alan belirtilen uzunluga ulasmis ise yazma
  if(k > 0 && m == decimalPart + 1) key = '';
  
  aux = '';
  m = 0;
  len = fld.value.length;  
  for(i=0; i < len; i++){
	if (strCheck.indexOf(fld.value.charAt(i))!=-1 && k < 2) aux += fld.value.charAt(i);
  }
  if(k < 2 && len <= toplamUz) aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len > 0) fld.value = aux; 
  
  return false;
}

function isNumericTus(fld,e,toplamUz,decimalPart){

  var sep = 0;
  var key = '';
  var i = j = k = m = n = 0;
  var len = len2 = 0;
  var strCheck = '0123456789.';
  var decSep = '.';
  var tamSayiAlan = 0;
  var aux = '';
  //var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCode = (document.all) ? e.keyCode : e.which;
  
  if(whichCode == 44) whichCode = 46;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key  
  
  len = fld.value.length;  
  if(key == '.') k = 1; else k = 0;
  for(i=0; i < len; i++){ 
  	if(m > 0) m = m + 1;
  	if (fld.value.charAt(i) == decSep){ k = k + 1;	m = k; }	
  }
  if(k > 1) return false;  
  tamSayiAlan = toplamUz - decimalPart; //tam sayi alan uzunlugu
  if(k == 0 && len == tamSayiAlan ) { fld.value = fld.value+'.'; } //eger tam sayi alani belirtilenden fazla olacak ise . koy 
  if(len == 0 && key == '.')  { fld.value = '0.'; key = ''; } //ilk olarak noktaya basiliyor ise
  //if(len - m == decimalPart + 1) key = ''; // eger decimal alan belirtilen uzunluga ulasmis ise yazma
  if(k > 0 && m == decimalPart + 1) key = '';
  
  aux = '';
  m = 0;
  len = fld.value.length;  
  for(i=0; i < len; i++){
	if (strCheck.indexOf(fld.value.charAt(i))!=-1 && k < 2) aux += fld.value.charAt(i);
  }
  if(k < 2 && len <= toplamUz) aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len > 0) fld.value = aux; 
  
  return false;
}



function kalan(sec,maxharf,yazAlan){
	var msjtxt;
	var msjgen;
	var azalma;
	var kalanh;
	if (sec.value != null){
		msjtxt = sec.value;
		msjgen = msjtxt.length;
		if (msjgen > maxharf){
			sec.value=msjtxt.substring(0,maxharf);
			kalanh = 0;
		}
		else {
			kalanh = maxharf - msjgen;
		}
		yazAlan.value = kalanh;
	}
} 

function currencyFormatUz123(fld, e, uz) {
  milSep = ',';

  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  //var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCode = (document.all) ? e.keyCode : e.which;
  
  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  //else len = fld.value.length - 1;
  for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0')) break;
  aux = '';
  for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  if (whichCode != 8) aux += key;
  len = aux.length;
  if (len <= uz) {
    aux2 = '';
    for (j = 0, i = len-1; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
  }
  return false;
}

function currencyFormatUz(fld, e, uz) {
  milSep = ',';
  decSep = '.';

  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  //var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCode = (document.all) ? e.keyCode : e.which;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2 && len <= uz) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}

function currencyFormat(fld, milSep, decSep, e) {
	if(!milSep || !decSep){
		milSep = '.';
		decSep = ',';
	}
  //<input type=text name=test length=15 onKeyPress="return(currencyFormat(this,',','.',event))">
  var sep = 0;
  var key = '';
  var i = j = 0;
  var len = len2 = 0;
  var strCheck = '0123456789';
  var aux = aux2 = '';
  //var whichCode = (window.Event) ? e.which : e.keyCode;
  var whichCode = (document.all) ? e.keyCode : e.which;

  if (whichCode == 13) return true;  // Enter
  if (whichCode == 8) return true;  // Delete
  key = String.fromCharCode(whichCode);  // Get key value from key code
  if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
  len = fld.value.length;
  for(i = 0; i < len; i++)
  if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
  aux = '';
  for(; i < len; i++)
  if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
  aux += key;
  len = aux.length;
  if (len == 0) fld.value = '';
  if (len == 1) fld.value = '0'+ decSep + '0' + aux;
  if (len == 2) fld.value = '0'+ decSep + aux;
  if (len > 2) {
    aux2 = '';
    for (j = 0, i = len - 3; i >= 0; i--) {
      if (j == 3) {
        aux2 += milSep;
        j = 0;
      }
      aux2 += aux.charAt(i);
      j++;
    }
    fld.value = '';
    len2 = aux2.length;
    for (i = len2 - 1; i >= 0; i--)
    fld.value += aux2.charAt(i);
    fld.value += decSep + aux.substr(len - 2, len);
  }
  return false;
}

function str_replace(search, replace, subject, count) {
     var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function onKeyDown(e) {
	 
	 var keyCode = (document.all) ? e.keyCode : e.which;
	
	/*if ( (event.altKey) || ((keyCode == 8) &&	(event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password")) ||	((event.ctrlKey) && ((keyCode == 78) || (keyCode == 82)) ) || (keyCode == 116) ) {
	keyCode = 0;
	e.returnValue = false;
	}*/
	if((keyCode == 8) && (e.srcElement.type != "text" && e.srcElement.type != "textarea" && e.srcElement.type != "password") ){ keyCode = 0; e.returnValue = false; }
	if(keyCode == 8 && (e.srcElement.disabled == true || e.srcElement.readOnly == true)){ keyCode = 0; e.returnValue = false; }
}

function cancelBack(){
	if ((event.keyCode == 8 ||
	   (event.keyCode == 37 && event.altKey) ||
	   (event.keyCode == 39 && event.altKey))
		&&
	   (event.srcElement.form == null || event.srcElement.isTextEdit == false)
	  )
	{
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

function getBrowserHeight() {
	var intH = 0;
	var intW = 0;
   
	if(typeof window.innerWidth  == 'number' ) {
	   intH = window.innerHeight;
	   intW = window.innerWidth;
	} 
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		intH = document.documentElement.clientHeight;
		intW = document.documentElement.clientWidth;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		intH = document.body.clientHeight;
		intW = document.body.clientWidth;
	}

	return { width: parseInt(intW), height: parseInt(intH) };
} 

function setLayerPosition() {
	var shadow = parent.document.getElementById("shadow");
	
	/*var bws = getBrowserHeight();
	shadow.style.width = "100%";
	shadow.style.height = screen.height + 68 +"px";	*/
	//shadow.style.height = htmlheight +"px";	
	//shadow.style.margin = "auto";
	shadow.style.cssText = "min-height:100%; height:auto !important; height:100%;width:100%;";
	shadow = null;
}

function showLayer() {
	setLayerPosition();

	var shadow = parent.document.getElementById("shadow");
	shadow.style.display = "block"; 
	shadow.style.opacity = "0.1"; 
	shadow.style.filter = "alpha(opacity=10)"; 
	shadow = null;
}

function hideLayer() {
	var shadow = parent.document.getElementById("shadow");
	shadow.style.display = "none"; 
	shadow = null;
}


//var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
function autoTab(fld,e,uz) {
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (document.all) ? e.keyCode : e.which;
	
	key = String.fromCharCode(whichCode);  // Get key value from key code
 	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	else {
		if( fld.value.length >= uz ) { 
			fld.value = fld.value.slice( 0, uz ); 
			fld.form[( getIndex( fld ) + 1 ) % fld.form.length].focus(); 	
		}
	}
	return false;
} 
 
function getIndex( input ) { 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 ) 
	if ( input.form[i] == input ) { 
		index = i; 
	} else { 
		i++; 
	} 
	return index; 
} 


//window.onresize = setLayerPosition;


