function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		
		preloadFlag = true;
	}
}

//News
var interval;
yukseklik=0; 
ust=yukseklik;
HrCursor=0;
HrCursorTop=0;
dikeyuzunluk=200
speed=75
waitingspeed=1000

function ayarla()
{
	yukseklik=document.all.news.offsetHeight;				
	if (document.all('hr0')!=null)
	{HrCursorTop=document.all('hr0').offsetTop;	
	}				
	if (yukseklik==0) {setTimeout("ayarla()",60)};				
}

function dongu()
{
	if (ust<=-yukseklik) {ust=dikeyuzunluk};
	if (scrolling) 
	{
	ust=ust-1;
	document.all.news.style.top=ust;
	}
	if (ust==-HrCursorTop)
	{	
	cursorchange();
	interval=setTimeout("dongu()",waitingspeed)
	}
	else
	{
	interval=setTimeout("dongu()",speed)
	}
}

function cursorchange()
{
	HrCursor=HrCursor+1;
	if (document.all('hr'+HrCursor)!=null)
	{ HrCursorTop=document.all('hr'+HrCursor).offsetTop;	
	}
	else
	{
	HrCursor=0;
	HrCursorTop=0;
	if (document.all('hr0')!=null)
		{HrCursorTop=document.all('hr0').offsetTop;
		}
	}				
}

function NewsWrite(SubDikeyuzunluk,SubSpeed,SubWaitingspeed)
{
dikeyuzunluk=SubDikeyuzunluk
speed=SubSpeed
waitingspeed=SubWaitingspeed
scrolling=true
document.all('news').innerHTML='<label onmousemove="javascript:scrolling=false;" onmouseout="javascript:scrolling=true;" > '
  + document.all('news').innerHTML +'</label>'
ayarla();
dongu();	
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function mOvr(src,clrOver) {
    if (!src.contains(event.fromElement)) {
	  //src.style.cursor = 'hand';
	  src.bgColor = clrOver;	  
	}
  }

 function mOut(src,clrIn) {
		if (!src.contains(event.toElement)) {
			src.style.cursor = 'default';
			src.bgColor = clrIn;
		}
  }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

 function ShowHideBlock(blockId)
        {
            if (document.getElementById(blockId).style.display == "block")
            {
                document.getElementById(blockId).style.display = "none";
            }
            else
            {
                document.getElementById(blockId).style.display = "block";
            }
        }

function openDocument(docURL, w, h) {
 var opt='scrollbars=no,toolbar=no,status=no,menubar=no,width='+w+',height='+h+',left=100,top=100';
 imgWin = window.open(docURL,'',opt);
}

function getScreenSize() {
    var screenW = 1024, screenH = 768;
    if (parseInt(navigator.appVersion)>3) {
    screenW = screen.width;
    screenH = screen.height;
    }
    else if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
        var jToolkit = java.awt.Toolkit.getDefaultToolkit();
        var jScreenSize = jToolkit.getScreenSize();
        screenW = jScreenSize.width;
        screenH = jScreenSize.height;
    }
    return new Array(screenW, screenH);
}

function popImage(pictureID) 
        {
            var screen = getScreenSize();
            var opt='scrollbars=no,width=150,height=100,left=100,top=100';
            
            imgWin = window.open('','',opt);
            with (imgWin.document) {
                    writeln('<html><head><title>...</title><style type="text/css">body { margin: auto; margin:0; padding: 0;}</style>');
                    writeln('<sc'+'ript type="text/javascript">');
                    writeln('function resizePopup() {');
                    writeln('width = document.images[0].width ; ');
                    writeln('height = document.images[0].height ; ');
                    writeln('if ('+ screen[0]+' < width || '+screen[1]+' < height) { width = '+screen[0]+'/2; height='+screen[1]+'/2; document.images[0].width = width; document.images[0].height = height;}');
                    writeln('window.resizeTo(width+10, height+70);');
                    writeln('if (window.innerWidth) { window.innerWidth = width ; window.innerHeight = height; }');
                    writeln('}');
                    writeln('</s' + 'cript>');
                    writeln('</head><body bgcolor="#ffffff" onload="resizePopup();">')
                    writeln('<img src="../Picture/PictureHandler.ashx?pictureID='+pictureID+'" onclick="window.close();" border="0" style="position: absolute; left: 0px; top: 0px; cursor: pointer;"/></body></html>');
                    close();
            }
        }
                         
                 
function change_picture(img_name, img_src) 
{
    var image = document.getElementById(img_name);
    image.setAttribute("src", img_src);            
}   

var pictureID;

function set_pictureID(tmpID) 
{
    pictureID = tmpID;
}
function popImage2() 
{
    var screen = getScreenSize();
    var opt='scrollbars=no,width=150,height=100,left=100,top=100';
    
    imgWin = window.open('','',opt);
    with (imgWin.document) {
            writeln('<html><head><title>...</title><style type="text/css">body { margin: auto; margin:0; padding: 0;}</style>');
            writeln('<sc'+'ript type="text/javascript">');
            writeln('function resizePopup() {');
            writeln('width = document.images[0].width ; ');
            writeln('height = document.images[0].height ; ');
            writeln('if ('+ screen[0]+' < width || '+screen[1]+' < height) { width = '+screen[0]+'/2; height='+screen[1]+'/2; document.images[0].width = width; document.images[0].height = height;}');
            writeln('window.resizeTo(width+10, height+70);');
            writeln('if (window.innerWidth) { window.innerWidth = width ; window.innerHeight = height; }');
            writeln('}');
            writeln('</s' + 'cript>');
            writeln('</head><body bgcolor="#ffffff" onload="resizePopup();">')
            writeln('<img src="../Picture/PictureHandler.ashx?pictureID='+pictureID+'" onclick="window.close();" border="0" style="position: absolute; left: 0px; top: 0px; cursor: pointer;"/></body></html>');
            close();
    }
}
            
