function OpenStandardWindow(strURL,strName,iWidth,iHeight)
{
	var strFeatures = 'top=' + ((screen.height-iHeight)/3) + ',left=' + (screen.width-iWidth)/2 +  ' ,width=' + iWidth + ',height=' + iHeight + ',toolbar=no, menubar=no, scrollbars=no, resizable=yes,location=no, directories=no, status=no'
	var w = window.open(strURL,strName,strFeatures);
	if(w!=null)
		w.focus();
}

function OpenStandardScrollWindow(strURL,strName,iWidth,iHeight)
{
	var strFeatures = 'top=' + ((screen.height-iHeight)/3) + ',left=' + (screen.width-iWidth)/2 +  ' ,width=' + iWidth + ',height=' + iHeight + ',toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no'
	var w = window.open(strURL,strName,strFeatures);
	if(w!=null)
		w.focus();
}
function OpenStandardScrollFullWindow(strURL,strName)
{
	var strFeatures = 'top=' + 0+ ',left=' + 0 +  ' ,width=' + screen.availWidth + ',height=' + screen.availHeight + ',toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=no'
	var w = window.open(strURL,strName,strFeatures);
	if(w!=null)
		w.focus();
}

function PageBack()
{
	window.history.back();
}

function CloseWindow()
{
	window.close();
}

function PrintWindow()
{
	window.print();
}
function ImageOver(objImage)
{
	var idxOff;
	var strOnImagePath;
	idxOff = objImage.src.lastIndexOf("Off.gif");
	if (idxOff!=-1)
	{
		var strOnImagePath = objImage.src.substr(0,idxOff) + "On.gif";
		objImage.src = strOnImagePath;
	}
}

function ImageOut(objImage)
{
	var idxOff;
	idxOn = objImage.src.lastIndexOf("On.gif");
	if (idxOn!=-1)
	{
		var strOffImagePath = objImage.src.substr(0,idxOn) + "Off.gif";
		objImage.src = strOffImagePath;
	}
}

function GetObjectByID(strElementID)
{
	if((document.getElementById)&& (document.getElementById(strElementID)!=null))
	{
		return document.getElementById(strElementID);
	}
	return null;
}

function GetSelRadioValue(objRadio)
{
	var i;
	for(i=0;i<objRadio.length;i++)
	{
		if(objRadio[i].checked) 
			return objRadio[i].value;
	}
	return "";
}

function SetSelRadioItemByValue(objRadio,strValue)
{
	var i;
	for(i=0;i<objRadio.length;i++)
	{
		if(objRadio[i].value==strValue) 
			objRadio[i].checked = true;
		else
			objRadio[i].checked = false;
	}
}

function GetSelComboValue(strComboID)
{
	if((document.getElementById)&& (document.getElementById(strComboID)!=null))
	{
		var objCombo = document.getElementById(strComboID);
		if(objCombo.selectedIndex!=-1)
		{
			return objCombo.options[objCombo.selectedIndex].value;
		}
	}	
	return "";

}

function SetSelComboValue(strComboID,strValue)
{
	if((document.getElementById)&& (document.getElementById(strComboID)!=null))
	{
		var objCombo = document.getElementById(strComboID);
		for(var i=0;i<objCombo.options.length;i++)
		{
			if(objCombo.options[i].value==strValue)
				objCombo.options[i].selected=true;
		}
	}
}

function GetCheckedListItem(strMainControlID)
{
	if(document.getElementById)
	{
		var strCurControlID;
		var objCurControl;
		var i=0;
		while(i!=-1)
		{
			strCurControlID = strMainControlID + '_' + i;
			objCurControl = document.getElementById(strCurControlID)
			if(objCurControl!=null)
			{
				if(objCurControl.checked)
					return objCurControl.value;
				i++;
			}
			else
			{//Exit the last while loop because the control was not valid
				i=-1;
			}
		}
	}
	return '';
}

function ChangeElementStyle(strElementID,strStyleTags)
{
	//Accepts style parameters like "color:red;border:25px solid red;
	if((document.getElementById)&& (document.getElementById(strElementID)!=null))
	{
		var objElement = document.getElementById(strElementID);
		var arrStyleTags = strStyleTags.split(";");
		var arrStyleParts;
		var i,arrSize=arrStyleTags.length;
		for(i=0;i<arrSize;i++)
		{
			arrStyleParts  = arrStyleTags[i].split(":");
			if(arrStyleParts.length==2)
			{//there exist 2 elements. the tag name [0]and the tag value [1];
				eval('objElement.style.' + arrStyleParts[0] + '="'  +  arrStyleParts[1] + '"');
			}
		}
	}
}
function IsElementVisible(strElementID)
{
	if((document.getElementById)&& (document.getElementById(strElementID)!=null))
	{
		var objElement = document.getElementById(strElementID);
		if(objElement.style.display!='none')
			return true;
		else
			return false;
	}	
}

