
//Javascript common functions.
function RequeryResources()
{
	document.getElementById('btnRefresh').disabled=false;
	document.getElementById('btnSubmit').disabled=true;
}

function ShowDiv()
{
	var DevLayer = document.getElementById('devVars');
	document.all['devVars'].style.visibility = "visible";
}

function HideDiv()
{
	var DevLayer = document.getElementById('devVars');
	document.all['devVars'].style.visibility = "hidden";
}

function popUp(URL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=300');");
}

function MM_openDialog(strWebPageName, width, height, parentpage)
{
	var winArgs = new Array("", parentpage); //str1, str2, bool1);
	var winSettings = 'center:yes;resizable:no;help:yes;'
					+ 'status:no;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px';
				
	// return the dialog control values after passing them as a parameter
	winArgs = window.showModelessDialog(strWebPageName, winArgs, winSettings);
}

function MM_openDialogQS(strWebPageName, width, height, strID, parentpage)
{
	var queryString = getQueryStringValue(strID);
	var winArgs = new Array(queryString, parentpage);
	var winSettings = 'center:yes;resizable:no;help:yes;'
					+ 'status:no;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px';
					
	winArgs = window.showModelessDialog(strWebPageName + '?' + strID + '=' + queryString, winArgs, winSettings);
}

function MM_openModalDialog(strWebPageName, width, height, parentpage)
{
	var winArgs = new Array("", parentpage);
	var winSettings = 'center:yes;resizable:no;help:yes;'
					+ 'status:no;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px';
					
	winArgs = window.showModalDialog(strWebPageName, winArgs, winSettings);
}

function MM_openModalDialogQS(strWebPageName, width, height, strID, parentpage)
{
	var queryString = getQueryStringValue(strID);
	var winArgs = new Array(queryString, parentpage);
	var winSettings = 'center:yes;resizable:no;help:yes;'
					+ 'status:no;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px';
					
	winArgs = window.showModalDialog(strWebPageName + '?' + strID + '=' + queryString, winArgs, winSettings);
}

function MM_testQS(ID)
{
	var queryString = getQueryStringValue(ID);
	alert(queryString);
}

function getQueryStringValue(id)
{
	var qs = new qsObject();
	var idObj = qs.item(id);
	return idObj.value;
}

//this is to store the key value pairs of the querystring    
function qsObject(){
    this.objects = new Array();
    this.add = _add;
    this.remove =_remove;
    this.item = _item;
    this.populateCollection =_populateCollection;
    this.setRawString = _setRawString;
    this.rawString ="";
    
    this.setRawString();
    this.populateCollection();
    
    // to add items to the array
    function _add(obj){
        this.objects[this.objects.length] = obj;
    }
    //to remove items from the array
    function _remove(index){
        this.objects.splice(index, 1);
    }
    //gets a reference to an item object
    function _item(searchKey){
        searchKey = new String(searchKey);
        searchKey = searchKey.toLowerCase();
        for(i=0;i<this.objects.length;i++){
            //the current key in the coll
            var key = this.objects[i].key;
            key = new String(key);
            key = key.toLowerCase();
            
            if(key == searchKey){
                return this.objects[i];
            }
        }
    }
    
    function _setRawString(){
        //Create regular expression object to retrieve the qs part
        // Used regex 'cause the search property on the location object includes the bookmark stuff
        var qsReg = new RegExp("[?][^#]*","i");  
        hRef = unescape( window.location.href);
        var qsMatch = hRef.match(qsReg);  
        //removes the question mark from the url 
        qsMatch = new String(qsMatch);
        qsMatch = qsMatch.substr(1, qsMatch.length -1);        
        this.rawString = qsMatch;        
    }
    
    //takes a string and populates the array with the key/value pairs
    function _populateCollection(rawString){
        this.rawString = new String(this.rawString);
        var rootArr = this.rawString.split("&");
        for(i=0;i<rootArr.length;i++){
            var tempArr =  rootArr[i].split("=");
            if(tempArr.length ==2){
                tempArr[0] = unescape(tempArr[0]);
                tempArr[1] = unescape(tempArr[1]);
                
                this.add(new qsValue(tempArr[0], tempArr[1]));
            }
        }
    }
    
    function qsValue(key, value){
        this.key = key;
        this.value=value;    
    }     
}    

