//UTILITY
function PrintPage(){
    if(document.getElementById('PrintArea')==null) return;
    var printstr = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>"+ document.title +"</title>"+
    "<link href='/App_Themes/layout.css' rel='stylesheet' type='text/css'>"+
    "</head><body>"+
    document.getElementById('PrintArea').innerHTML;
    "</body></html>";
    
    winPrint = open();
    winPrint.document.open();
    winPrint.document.write(printstr);
    winPrint.document.close();
}

function Alert(msg){
	window.status=msg;
}
function GetFileNameWithoutExtension(filename){
	idx = filename.lastIndexOf('.');
	return filename.substring(0,idx);
}
function GetFileName(filename){
	idx = filename.lastIndexOf('/');
	filename = filename.substring(idx+1);
	if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	if(filename.indexOf('?')>-1) filename = filename.substring(0,filename.indexOf('?'));
	if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	
	return filename;
}
function GetCMSPageFileName(filename){
	idx = filename.lastIndexOf('/');
	filename = filename.substring(idx+1);
	if(filename.toLowerCase().indexOf('default.aspx')==0){
	    if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	    if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	}
	else
	{
	    if(filename.indexOf('#')>-1) filename = filename.substring(0,filename.indexOf('#'));
	    if(filename.indexOf('?')>-1) filename = filename.substring(0,filename.indexOf('?'));
	    if(filename.indexOf('&')>-1) filename = filename.substring(0,filename.indexOf('&'));
	}
	
	return filename;
}
function GetFileExtension(filename){
	idx = filename.lastIndexOf('.');
	return filename.substring(idx);
}

function getSize( dimension) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
	if(dimension=="w")
		return myWidth;
	else
		return myHeight;
}
function pageY(element) {
	  var curTop = 0;
	  if (document.getElementById || document.all) {
		while (element.offsetParent) {
		  curTop += element.offsetTop;
		  element = element.offsetParent;
		}
	  }
	  return curTop;
}
function pageX(element) {
	  var curTop = 0;
	  if (document.getElementById || document.all) {
		while (element.offsetParent) {
		  curTop += element.offsetLeft;
		  element = element.offsetParent;
		}
	  }
	  return curTop;
}
function pageSize(arg) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if(arg=='w')  return myWidth;
  else          return myHeight;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
function getElementTopPosition(e){
    var y=0;
    while(e){
    y+=e.offsetTop+((e.clientTop!=null)?e.clientTop:0);
    e=e.offsetParent;
    }
    return y;
}

function selectAllCheckBox(checkboxListObject){
    if(checkboxListObject==null) return;
    var allCheck = checkboxListObject.getElementsByTagName('input');
    for (var i = 0; i < allCheck.length; i++) { 
        type = allCheck[i].getAttribute("type"); 
        if ( type == "checkbox") { 
            allCheck[i].checked = true;
        }
    }
    return false;
}

function PressButtonOnEnter(obj, e, buttonid)
{ 
  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);

  if (bt)
  { 
    if (evt.keyCode == 13)
    { 
      clearPasswordField(obj);
      bt.click(); 
      return false; 
    } 
  } 
}

// *** FINE UTILITY

var callBackControl = "";

function OpenDialog(currentCallBackControl, dialog, type) 
{
    callBackControl = currentCallBackControl;
    $find(dialog).open(type); 
}

function ImageManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultImageObject = args.Result;

    var txt = $get(callBackControl);
    if (document.all) 
    {
        txt.value = selectedItem.getPath();
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}
function DocumentManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultDocumentObject = args.Result;

    var txt = $get(callBackControl);
    if (document.all) 
    {
        txt.value = selectedItem.getPath(); ;
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}
function FlashManagerFunction(sender, args) 
{
    var selectedItem = args.SelectedItem;
    var resultDocumentObject = args.Result;
    var txt = $get(callBackControl);

    if (document.all) 
    {
        txt.value = selectedItem.getPath();
    }
    else 
    {
        txt.value = selectedItem.getPath();
    }
}  
