var panelTimer;


function 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=findObj(n,d.layers[i].document);
		if(!x && document.getElementById) x=document.getElementById(n); return x;
		}
		
		var timeout	= 100;
		var closetimer	= 0;
		var ddmenuitem	= 0;


function HideVisibleId(what) {document.getElementById(what).style.visibility = 'hidden';}
function ShowVisibleId(what) {document.getElementById(what).style.visibility = 'visible';}

function HideAttPanel(){document.getElementById("AttPanGenId").style.display="none";}
function ShowAttPanel(){document.getElementById("AttPanGenId").style.display="block";}


function HideDisplayId(what){document.getElementById(what).style.display="none";}
function ShowDisplayId(what){
			var element=document.getElementById(what);
			element.style.opacity = 1.0;
        	element.style.MozOpacity = 1.0;
        	element.style.KhtmlOpacity = 1.0;
        	element.style.filter = "alpha(opacity=" + 100 + ");";document.getElementById(what).style.display="block";}


function ShowPanel(what,milSec){
			clearTimeout(panelTimer);
		
		
			//panelTimer = setTimeout("HideDisplayId('" + what + "')",milSec); ilk
			panelTimer = setTimeout("fadeOutElem('" + what + "',300)",milSec);
			//fadeOutElem(what,duration)
			
			ShowDisplayId(what);
			}




function ToogleId(what) {
if(document.getElementById(what).style.display=="none")
	{document.getElementById(what).style.display="block";}
else 
if(document.getElementById(what).style.display=="block")
	{document.getElementById(what).style.display="none";}
}

function ToogleIdLink(what,clickID)
{


	if(findObj(what).style.visibility=="hidden")
	{
	findObj(what).style.visibility="visible";
	findObj(clickID).innerHTML="<img src='/images/game_images/icon_Close.png' height='10' align='absmiddle' border='1' />";
	}
	else 
	if(findObj(what).style.visibility=="visible")
	{
		findObj(what).style.visibility="hidden";
		findObj(clickID).innerHTML="<img src='/game_images/icon_MsgReplied.png' height='13' align='absmiddle' border='0' />";
	}


}



function ToogleBlockIdLink(what,clickID,ShowLbl,HideLbl)
{


	if(findObj(what).style.display=="none" || findObj(what).style.display== null)
	{
	findObj(what).style.display="table-row";
	findObj(clickID).innerHTML = HideLbl + " <img src='/images/game_images/icon_Close.png' height='16' align='absmiddle' border='1' />";
	}
	else 
	if(findObj(what).style.display=="table-row")
	{
		findObj(what).style.display="none";
		findObj(clickID).innerHTML= ShowLbl +  " <img src='/images/game_images/icon_MsgReplied.png' height='16' align='absmiddle' border='0' />";
	}


}




function ShowIdLink(what,clickID) {document.getElementById(what).style.visibility = 'visible'; findObj(clickID).innerHTML="<img src='images/left_arrow_lst.png' height='15' align='absmiddle' border='0' />";}


///=========================================================================
function  UpdateElemHtml(ElemId,Html)
{
				findObj(ElemId).innerHTML =Html;
	}


function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 

document.onkeypress = stopRKey; 


///=========================================================================


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 GotoUrl(url)

{
	top.location.href=url;	
	}
///=========================================================================
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/*
Author: Robert Hashemian
http://www.hashemian.com/

You can use this code in any manner so long as the author's
name, Web address and this disclaimer is kept intact.
********************************************************
Usage Sample:

<script language="JavaScript" src="http://www.hashemian.com/js/NumberFormat.js"></script>
<script language="JavaScript">
document.write(FormatNumberBy3("1234512345.12345", ".", ","));
</script>
*/

// function to format a number with separators. returns formatted number.
// num - the number to be formatted
// decpoint - the decimal point character. if skipped, "." is used
// sep - the separator character. if skipped, "," is used
function FormatNumberBy3(num, decpoint, sep) {
  // check for missing parameters and use defaults if so
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  // need a string for operations
  num = num.toString();
  // separate the whole number and the fraction if possible
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    // reverse the digits. regexp works from left to right.
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    // add seperators. but undo the trailing one, if there
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    // reverse again to get back the number
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    // add the fraction back in, if it was there
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}

///=========================================================================
 
function showErr(stext)
{	
	findObj("errPanelBody").innerHTML=stext; 
	ShowDisplayId("errPanel");
	OpenModal();
}

function hideErr()
{
	HideDisplayId("errPanel");
	CloseModal();
}
///=========================================================================
//write errpanel
//window.onload= create_err_pan();
//
//function create_err_pan()
//{
//var newdiv1 = document.createElement('div'); 
//newdiv1.setAttribute("id", "errPanel");
//newdiv1.className = "errPanel";
//
//var newdiv2 = document.createElement('div'); 
//newdiv2.setAttribute("id", "errPanelBody");
//newdiv2.appendChild(newdiv1);
//if(document.body)
//document.body.appendChild(newdiv1);
//}

///=========================================================================
//modal
 function OpenModal()
    { 
       // document.getElementById ('ModalPopupDiv').style.visibility='visible';
//        document.getElementById ('ModalPopupDiv').style.display='';
//        document.getElementById ('ModalPopupDiv').style.top= Math.round ((document.documentElement.clientHeight/2)+ document.documentElement.scrollTop)-100 + 'px';
//        document.getElementById ('ModalPopupDiv').style.left='400px';
        
        document.getElementById ('MaskedDiv').style.display='';
        document.getElementById ('MaskedDiv').style.visibility='visible';
        document.getElementById ('MaskedDiv').style.top='0px';
        document.getElementById ('MaskedDiv').style.left='0px';
        document.getElementById ('MaskedDiv').style.width=  document.documentElement.clientWidth + 'px';
        document.getElementById ('MaskedDiv').style.height= document.documentElement.clientHeight+ 'px';
    }
    function CloseModal()
    {
        document.getElementById ('MaskedDiv').style.display='none';
       // document.getElementById ('ModalPopupDiv').style.display='none';
    }
    
//end modal

function GetChkBoxVal(id)
{

	if (findObj(id).checked)
		{return findObj(id).value;}  else {return "";}
	}

function encodeTextarea(str) 
{		//tek başına kullanılan textarea içerikleri post edilirken encode etmeden önce crlf değiştir.
		str = str.replace(/\n/g,"<br>")
	
		return encodeURIComponent(str);
}