function MM_openBrWindow(theURL,winName,features) //v2.0
{ 
	window.open(theURL,winName,features);
}

// Functions Added by Shabbir
var ids='';
var firstTime = false;

function buildQueryString(winName, qry, rowIDs, popupWinAttr){
	//alert("winName = "+winName+" qry = "+qry+" rowIDs ="+rowIDs+ " popupWinAttr = "+popupWinAttr);
	if(firstTime == false){
		qry = qry + "&rowIDs=" + rowIDs;
	}else{
		qry = qry + "&rowIDs=" + ids;
	}
	winName = "popup"+winName;
	if(popupWinAttr.length > 0) {
		//alert("if popupWinAttr.length  = "+popupWinAttr);
		popupWinAttr = adjustPopupWindowAttributes(popupWinAttr);
	}else{
		//alert("else popupWinAttr = "+popupWinAttr);
		popupWinAttr = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=350';
		popupWinAttr = adjustPopupWindowAttributes(popupWinAttr);
	}
	window.open(qry,winName,popupWinAttr);
}


function buildQueryString_New(winName, qry, rowIDs, popupWinAttr, type){
	//alert("winName = "+winName+" qry = "+qry+" rowIDs ="+rowIDs+ " popupWinAttr = "+popupWinAttr);
	var winURL
	if(type == 1) {
		if(firstTime == false){
			winURL = qry + "&rowIDs=" + rowIDs;
		}else{
			winURL = qry + "&rowIDs=" + ids;
		}
	}else{
		winURL = qry;
	}
	winName = "popup"+winName;
	if(popupWinAttr.length > 0) {
		//alert("if popupWinAttr.length  = "+popupWinAttr);
		popupWinAttr = adjustPopupWindowAttributes(popupWinAttr);
	}else{
		//alert("else popupWinAttr = "+popupWinAttr);
		popupWinAttr = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=500,height=350';
		popupWinAttr = adjustPopupWindowAttributes(popupWinAttr);
	}
	window.open(winURL, winName, popupWinAttr);
}


function adjustPopupWindowAttributes(winAttributes) {
	var retWinAttributes;
	var w1   = winAttributes.indexOf("width");
	var w11 = winAttributes.substring(w1,winAttributes.length).indexOf(",");
	var w     = winAttributes.substring(w1,winAttributes.length);
	if(w11 < 0)
		w  = winAttributes.substring(w1, winAttributes.length);
	else
		w  = w.substring(0, w11);
	w           = w.replace("width=","");

	var h1   = winAttributes.indexOf("height");
	var h11 = winAttributes.substring(h1,winAttributes.length).indexOf(",");
	var h     = winAttributes.substring(h1,winAttributes.length)
	if(h11 < 0)
		h     = winAttributes.substring(h1, winAttributes.length);
	else
		h     = winAttributes.substring(0, h11);
	h           = h.replace("height=","");

	var width = 480, height = 340;
	if (document.all || document.layers) {
		width  = screen.availWidth;
		height = screen.availHeight;
	}
	//var popW = 300, popH = 200;
	var popW = w, popH = h;
	var leftPos = (width - popW)/2, topPos = (height - popH)/2;

	retWinAttributes = winAttributes + ",top="+topPos+",left="+leftPos;
	return retWinAttributes;
}

function CollapseAll(elements){
	ids='';
	for(element=1; element<=elements; element++){
		var rowID = document.getElementById('rowID_'+element); 
		var img = document.getElementById(element);
		if ((rowID != null) && (img != null)){
			rowID.style.visibility='hidden'; 
			rowID.style.display='none'; 
			img.src = "../../images/plus.gif";
		}
	}
	return false;
}

