/* ================================================================
    Window related Functions
  ================================================================ */
//--Open a window at the center of the screen
function openCenteredWindow(url, name, width, height, status, scrollbars, openerName) {
	var x = 0;
	var y = 0;
	if (screen) x = (screen.availWidth - width) / 2;
	if (screen) y = (screen.availHeight - height) / 2;
	if (!status) status == '';
	if (!openerName) openerName == '';
	var reference = openPositionedWindow(url, name, width, height, x, y, status, scrollbars, openerName);
	return reference;
}	

//-- Function to open a new window with specified url & window attributes

function openWin(url,strwindowName,attributes) {        
   attributes  = attributes + ",top=20, left=30"
  //alert(attributes);
   var swin = attributes.split(",");
   var heightswin;
   var widthswin;
   for (i=0;i<swin.length;i++)
   {
    if (swin[i].indexOf("height") != -1)
    {
		hswin = swin[i].split("=");
		heightswin = parseInt(hswin[1]) + 30;
    }
    else if (swin[i].indexOf("width") != -1)    
    {
		wswin = swin[i].split("=");
		widthswin = parseInt(wswin[1]) + 10;    
    }
   }
  //  alert(heightswin);
  //  alert(widthswin);
  
    windowName = window.open(url,strwindowName,attributes);        
    windowName.focus();    
    windowName.resizeTo(widthswin,heightswin);
    return windowName
}

function centerWindow(){
    w = screen.availWidth;
    h = screen.availHeight;
    w = w  -  document.body.clientWidth
    h =  h - document.body.clientHeight
    window.moveTo(w/2,h/2)
}

/* ================================================================
    BalloonHelp Functions
  ================================================================ */
var helpTimer
//-- Function to show balloon 
function showBalloonHelp(width,message,timeDelay) {

	if (message==""){return;}
	//Get balloon Div object	       
	balloonObj = document.all['balloon']
	//Set time for showing balloon ( Delaying )
	if ( timeDelay == "undefined" ){
		timeDelay = 700
	}
	helpTimer = window.setTimeout('balloonObj.style.visibility="visible"',timeDelay); 

	balloonObj.innerHTML = message;	  	
        balloonObj.style.width = eval(width);
	balloonObj.style.backgroundColor="#ffffea";
	balloonObj.style.padding = '10px';
	balloonObj.style.color = 'black';
	balloonObj.style.textalign = "justify";
	balloonObj.style.height ="1ex";
	balloonObj.style.border= "1px";
	balloonObj.style.fontSize ="8pt";
	balloonObj.style.fontFamily ="Arial";
	balloonObj.style.border= "1pt black solid";
       // Code for checking popup not  to go out of window
       // ---- More refinment required ------
	if ( ((document.body.scrollLeft + window.event.clientX) + 10) + parseInt(width) >  760  )
	{
      		 balloonObj.style.pixelLeft = 760 - width;
	}
	else
	{
       balloonObj.style.pixelLeft = (document.body.scrollLeft + window.event.clientX) + 10;
	}	
       balloonObj.style.pixelTop = (document.body.scrollTop + window.event.clientY) - 65;  //+10;

}

//-- function to hide balloon
function hideBalloonHelp() {

	window.clearTimeout(helpTimer);
	balloonObj = document.all['balloon']
	balloonObj.style.visibility="hidden";


}



/* ================================================================
    Mis. Functions
  ================================================================ */

//-- Function to clear a Non-postable form
function resetForm(targetform){
	for (var i=0; i < targetform.length ; i++){
		targetform.elements[i].value = "";
	}
	// Focus on fist visible element
	for (var i=0; i < targetform.length ; i++){
		if ( targetform.elements[i].type != 'hidden' ) {
			targetform.elements[i].focus();
			break;
		}
	}
}

//--Check/Uncheck all fields in field array
function checkAll(field) {
	if (field == null){return;};
	if (field.tabIndex == 0) {
		field.checked=document.all.allbox.checked;
	}
	else {
		for (i = 0; i < field.length; i++){
			var curField = field[i];
			curField.checked = document.all.allbox.checked;
		}
	}
}

//--- Get checked value from radio button.
function getRadioButtonValue (radio)
{   for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { break }
    }
    return radio[i].value
}


function getAllCheckedFieldAttributeString(field, attributeName) 
{

    // Case Only One row
	if ( isFinite(field.length) == false)
	{
		
		if (  field.checked == true  )
		{
		return field.getAttribute(attributeName)
		}
	}

    // Case Multiple Row ( Array )
	var returnStr = ""
	for (i = 0; i < field.length; i++){
	var e = field[i];
	if (field[i].checked == true ) {
		returnStr = returnStr + e.getAttribute(attributeName) +"," ; 
		}
	}
	returnStr = returnStr.substring(0,returnStr.length - 1);

	return returnStr;
}

//global variables
var curRow = null;       // Current Row in HTML Table
var CurrentElm;          // Current Row Element in XML DOM

function genericSelectRow()	{

        // Reset Erlier TR Higlight in Table        
        if(curRow!=null) {
		curRow.style.background="#E5E5E5"; 	
	}	

        // Get Current row TR in Table
	curRow = window.event.srcElement;	
        while(curRow.tagName!="TR") curRow = curRow.parentElement;	

        // HighLight Current TR in table
	curRow.style.background="#BFC6D7";	
}

function sendEmail(myAddress, mySubject, myBcc, myCc, myBody) 
{
    var myAddress = myAddress;
	var mySubject = mySubject;
	var myBody    = myBody;   
	var myBcc     = myBcc;
	var myCc      = myCc;

	var myURL =  'mailto:'+ myAddress +'?subject='+ mySubject + '&body=' + myBody 

	if ( myCc != "" ) {	myURL = myURL + '&cc=' + myCc	}
	if ( myCc != "" ) {	myURL = myURL + '&bcc=' + myBcc }
     this.document.location = myURL
}

function SetIndexAccToVal(mylstobj,mylstobjlen,arrElemVal)
{
	var strtmp=new String();
	for(var i=0;i<mylstobjlen;i++)
	{
		 strtmp = mylstobj[i].value;
		if(arrElemVal == strtmp)
		{
			mylstobj.selectedIndex = i;
			break;
		}
	}
}

  
