function Trim(s) 
{
	// Remove leading spaces and carriage returns
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{ s = s.substring(1,s.length); }
     
	// Remove trailing spaces and carriage returns
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{ s = s.substring(0,s.length-1); }
     
   	return s;
}

function formCheck(formobj,fieldRequiredList,fieldDescriptionList)
{
	var fieldRequired = new Array()
	fieldRequired = fieldRequiredList.split(",");

	var fieldDescription = new Array()
	fieldDescription = fieldDescriptionList.split(",");

	var alertMsg = "الرجاء ، إكمال البيانات التالية: \n\n";

	var l_Msg = alertMsg.length;
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			if (obj.type == null){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				continue;
			}

			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "password":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function Set_RedBox(varBoxList)
{
var arrBoxList = new Array()
arrBoxList = varBoxList.split(",");
for (var i = 0; i < arrBoxList.length; i++)
	{
//	alert(arrBoxList[i])
//	document.getElementById(arrBoxList[i]).style.color='red';
	document.getElementById(arrBoxList[i]).style.background='#ff9999';
	}
}

function ConfirmLink(strMessage,strURL)
{
doyou = confirm(strMessage)
if (doyou == true)
	{
	window.location.href = strURL
	}
}

function objData(ID,ParentID,Label)
{
	this.ID = ID;
	this.ParentID = ParentID;
	this.Label  = Label;
}
			
function Get_ChildCombo(objParentCombo,objChildCombo,aArray,ChildID,intZero)
{
  if (intZero==0)
	  objChildCombo.length = 1 // view blank value
  else
	  objChildCombo.length = 0

  varFirstChildID = 0

  for(var i=0; i < aArray.length ;  i++)
  {
	if( aArray[i].ParentID == objParentCombo.options[objParentCombo.selectedIndex].value)
	{
		if (varFirstChildID == 0 ) varFirstChildID = aArray[i].ID

		if (intZero==0) varFirstChildID = 0

		objChildCombo.length = parseInt(objChildCombo.length) + 1
		objChildCombo.options[objChildCombo.length-1] = new Option(aArray[i].Label,aArray[i].ID);
		if (aArray[i].ID == varFirstChildID || aArray[i].ID == parseInt(ChildID))
		{
			objChildCombo.options[objChildCombo.length-1].selected=true;
		}

	}
  }
}


function PopUpSearchFeature(varAccident_ID,varA,strExpandList)
{
	intJordan_Governorate_ID	= parseInt(document.getElementById("Jordan_Governorate_ID").value)
	intJordan_Administration_ID	= parseInt(document.getElementById("Jordan_Administration_ID").value)
	intMunicipality_ID		= parseInt(document.getElementById("Municipality_ID").value)
	intDistrict_ID			= parseInt(document.getElementById("District_ID").value)
	intSubDistrict_ID		= parseInt(document.getElementById("SubDistrict_ID").value)

	if (varA==1)
	{
		intCity_StreetCenter_ID	= parseInt(document.getElementById("City_StreetCenter_ID").value)
		intJordan_MainRoad_ID	= 0
	}
	else
	{
		intCity_StreetCenter_ID	= 0
		intJordan_MainRoad_ID	= parseInt(document.getElementById("Jordan_MainRoad_ID").value)
	}
	w = window.open('search_feature.asp?d=0&Accident_ID=' + varAccident_ID +'&Jordan_Governorate_ID=' + intJordan_Governorate_ID + '&Jordan_Administration_ID=' + intJordan_Administration_ID + '&Municipality_ID=' + intMunicipality_ID + '&District_ID=' + intDistrict_ID + '&SubDistrict_ID=' + intSubDistrict_ID + '&A=' + varA + '&City_StreetCenter_ID=' + intCity_StreetCenter_ID + '&Jordan_MainRoad_ID=' + intJordan_MainRoad_ID + '&ExpandList=' +strExpandList ,'PopUpSearchFeature','width=500,height=300')
}

function PopUp_UploadForm(varAccident_ID,varSize)
{
	w = window.open('upload.asp?d=0&Accident_ID=' + varAccident_ID +'&size=' + varSize ,'PopUp_UploadForm','width=500,height=300')
}

function Enable_Box(strBox)
{
	document.getElementById(strBox).style.background="#AED0E6";
	document.getElementById(strBox).disabled=0;
}

function Enable_Box_Value(strBox,varValue)
{
	Enable_Box(strBox)
	document.getElementById(strBox).value=varValue;
}

function Disable_Box(strBox)
{
	document.getElementById(strBox).value="";
	document.getElementById(strBox).style.background="#BBBBBB";
	document.getElementById(strBox).disabled=1;
}

function PopUp_Window(varURL,varName)
{
w = window.open(varURL,varName,'width=600,height=560,scrollbars=yes')
}

function PopUp_SearchVehicle(varDo,varAcceptVehicleMode,varAccidentVehicle_ID,varAccidentVehicleNo,varVehicle_Nationality_No,varVehicleRegType_No,varVehicle_Plate,varVehicle_PlateID_No)
{
	PopUp_Window('vehicles.asp?d=' + varDo + '&avm=' + varAcceptVehicleMode + '&AccidentVehicle_ID=' + varAccidentVehicle_ID + '&AccidentVehicleNo=' + varAccidentVehicleNo + '&Vehicle_Nationality_No=' + varVehicle_Nationality_No + '&VehicleRegType_No=' + varVehicleRegType_No + '&Vehicle_Plate='+varVehicle_Plate + '&Vehicle_PlateID_No='+varVehicle_PlateID_No,'PopUpVehicle')
}

function PopUp_SearchPerson(varAcceptPersonMode,varDo,varPerson_Nationality_No,varNationalNo,varFirstName,varFatherName,varGrandName,varFamilyName)
{
	PopUp_Window('persons.asp?apm=' + varAcceptPersonMode + '&d=' + varDo + '&Person_Nationality_No=' + varPerson_Nationality_No + '&NationalNo=' + varNationalNo + '&FirstName=' + varFirstName + '&FatherName=' + varFatherName + '&GrandName=' + varGrandName + '&FamilyName=' + varFamilyName,'PopUpPerson')
}

function PopUp_SearchDocument(varAcceptDocumentMode,varDo,varDocument_Nationality_No,varDocumentNo,varDocumentType_No,varLicenseCategory_No,varLicenseCenter_No,varPerson_ID)
{
	PopUp_Window('documents.asp?adm=' + varAcceptDocumentMode + '&d=' + varDo + '&Document_Nationality_No=' + varDocument_Nationality_No + '&DocumentNo=' + varDocumentNo + '&DocumentType_No=' + varDocumentType_No + '&LicenseCategory_No=' + varLicenseCategory_No + '&LicenseCenter_No=' + varLicenseCenter_No + '&Person_ID=' + varPerson_ID ,'PopUpDocument')
}

function PopUp_SearchEstablishment(varDo,varAcceptEstablishmentMode,varEstablishment_Nationality_No,varEstablishment_Name)
{
	PopUp_Window('establishments.asp?aem=' + varAcceptEstablishmentMode + '&d=' + varDo + '&Establishment_Nationality_No=' + varEstablishment_Nationality_No + '&Establishment_Name=' + varEstablishment_Name ,'PopUpEstablishment')
}

function ViewHide_Item(varItem)
{
if (document.getElementById(varItem).style.display=='none')
	View_Item(varItem)
else
	Hide_Item(varItem)
}

function View_Item(varItem)
{
	document.getElementById(varItem).style.display=""
}

function View_Item_GoTo(varItem)
{
	View_Item(varItem)
	window.location.href = "#" + varItem
}

function Hide_Item(varItem)
{
	document.getElementById(varItem).style.display="none"
}

function Check_NumberTextBox(varName)
{
	txtValue = document.getElementById(varName).value
	intValue = parseInt(txtValue)
	if ((intValue = txtValue) && (intValue > 0))
	{
		document.getElementById(varName).style.background='#aed0e6';
		return true
	}
	else
	{
		document.getElementById(varName).style.background='#ff9999';
//		document.getElementById(varName).select()
//		document.getElementById(varName).focus()
		return false
	}
}

function RefreshOpenerWindow()
{
	window.opener.document.location.reload()
}

function Update_OpenerWindowURL(varURL)
{
	window.opener.document.location.href = varURL
}

function Get_UTMZone_Jordan(X,Y)
{
    Zone = 0;
    if (( Y > 3232292.60 ) && ( Y < 3707871.68 ))
    {
	if ((X > 217525.59) && (X < 528368.98))
		Zone = 37;
	else if ((X > 690289.09) && (X < 783481.25))
		Zone = 36;
    }
    return Zone;
}

function Check_Zone()
{
	X = document.getElementById("Longitude").value;
	Y = document.getElementById("Latitude").value;
	Zone = Get_UTMZone_Jordan(X,Y)
	document.getElementById("Zone").value = Zone

	if (Zone > 0)
	{
		document.getElementById("Longitude").style.background='#aed0e6';
		document.getElementById("Latitude").style.background='#aed0e6';
		return true
	}
	else
	{
		document.getElementById("Longitude").style.background='#ff9999';
		document.getElementById("Latitude").style.background='#ff9999';
		return false
	}
}