function ExpandAll(elements){ // elements is number of childs + 1
	CollapseAll(elements);
	for(element=1; element<=elements; element++){
		Show_Hide_TableRows(element, ids);
	}
	return false;
}
function Show_Hide_TableRows(element, newIDs){
	var rowID  = document.getElementById('rowID_'+element); 
	var img = document.getElementById(element);
	if(firstTime == false){
		if(newIDs==0){
			ids = '';
		}else{
			ids = newIDs;
		}
		firstTime = true;
	}
	if(ids.indexOf(element) < 0){
		ids = ids + ',' + element;
	}else{
		ids = ids.replace(element,"");
	}
	if(ids.indexOf(",") == 0)
		ids = ids.substring(1,ids.length);				
	
	if ((rowID != null) && (img != null)) {
		if(rowID.style.visibility == 'visible') 
		{ 
			rowID.style.visibility='hidden'; 
			rowID.style.display='none'; 
			img.src = "../../images/plus.gif";
		} 
		else 
		{ 
			rowID.style.visibility='visible'; 
			rowID.style.display=''; 
			img.src = "../../images/minus.gif";
		}
	}
	return false;
}
function Mark_All_CheckBoxes(element, counter){
	var pCHK = document.getElementById('p'+element);
	var cCHK;
	if(pCHK.checked==true){
		pCHK.checked = true;
	}else{
		pCHK.checked = false;
	}
	for(i=1;i <= counter; i++) {
		cCHK = document.getElementById('c'+element+'_'+i);
		if(cCHK != null && cCHK.disabled == false)
			cCHK.checked = pCHK.checked;
	}
	return pCHK;
}

// Used in TimeSheetExpense/timesheetapprovallist.aspx, expenseapprovallist.aspx, 
// timesheetunapprove.aspx, unapproveexpenses.aspx
function Mark_CheckBox(childelement, parentelement, counter)
{
	//alert("childelement = "+childelement+ " parentelement = "+parentelement+ " counter = "+counter);
	var cCHK = document.getElementById('c'+parentelement+'_'+childelement);
	var pCHK = document.getElementById('p'+parentelement);
	if(cCHK.checked==true)
	{
		cCHK.checked = true;
		//alert("counter = "+counter); 
		for(i=1;i <= counter; i++) 
		{
			cCHK = document.getElementById('c'+parentelement+'_'+i);
			if(cCHK != null)
			{
				if(cCHK.checked)
				{
					checkAll = true;
				}
				else
				{
					checkAll = false;
					break;
				}
			}
		}
		if( pCHK != null ) 
		{
			if(checkAll) 
				pCHK.checked = true;
			else
				pCHK.checked = false;
		}
	}
	else
	{
		cCHK.checked = false;
		if( pCHK != null ) 
		{
			if(checkAll) 
				pCHK.checked = false;
			else
				pCHK.checked = false;
		}
	}
	return cCHK;
}			


// function for Customer Satisfaction Survey
	function checkLimits(bitCheck, expectedValue, ctlID, checkType){
		var expValue = expectedValue;
		if(bitCheck > 0){
		
			if(checkType == '1') {
			
				var rowID  = document.getElementById('rowID_Comments_'+ctlID);
				var ddl = document.getElementById('ddl_'+ctlID);
				if(ddl.value < expValue){
					rowID.style.visibility='visible'; 
					rowID.style.display=''; 
				}else{
					rowID.style.visibility='hidden'; 
					rowID.style.display='none'; 
				}
				
			}else if((checkType == '2') || (checkType == '3')) {
			
				var rowID  = document.getElementById('rowID_Comments_'+ctlID);
				var rdList = document.getElementsByName('rdList_'+ctlID);

				if((rdList[1].checked==true) && (expValue == 'True') ){
					rowID.style.visibility='visible'; 
					rowID.style.display=''; 
				}else if((rdList[2].checked==true) && (expValue == 'False')){
					rowID.style.visibility='visible'; 
					rowID.style.display=''; 
				}else{
					rowID.style.visibility='hidden'; 
					rowID.style.display='none'; 
				}
			}
		}
	}