function popImage3(image_path) 
{
    var screen = getScreenSize();
    var opt='scrollbars=no,width=150,height=100,left=100,top=100';
    
    imgWin = window.open('','',opt);
    with (imgWin.document) {
            writeln('<html><head><title>...</title><style type="text/css">body { margin: auto; margin:0; padding: 0;}</style>');
            writeln('<sc'+'ript type="text/javascript">');
            writeln('function resizePopup() {');
            writeln('width = document.images[0].width ; ');
            writeln('height = document.images[0].height ; ');
            writeln('if ('+ screen[0]+' < width || '+screen[1]+' < height) { width = '+screen[0]+'/2; height='+screen[1]+'/2; document.images[0].width = width; document.images[0].height = height;}');
            writeln('window.resizeTo(width+10, height+70);');
            writeln('if (window.innerWidth) { window.innerWidth = width ; window.innerHeight = height; }');
            writeln('}');
            writeln('</s' + 'cript>');
            writeln('</head><body bgcolor="#ffffff" onload="resizePopup();">')
            writeln('<img src="'+image_path+'" onclick="window.close();" border="0" style="position: absolute; left: 0px; top: 0px; cursor: pointer;"/></body></html>');
            close();
    }
}
        
function SelectIt (idVal) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
        if (idVal.indexOf ('SelectThis') != -1) 
        {
            if(frm.elements[i].checked == false) 
            {
                frm.elements[1].checked = false;
            }
        }
    }

}                 



//Treeview With Checkbox - Start
function OnTreeClick(evt)
   {
        var src = window.event != window.undefined ? window.event.srcElement : evt.target;
        var isChkBoxClick = (src.tagName.toLowerCase() == "input" && src.type == "checkbox");
        if(isChkBoxClick)
        {
            var parentTable = GetParentByTagName("table", src);
            var nxtSibling = parentTable.nextSibling;
            if(nxtSibling && nxtSibling.nodeType == 1)//check if nxt sibling is not null & is an element node
            {
                if(nxtSibling.tagName.toLowerCase() == "div") //if node has children
                {
                    //check or uncheck children at all levels
                    CheckUncheckChildren(parentTable.nextSibling, src.checked);
                }
            }
            //check or uncheck parents at all levels
            CheckUncheckParents(src, src.checked);
        }
   } 
   function CheckUncheckChildren(childContainer, check)
   {
      var childChkBoxes = childContainer.getElementsByTagName("input");
      var childChkBoxCount = childChkBoxes.length;
      for(var i = 0; i<childChkBoxCount; i++)
      {
        childChkBoxes[i].checked = check;
      }
   }
   function CheckUncheckParents(srcChild, check)
   {
       var parentDiv = GetParentByTagName("div", srcChild);
       var parentNodeTable = parentDiv.previousSibling;
       
       if(parentNodeTable)
        {
            var checkUncheckSwitch;
            
            if(check) //checkbox checked
            {
                var isAllSiblingsChecked = AreAllSiblingsChecked(srcChild);
                if(isAllSiblingsChecked)
                    checkUncheckSwitch = true;
                else    
                    return; //do not need to check parent if any(one or more) child not checked
            }
            else //checkbox unchecked
            {
                checkUncheckSwitch = false;
            }
            
            var inpElemsInParentTable = parentNodeTable.getElementsByTagName("input");
            if(inpElemsInParentTable.length > 0)
            {
                var parentNodeChkBox = inpElemsInParentTable[0]; 
                parentNodeChkBox.checked = checkUncheckSwitch; 
                //do the same recursively
                CheckUncheckParents(parentNodeChkBox, checkUncheckSwitch);
            }
        }
   }
   function AreAllSiblingsChecked(chkBox)
   {
     var parentDiv = GetParentByTagName("div", chkBox);
     var childCount = parentDiv.childNodes.length;
     for(var i=0; i<childCount; i++)
     {
        if(parentDiv.childNodes[i].nodeType == 1) //check if the child node is an element node
        {
            if(parentDiv.childNodes[i].tagName.toLowerCase() == "table")
            {
               var prevChkBox = parentDiv.childNodes[i].getElementsByTagName("input")[0];
              //if any of sibling nodes are not checked, return false
              if(!prevChkBox.checked) 
              {
                return false;
              } 
            }
        }
     }
     return true;
   }
   //utility function to get the container of an element by tagname
   function GetParentByTagName(parentTagName, childElementObj)
   {
      var parent = childElementObj.parentNode;
      while(parent.tagName.toLowerCase() != parentTagName.toLowerCase())
      {
         parent = parent.parentNode;
      }
    return parent;    
   }
   //Treeview With Checkbox - End
   
   function select_deselectAll (chkVal, idVal) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
        // Look for our Header Template's Checkbox
        if (idVal.indexOf ('CheckAll') != -1) 
        {
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if(chkVal == true) 
            {
                frm.elements[i].checked = true;
            } 
            else 
            {
                frm.elements[i].checked = false;
            }
            // Work here with the Item Template's multiple checkboxes
        } 
        else if (idVal.indexOf ('CheckThis') != -1) 
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false) 
            {
                frm.elements[1].checked = false; //Uncheck main select all checkbox
            }
        }
    }
 }