function ChangeElementVisible(strElementID, bShow)
{
	if((document.getElementById)&& (document.getElementById(strElementID)!=null))
	{
		var objElement = document.getElementById(strElementID);
		if(bShow)
			objElement.style.display='block';
		else
			objElement.style.display='none';
	}
}

function ToggleElementVisible(strElementID)
{
	ChangeElementVisible(strElementID,!IsElementVisible(strElementID));
}

//The valArr is a 2 dimensional array of [text, value] where it can hold more than one "UnSelected Item"
function LoadComboElementsByParentCombo(strParentCombo,strCombo,strHidden, valArr)
{
	var objParentCombo = document.getElementById(strParentCombo);
	var objCombo = document.getElementById(strCombo);
	var objHidden = document.getElementById(strHidden);
	var iSelParentElementID=-1;
	if(objParentCombo.selectedIndex>-1)
		iSelParentElementID = parseInt(objParentCombo[objParentCombo.selectedIndex].value,10);
	
	while(objCombo.options.length>0)
	{//delete all the elements in the combo
		objCombo.options[0] = null;	
	}
	
	//Add The Not Selected Item(s) at the beginning of the child combo
	if(typeof valArr != "undefined")
	{		
		for(var ndx=0; ndx < valArr.length; ndx++)
			objCombo.options[ndx] = new Option(valArr[ndx][0],valArr[ndx][1],true,true); 			
	}
	
	var arrElements,arrElementSubs;
	arrElements = objHidden.value.split("#;;#");
	var iParentID,iID,strName;
	for(var i=0;i<arrElements.length;i++)
	{
		arrElementSubs = arrElements[i].split("#;#");
		if(arrElementSubs.length==3)
		{
			iParentID = parseInt(arrElementSubs[0],10);
			iID = parseInt(arrElementSubs[1],10);
			strName = arrElementSubs[2];
			if(iSelParentElementID==iParentID || iParentID==-1)
			{
				objCombo.options[objCombo.options.length] = new Option(strName,iID);
			}
		}
	}
}

function ShowElementByComboOtherContent(strElementID, strComboID)
{
	if(GetSelComboValue(strComboID) == '-2')
		ChangeElementVisible(strElementID, true);
	else
		ChangeElementVisible(strElementID, false);
}

function load()
{
	if(window.opener!=null)
	{
		if(window.opener.closed!=true)
		{
			window.opener.location.reload();
		}
	}
}

function togDisp(e)
{
		stopB(e);
		var elems=document.getElementsByName('more');
		for(var i=0;i<elems.length;i++)
		{
			var obj=elems[i];
			var dp="";
			if(obj.style.display=="")
			{
				dp="none";
			}
			obj.style.display=dp;
		}
		return false;
}

function stopB(e)
{
	if(!e)e=window.event;
	e.cancelBubble=true;
}
function ChangeImageURL(ImageID, newImageURL)
{
   var imageObj =  document.getElementById(ImageID);
   if(imageObj != null)
        imageObj.src = newImageURL;
}

function CollapseElement(elementID,Direction,imageID,imageURL)
{
    if(Direction == "Vertical")
        new Rico.Effect.Size(elementID,
        null, // don't change the width
        1, // change the height 
        300 , // 500ms (1/2 second) 
        10, // 10 steps 
        null);
    else
        new Rico.Effect.Size(elementID,
        1, //change the width
        null, // don't change the height 
        300, // 500ms (1/2 second) 
        10, // 10 steps 
        null);
    GetObjectByID(elementID).style.visibility = "hidden";
    ChangeImageURL(imageID,imageURL);
}

function ExpandElement(elementID, size, Direction,imageID,imageURL)
{    
    if(Direction == "Vertical")
        new Rico.Effect.Size(elementID,
        null, // don't change the width 
        size, // change the height 
        300, // 500 ms (1/2 second) 
        10, // 10 steps 
        null);
     else 
        {
            new Rico.Effect.Size(elementID,
            size, //  change the width
            null, // don't change the height
            300, // 500ms (1/2 second) 
            10, // 10 steps 
            null);
        }
    GetObjectByID(elementID).style.visibility = "visible";
    ChangeImageURL(imageID,imageURL);
}