function match_DropDownDays(val, ddl_1, ddl_2){
	if(val == 1) {
		var ddl1 = document.getElementById(ddl_1);
		var ddl2 = document.getElementById(ddl_2);
		ddl2.selectedIndex = ddl1.selectedIndex;
	}else{
		ddl_2.selectedIndex = ddl_1.selectedIndex;
	}
}

/*function getCustomerID(ddl,txt)
{
	var ddl1 = document.getElementById(ddl);
	document.getElementById("txt").value = ddl1.selectedIndex;
}	*/
/*
function GetProvinves(str_us, str_canada, ddl1, ddl2)
{
	string strCountry;
	alert(strCountry);
	
	if (ddl1.selectedIndex == 1)
		{strCountry = str_canada;}
	else if (ddl1.selectedIndex == 2)
		{strCountry = str_us;}
	else
		{strCountry = str_us + str_canada;}
		
		alert(strCountry);
	var arrCountry = strCountry.split(',');
	for (i=0; i < arrCountry.Length - 1; i++)
	{
		ddl2[i].value = arrCountry[i];
		ddl2[i].text = arrCountry[i];
	}
		
}
*/
/*
function match_DropDownDays(ddl_1, ddl_2){
}
*/


//////////////////////////////Show/Hide Form Elements///////////////////////
function showHideTableRows(idString, Checked, ShowWhenChecked)
	{	
		var myArray = idString.split(',');
		var myArrBools = ShowWhenChecked.split(',');
		var arrLength = myArray.length - 1;
		for(i=0; i<= arrLength; i++)
		{
			if (myArrBools[i] == "true")
			{
				if(Checked)
				{
					document.getElementById(myArray[i]).style.display='';
				}
				else
				{
					document.getElementById(myArray[i]).style.display='none';
				}
			}
			else
			{
				if(Checked)
				{
					document.getElementById(myArray[i]).style.display='none';
				}
				else
				{
					document.getElementById(myArray[i]).style.display='';
				}
			}			
		}
	}
////////////////////////END Show/Hide Form Elements////////////////////////


////////////////////////////FILTERING////////////////////////////////////////////

function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}

/////////////////////////////////END FILTERING//////////////////////////////////

function GetProv(str_us, str_canada, str_us_values, str_canada_values, ddlCountry, ddlProv)
			{
				var strProv;
				var strProvValues;
				var ddlCntry = document.getElementById(ddlCountry);
				var ddlPrv = document.getElementById(ddlProv);
				
				//alert(ddlCntry[ddlCntry.selectedIndex].text); // Canada, US, ----
				
				if (ddlCntry.selectedIndex == 1)
				{
					strProv = str_canada;
					strProvValues = str_canada_values
				}
				else if (ddlCntry.selectedIndex == 2)
				{
					strProv = str_us;
					strProvValues = str_us_values;
				}
				else 
				{
					strProv = "---";
					strProvValues = "0";
				}
									
				var arrProv = strProv.split(',');
				var arrProvValues = strProvValues.split(',');
				
				//// works ddlCntry.options[ddlCntry.options.length] = new Option('three',"'" + j + "'")
				if (arrProv.length > ddlPrv.length) //number of provinces for this country is more than lenght of dropdown list
				{
					var start_index = ddlPrv.length
					var end_index = arrProv.length
					for (i=start_index; i<end_index; i++)
						ddlPrv.options[ddlPrv.options.length] = new Option('',"'" + i+ddlPrv.length + "'")
				}
				var ProvCount = 0;
				for (i=0; i < arrProv.length; i++) ///zero indexing
				{	
					//ddlPrv.options[ddlPrv.options.length] = new Option(arrProv[i],"'" + i + "'")
					///ddlPrv.options[i] = new Option(arrProv[i],"'" + i + "'")
					ddlPrv.options[i].value = arrProvValues[i];
					ddlPrv.options[i].text = arrProv[i];
					ProvCount++;
					
				}
												
				var j = ProvCount;
				var ddlLength = ddlPrv.length;
				
				for(i = ProvCount; i < ddlLength; i++)
				{
					ddlPrv.remove(j);	
				}
				//if (ddlCntry.selectedIndex == oldCountry)
					//ddlPrv.selectedIndex = oldProv;
				//else
				ddlPrv.selectedIndex = 0;
				//alert(ddlPrv.length);
			}
			
