//used with select search boxes
function SubmitToParent(formField_Name, ID_Value, Display_Value) 
{
	//alert(formField_Name + '-- ' + ID_Value + ' - ' + Display_Value);
	eval("window.opener.document.forms[0]." + formField_Name).value = ID_Value;
	eval("window.opener.document.forms[0]." + formField_Name + "_Display").value = Display_Value;
	window.opener.document.anchors(formField_Name + "_GoTo").disabled = true;
	window.close();
	return false;
}

//also used with select search boxes....fires onchange of text box, which will fire autopostback
function SubmitToParent_PostBack(formField_Name, ID_Value, Display_Value) 
{
	//alert(formField_Name + '-- ' + ID_Value + ' - ' + Display_Value);
	eval("window.opener.document.forms[0]." + formField_Name).value = ID_Value;
	eval("window.opener.document.forms[0]." + formField_Name + "_Display").value = Display_Value;
	window.opener.document.anchors(formField_Name + "_GoTo").disabled = true;
	eval("window.opener.document.forms[0]." + formField_Name + "_Display").fireEvent("onchange");
	window.close();
	return false;
}

//simplified....used with calendar control
function SubmitToParent2(formField_Name, value)
{
	//alert(formField_Name);
	eval("window.opener.document.forms[0]." + formField_Name).value = value;

	window.close();
	return false;
}

function popupCalendar(formField)
{
	//alert(window.event.clientX);
	Top = window.screenTop + window.event.clientY - 220;
	Left = window.screenLeft + window.event.clientX + 10;	
	if (formField.value != "")
		url = "/Common/Calendar.aspx?returnField=" + formField.name + "&InitDate=" + formField.value;
	else
		url = "/Common/Calendar.aspx?returnField=" + formField.name;
	attributestring = "width=235,height=260,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	myWindow = window.open(url,'PopUpCalendar',attributestring);
}

function OnChangeMonth(dropdown)
{
	var hf = document.getElementById("hdnMonth");
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value;
	hf.value = SelValue;
    
	return true;
}
function OnChangeYear(dropdown)
{
	var hf = document.getElementById("hdnYear");
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value
	hf.value = SelValue;
    
	return true;
}
function PopupReport(reportID, extraArgs)
{
	Top = window.screenTop + 5;
	Left = window.screenLeft + 5;
	url = "/Reporting/DisplayReport.aspx?ReportID=" + reportID + extraArgs;
		
	attributestring = "width=800,height=550,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	myWindow = window.open(url,'PopUpReport',attributestring);
	return false;
}

  
/***********************************************
 * popupWindow();
 ***********************************************/
function popupWindow(url,windowType, windowName) 
{
	Top = window.screenTop + 5;
	Left = window.screenLeft + 5;
	if (windowType == 'MainEdit')
	{
		attributestring = "width=775,height=630,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	else if (windowType == 'Full')
	{
		attributestring = "width=880,height=650,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=auto,resizable=yes,status=yes,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	else if (windowType == 'SmallEdit')
	{
		attributestring = "width=520,height=450,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=auto,resizable=yes,status=yes,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	else if (windowType == 'SelectSearch')
	{
		attributestring = "width=450,height=312,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	else if (windowType == 'Calendar')
	{
		attributestring = "width=233,height=197,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	else if (windowType == 'ViewSpace')
	{
		attributestring = "width=780,height=500,top=" + Top + ",left=" + Left + ",toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,location=no,directories=no,copyhistory=no,alwaysRaised=yes";
	}
	
	myWindow = window.open(url,windowName,attributestring);
}


function ClearFormField(formfield)
{
	formName = formfield.form.name;
	formFieldName = formfield.name;
	formfield.value = "0";
	eval(formName + "." + formFieldName + "_Display.value = ''");
	return true;
}

function CloseAndRefresh(args)
{	
	window.opener.location.reload();
	window.close();
}

function RemoveQSParam(strQ, param)
{
	//string in front of param
	str1 = strQ.substring(0, strQ.toUpperCase().indexOf(param) - 1);
	//alert(str1);
	
	//param to end
	str2 = strQ.substring(strQ.toUpperCase().indexOf(param), strQ.length);
	//alert(str2);
	
	alert("str2: " + str2);
	str2 = str2.substring(str2.indexOf('&'), str2.length);
	alert("str2: " + str2);
	
	str3 = str1 + str2;
	//alert(str3);
	if (str3.charAt(str3.indexOf('.aspx') + 5) == "&")
		str3 = str3.substring(0, str3.indexOf('.aspx') + 5) + '?' + str3.substring((str3.indexOf('.aspx') + 6), str3.length);
	alert(str3);

}


/**********************************************************************************************
* General function used to set default button on page....that is, fires click event of 
*	button in the EventTarget
*
* To implement - 
* In code behind set default button like so, (if not set, clicking 'return' btn does nothing):
*		this.Page.RegisterHiddenField("__EVENTTARGET", "btnSave");
*
* In HTML add to Body Tag like so:
*		<BODY ONKEYDOWN="return Trap(event);">
*
***********************************************************************************************/
function Trap(event)
{
	if (event.keyCode == 13)
	{
		event.returnValue = false;
		event.cancel = true;
		if (document.forms[0].__EVENTTARGET)
		{
			//alert('ok');
			str = document.forms[0].__EVENTTARGET.value;
			btn = eval("document.forms[0]." + str);
			btn.click();
		}else{
			//do nothing
		}
	}
}