///////////////////////////////////////////////////////////////////////////

			
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   }
window.attachEvent("onload", correctPNG);
			

// function for customeradd.aspx ( Customer Expenses dynamic table )
// If Use Cost Uplift checkbox = unchecked, Cost Uplift Factor textbox.value = "0"
function matchCheckBox_TextBox( chkBox, txtBox )
{
	var chk = document.getElementById( chkBox );
	var txt = document.getElementById( txtBox );

	if( !chk.checked ) {
		txt.value = 0;
		txt.Text = "0";
		txt.disabled = true;
	}
	else 
		txt.disabled = false;

	if( isNaN( parseFloat( txt.value )) ) {
		alert("That was an invalid value.");
		//MM_openBrWindow('inputerrormessage.aspx',null,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=100,height=80'); 
		txt.value = 0;
		txt.focus();
	}
}


// Function displays a confirmation alert box 
// that provides two choices for the user, OK and Cancel.
// Depending on user choice, hiddenField value will be set
// to a string composed of elementID and fileName ( OK ), or -1 ( Cancel ).
// Function is used in AccountingFunctions/exportfilelist.aspx, quickbooksinvoiceexport.aspx,
// ceridianexpenseexportgenerate.aspx, ceridiantimeexportgenerate.aspx.
function confirmEntry( messageText, hidValue, hiddenFieldID )
{
	var hidden = document.getElementById( hiddenFieldID );
 
 	if( confirm( messageText ) )
		hidden.value = hidValue;		
 	else
 		hidden.value = -1;
 	//alert( hidden.value );
}


// Function sets a  textbox value accordingly to ddlExpenseType.SelectedIndex.
// Function is used in TimeSheetExpense/expensedetailadd.aspx. 
function GetAmount( strExpTypeID, strPdeCost, strPdeOverrideCost, ddlExpenseType, txtAmount )
{
	var ddlExpType = document.getElementById( ddlExpenseType );
	var txtAmnt = document.getElementById( txtAmount );
	
	var arrExpTypeID = strExpTypeID.split(',');
	var arrPdeCost = strPdeCost.split(',');
	var arrPdeOverrideCost = strPdeOverrideCost.split(',');

	for( var i=0; i < arrExpTypeID.length; i++ )
	{
		if( ddlExpType.options[i].selected == true )
		{						
			txtAmnt.value = arrPdeCost[i];
			//alert( txtAmnt.value );
		
		if( arrPdeOverrideCost[i] == 'True' ) // Resource can override cost
			txtAmnt.disabled = false;			
			else 
				if( arrPdeOverrideCost[i] == 'False' )
					txtAmnt.disabled = true;
		}
	}
}	
	
				
// Function disables textboxes when checkbox is checked.
// Used in AccountingFunctions/invoicingdateselector.aspx.
function DisableTextBoxes( chk, txt1, txt2 )
{
	var chkBox = document.getElementById( chk );
	var txtBox1 = document.getElementById( txt1 );
	var txtBox2 = document.getElementById( txt2 );
	
	if( chkBox.checked == true )
	{
		txtBox1.value = "";
		txtBox1.disabled = true;
		txtBox2.value = "";
		txtBox2.disabled = true;
	}
	else
	{
		txtBox1.disabled = false;
		txtBox2.disabled = false;
	}	
}


// Function disables passed controls 
// if any dropdown list value (but not "---") is selected.
// Used in AccountingFunctions/profitreportparam.aspx, profitrepparameters.aspx,
// and AccountingFunctions/approvedtimereport.aspx.
function DisableControls( d1, d2, d3, t1, t2, t3, t4 )
{
	var ddl1= document.getElementById( d1 );
	var ddl2 = document.getElementById( d2 );
	var ddl3 = document.getElementById( d3 );
	var txt1 = document.getElementById( t1 );
	var txt2 = document.getElementById( t2 );
	var txt3 = document.getElementById( t3 );
	var txt4 = document.getElementById( t4 );

	//alert( ddl1.options[0].value );
	//alert( txt1.value );
	
	if( ddl1.options[0].selected == true )
	{
		ddl2.disabled = false;
		if( ddl3 != null )
			ddl3.disabled = false;
		if( txt1 != null )
			txt1.disabled = false;
		if( txt2 != null )
			txt2.disabled = false;
		if( txt3 != null )			
			txt3.disabled = false;
		if( txt4 != null )			
			txt4.disabled = false;	
	}
	else
	{
		ddl2.options[0].selected = true;
		ddl2.disabled = true;
		if( ddl3 != null )
		{
			ddl3.options[0].selected = true;
			ddl3.disabled = true;
		}
		if( txt1 != null )
		{
			txt1.value = "";
			txt1.disabled = true;
		}
		if( txt2 != null )
		{
			txt2.value = "";
			txt2.disabled = true;
			}
		if( txt3 != null )
		{
			txt3.value = "";
			txt3.disabled = true;
		}
		if( txt4 != null )
		{
			txt4.value = "";
			txt4.disabled = true;	
		}
	}
}


// Function disables dropdownlist if one of the textboxes values is not empty.
// Is used in AccountingFunctions/profitreportparam.aspx, profitrepparameters.aspx.
// Works only with regular textboxes,
// does not work with DateTime textboxes because of calendar.
// txtStart.Attributes["onChange"] = "javascript:DisableDDL('" + txtStart.UniqueID + "','" + 
//		txtEnd.UniqueID + "','" + ddlInvoiceNum.UniqueID + "')";
function DisableDDL( t1, t2, d1 )
{
	var txt1 = document.getElementById( t1 );
	var txt2 = document.getElementById( t2 );
	var ddl1= document.getElementById( d1 );
	
	//alert( txt1.value );
	
	if( txt1.value != "" || txt2.value != "" )
	{
		ddl1.options[0].selected = true;
		ddl1.disabled = true;
	}
	else
		ddl1.disabled = false;
}


// Function shows a table row  if dropdown.SelectedValue = number.
// Function is used in AccountingFunctions/invoicingadvanced.aspx, SystemAdmin/customerprofileedit.aspx.
function ShowHideTableRow( rowIndex, dropdown, number )
{
	var ddl = document.getElementById( dropdown );
	//alert( ddl.options.length )	
	for( var i=0; i < ddl.options.length; i++ )
	{
		if( ddl.options[i].selected == true )
		{	
			//alert( ddl.options[i].value )
			if( ddl.options[i].value == number ) 
				document.getElementById(rowIndex).style.display = '';
			else
				document.getElementById(rowIndex).style.display = 'none';
		}
	}
} 


// Function hides a table row if dropdown.SelectedValue = number.
function HideShowTableRow( rowIndex, dropdown, number )
{
	var ddl = document.getElementById( dropdown );
	//alert( ddl.options.length )	
	for( var i=0; i < ddl.options.length; i++ )
	{
		if( ddl.options[i].selected == true )
		{	
			//alert( ddl.options[i].value )
			if( ddl.options[i].value == number ) 
				document.getElementById(rowIndex).style.display = 'none';
			else
				document.getElementById(rowIndex).style.display = '';
		}
	}
}


// Function sets a dropdown list value to 0 
// if another dropdown list value (but not "---") is selected.
// Used in ProjectMgmt/resschedcriteria.aspx
function SetDdlValueTo0( d1, d2 )
{
	var ddl1= document.getElementById( d1 );
	var ddl2 = document.getElementById( d2 );

	//alert( ddl1.options[0].value );
	
	if( ddl1.options[0].selected != true )
	{
		ddl2.options[0].selected = true;
	}
} 


