







try {
//Creating and setting the instance of appropriate XMLHTTP Request object to a “MainXmlHttp” variable 
function MainCreateXMLHTTP()
{	var NewMainXmlHttp;
	//Creating object of XMLHTTP in IE
	try{NewMainXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e){try{NewMainXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");} 
		catch(oc)
		{NewMainXmlHttp = null;}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!NewMainXmlHttp && typeof XMLHttpRequest != "undefined") 
	{NewMainXmlHttp = new XMLHttpRequest();}
	return NewMainXmlHttp;
}

//ID = Current ParentID
//Current document Obj
//Request URL 
//LoadingMessage or the wait message if you want
function MakeRequestHandler(obj,RequestURL,LoadingMessage,ChildFunctionCall,DefaultToSingleValue,SelectedValue)
{	//Global XMLHTTP Request object
	
	var MainXmlHttp;
	MySelectBox = document.getElementById(obj);
	for (var count = MySelectBox.options.length-1; count >-1; count--)
	{MySelectBox.options[count] = null;}
	
	MySelectBox.options[MySelectBox.options.length] = new Option('Refreshing',0);
	MySelectBox.value = 0;
	MySelectBox.disabled=true;
	//We just use this to make each request unique.. so it doesnt get served by the proxy cache.
	var mytime = new Date();
	var winname = mytime.getTime();
	MainXmlHttp = MainCreateXMLHTTP();
	//	
	
	var ModifiedrequestUrl = RequestURL + "&Timer=" + winname;
	// If browser supports XMLHTTPRequest object
	if(MainXmlHttp)
	{	MainXmlHttp.onreadystatechange = function () { 
								// To make sure receiving response data from server is completed
								if(MainXmlHttp.readyState == 4)
								{		var sel = document.getElementById(obj);
															
										sel.disabled=true;
									
									  // if empty then just return back. Don't let it loop.	
										if (MainXmlHttp.responseText == '') {
									 	sel.options[0] = new Option(LoadingMessage,'0');
										return;
										} 
										
										var arrOpt = MainXmlHttp.responseText.split("||");
										for (var count = sel.options.length-1; count >-1; count--)
											{sel.options[count] = null;}
										if (arrOpt.length  >1)
											{sel.disabled=false;}
										else{sel.options[sel.options.length] = new Option(LoadingMessage,'0');
												sel.disabled=true;
												if (ChildFunctionCall != true){
													try{document.getElementById(obj).onchange();}catch(noeventattached){}	
												}
												return;
											}
											sel.options[sel.options.length] = new Option('','');
											for(var i = 0; i< arrOpt.length-1;i++){
												var arrVal = arrOpt[i].split("~");
												sel.options[sel.options.length] = new Option(arrVal[1],arrVal[0]);									
												//will automatically select the passed in value
												if (arrVal[0] == SelectedValue)
												{	
													//+1 as blank row is not included in loop for i
													var j = i + 1
													sel.options[j].selected = true;
												}
											}
												
												
										//If there is only 1 value then we have to select that and raise an event if we can.
										//we only select the default value if DefaultToSingleValue is not set to anything
										if (typeof(DefaultToSingleValue) == 'undefined' || DefaultToSingleValue == '')
										{ if(i ==1){sel.options[i].selected = true;} }	
										//just raise an event all the time.. of the change.. 
										if (ChildFunctionCall != true){
													try{document.getElementById(obj).onchange();}catch(noeventattached){}	
												}
										
										
								}

			}
		MainXmlHttp.open("GET", ModifiedrequestUrl,  true);
		MainXmlHttp.send(null);		
	}
}	
function MakeContactRequestHandler(obj,RequestURL,LoadingMessage,ChildFunctionCall,DefaultToSingleValue)
{	//Global XMLHTTP Request object
	var MainXmlHttp;
	TheLable = document.getElementById(obj);
	
	//We just use this to make each request unique.. so it doesnt get served by the proxy cache.
	var mytime = new Date();
	var winname = mytime.getTime();
	MainXmlHttp = MainCreateXMLHTTP();
	
	var ModifiedrequestUrl = RequestURL + "&Timer=" + winname;
	// If browser supports XMLHTTPRequest object
	if(MainXmlHttp)
	{	MainXmlHttp.onreadystatechange = function () { 
								// To make sure receiving response data from server is completed
								if(MainXmlHttp.readyState == 4)
								{		//var sel = document.getElementById(obj);
										//sel.disabled=true;
										var strTable = MainXmlHttp.responseText;

										TheLable.innerHTML = strTable;

										//just raise an event all the time.. of the change.. 
										if (ChildFunctionCall != true){
											try{document.getElementById(obj).onchange();}catch(noeventattached){}	
										}
								}
			}
		MainXmlHttp.open("GET", ModifiedrequestUrl,  true);
		MainXmlHttp.send(null);		
	}	
}

function GetXMLAndDoRequest(RequestURL)
{
		//We just use this to make each request unique.. so it doesnt get served by the proxy cache.
	var mytime = new Date();
	var winname = mytime.getTime();
	MainXmlHttp = MainCreateXMLHTTP();
	//
	var ModifiedrequestUrl = RequestURL + "&Timer=" + winname;
	var MainXmlHttp = MainCreateXMLHTTP();
	if(MainXmlHttp)
	{	MainXmlHttp.open("GET", ModifiedrequestUrl,  true);
		MainXmlHttp.send(null);
		return MainXmlHttp;
	}
}
function ChangeAccountsWithServiceModeID(ID, obj,ChildFunctionCall,OnlyTrading,ServiceModeID,SelectedValue) 
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/AccountHandler.aspx?SelectedCustomer=" + encodeURIComponent(ID) + "&OnlyTrading=" + encodeURIComponent(OnlyTrading) + "&ServiceModeID=" + encodeURIComponent(ServiceModeID);
	MakeRequestHandler(obj,requestUrl,'No Accounts Loaded',ChildFunctionCall,true,SelectedValue);
}
function ChangeAccounts(ID, obj,ChildFunctionCall,OnlyTrading) 
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/AccountHandler.aspx?SelectedCustomer=" + encodeURIComponent(ID) + "&OnlyTrading=" + encodeURIComponent(OnlyTrading);
	MakeRequestHandler(obj,requestUrl,'No Accounts Loaded',ChildFunctionCall);
}

function ChangeZones(ID, obj, ApplicationName, ChildFunctionCall) //,OnlyTrading) 
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ApplicationName=" + ApplicationName + "&SelectedCustomer=" + encodeURIComponent(ID);// + "&OnlyTrading=" + encodeURIComponent(OnlyTrading);
	MakeRequestHandler(obj,requestUrl,'No Zones Loaded',ChildFunctionCall);
}

function GetContactDetails(ID, obj, ApplicationName, ChildFunctionCall) //,OnlyTrading) 
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ApplicationName=" + ApplicationName + "&SelectedContact=" + encodeURIComponent(ID);// + "&OnlyTrading=" + encodeURIComponent(OnlyTrading);
	MakeContactRequestHandler(obj,requestUrl,'No Contact Info',ChildFunctionCall);
}

function ChangeContacts(ID, obj,ChildFunctionCall) 
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/LocationHandler.aspx?SearchType=contact&SelectedLocation=" + encodeURIComponent(ID);
	MakeRequestHandler(obj,requestUrl,'No Contacts Loaded',ChildFunctionCall);
}

//This function is used for Changing Products
function ChangeProducts(ID, obj,ChildFunctionCall,DefaultToSingleValue) 
{
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/LocationHandler.aspx?SearchType=product&SelectedCustomer=" + encodeURIComponent(ID);
	MakeRequestHandler(obj,requestUrl,'No Products Loaded',ChildFunctionCall,DefaultToSingleValue);
}


//Gets called when country combo box selection changes
function ChangeGenerics(ID, obj,ApplicationName)
{
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ApplicationName=" + ApplicationName + "&FirstValue=" + encodeURIComponent(ID);
	MakeRequestHandler(obj,requestUrl,'No Values Loaded');
}

function ChangeLocations(ID, obj,OnlyPermanent)
{	
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/LocationHandler.aspx?SearchType=Location&SelectedCustomer=" + encodeURIComponent(ID) + "&OnlyPermanent=" + encodeURIComponent(OnlyPermanent);
	MakeRequestHandler(obj,requestUrl,'No Locations Loaded');
}

function ChangeGenericControl(Drop1,Drop2, AppName,Tr2ID,DefaultToSingleValue)
{	if (document.getElementById(Drop1).value == '')
	{	document.getElementById(Drop2).value = '';
		document.getElementById(Tr2ID).style.display = 'none' ;	}
	else
	{ChangeGenericsHandler(document.getElementById(Drop1).value,Drop2,document.getElementById(AppName).value,DefaultToSingleValue);
		document.getElementById(Tr2ID).style.display= 'inline'; 
	}
}
/*	
function ChangeAssetMakeControl(Drop1,Drop2,Drop3, AppName,Tr2ID, Tr3ID)
{	if (document.getElementById(Drop1).value == '')
	{	document.getElementById(Drop2).value = '';
	    document.getElementById(Drop3).value = '';
		document.getElementById(Tr2ID).style.display = 'none' ;	
		document.getElementById(Tr3ID).style.display = 'none' ;	
	}
	else
	{
		ChangeGenericsHandler(document.getElementById(Drop1).value,Drop2,document.getElementById(AppName).value);
		document.getElementById(Tr2ID).style.display= 'inline'; 
	}
}	
*/
function ChangeAssetModelControl(Drop1,Drop2,Drop3, AppName,Tr2ID,Tr3ID)
{
    if ( document.getElementById(Drop2).value == '')
	{	
		document.getElementById(Drop3).value = '';
		document.getElementById(Tr3ID).style.display = 'none' ;
	}
	else
	{
		ChangeAssetModelHandler(document.getElementById(Drop1).value,document.getElementById(Drop2).value,Drop3,document.getElementById(AppName).value);
		document.getElementById(Tr3ID).style.display= 'inline'; 
	}
}	
function ChangeAssetModelHandler(ID,ID2, obj,ApplicationName) 
{
	var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ApplicationName=" + ApplicationName + "&FirstValue=" + encodeURIComponent(ID) + "&SecondValue=" + encodeURIComponent(ID2);
	MakeRequestHandler(obj,requestUrl,'No values loaded');
}
//Gets called when country combo box selection changes
function ChangeGenericsHandler(ID, obj,ApplicationName,DefaultToSingleValue) 
	{
		var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ApplicationName=" + ApplicationName + "&FirstValue=" + encodeURIComponent(ID);
		MakeRequestHandler(obj,requestUrl,'No values loaded','',DefaultToSingleValue);
	}

function ClearAutoCompleteTableAndIframe()
{
	try {if (document.getElementById('tat_table')){document.body.removeChild(document.getElementById('tat_table')); document.body.removeChild(document.getElementById('__shim'));}
	}catch(clearauto){}
}
//This function is used by the AjRouteLocation COntrol
function AjDoHideShow(RouteType,TxtCurrent, CustomerDiv,PlaceDiv,SupplierDiv,BranchDiv,WareHouseDiv)
{	
	var ControlID = CustomerDiv.substring(0,CustomerDiv.lastIndexOf("_"));
	ClearAutoCompleteTableAndIframe();
	if (RouteType =='BRANCH')
	{	try{document.getElementById(ControlID + '_BranchControl_cboBranchID').onchange();}catch(e11){}
		document.getElementById(CustomerDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(SupplierDiv).style.display = 'none';
		document.getElementById(WareHouseDiv).style.display = 'none';
		document.getElementById(BranchDiv).style.display = 'inline';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
	if (RouteType =='CUSTOMER')
	{	
		try{document.getElementById(ControlID + '_CustomerLocationControl_CboLocations').onchange();}catch(e11){}
		document.getElementById(CustomerDiv).style.display = 'inline';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(SupplierDiv).style.display = 'none';
		document.getElementById(BranchDiv).style.display = 'none';
		document.getElementById(WareHouseDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	}



	if (RouteType =='PLACE')
	{	try{document.getElementById(ControlID + '_PlaceLocationControl_CboPlaceLocation_DropDown2').onchange();}catch(e11){}
		document.getElementById(CustomerDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'inline';
		document.getElementById(SupplierDiv).style.display = 'none';
		document.getElementById(BranchDiv).style.display = 'none';
		document.getElementById(WareHouseDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	

}
	
	if (RouteType =='SUPPLIER')
	{	try{document.getElementById(ControlID + '_SupplierLocationControl_CboLocations').onchange();}catch(e11){}
		document.getElementById(CustomerDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(SupplierDiv).style.display = 'inline';
		document.getElementById(BranchDiv).style.display = 'none';
		document.getElementById(WareHouseDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
	if (RouteType =='WAREHOUSE')
	{	try{document.getElementById(ControlID + '_WarehouseLocationControl_CboWareHouseLocation_DropDown2').onchange();}catch(e11){}
		document.getElementById(CustomerDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(SupplierDiv).style.display = 'none';
		document.getElementById(BranchDiv).style.display = 'none';
		document.getElementById(WareHouseDiv).style.display = 'inline';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
}

//this function is used by AjSupplierLocation
function MonitorCustomerChange(ACustomer,TxtCustomer,CboLocation,ChkOnlyPermanent)
	{	var CustomerID = ACustomer + '_AcCustomerID_txtFieldID';
		
	try{if (document.getElementById(TxtCustomer).value != document.getElementById(CustomerID).value) { 
		document.getElementById(TxtCustomer).value = document.getElementById(CustomerID).value;
		ChangeLocations(document.getElementById(TxtCustomer).value,CboLocation, document.getElementById(ChkOnlyPermanent).checked);}
	}catch(e25){}
	setTimeout(function () { MonitorCustomerChange(ACustomer,TxtCustomer,CboLocation, ChkOnlyPermanent);},100);
	}

//this function is used by AjSupplierLocation
function MonitorSupplierChange(ACustomer,TxtCustomer,CboLocation,ChkOnlyPermanent)
	{	var CustomerID = ACustomer + '_AcSupplierID_txtFieldID';
	try{if (document.getElementById(TxtCustomer).value != document.getElementById(CustomerID).value) { 
		document.getElementById(TxtCustomer).value = document.getElementById(CustomerID).value;
		ChangeLocations(document.getElementById(TxtCustomer).value,CboLocation,document.getElementById(ChkOnlyPermanent).checked);}
	}catch(e25){}
	setTimeout(function () { MonitorSupplierChange(ACustomer,TxtCustomer,CboLocation,ChkOnlyPermanent);},100);
	}




//this function is used by AjRouteLocationzone
function DoZoneHideShow(RouteType,TxtCurrent, LocationDiv,PlaceDiv,AddressDiv,ZoneDiv)
{	
	var ControlID = LocationDiv.substring(0,LocationDiv.lastIndexOf("_"));
	ClearAutoCompleteTableAndIframe();
	if (RouteType != 'LOCATION')
	{//Get the oldbranchid make the branch id null and then call the onchange event and assign the value back..
	var OldBranchID = document.getElementById(ControlID + '_RouteLocation_BranchControl_cboBranchID').value;
	//Make the value null
	document.getElementById(ControlID + '_RouteLocation_BranchControl_cboBranchID').value = '';
	//Call the onchange event
	try{document.getElementById(ControlID + '_RouteLocation_BranchControl_cboBranchID').onchange();}catch(e11){}
	//Assign the value back
	document.getElementById(ControlID + '_RouteLocation_BranchControl_cboBranchID').value = OldBranchID;
	}
	if (RouteType =='LOCATION')
	{	
		//Over here we just raise the event as an when required on what is selected
		try{ 
			if (document.getElementById(ControlID + '_RouteLocation_RadioButtonBranch').checked == true) {
			try{document.getElementById(ControlID + '_RouteLocation_BranchControl_cboBranchID').onchange();}catch(e11){}}
			else if (document.getElementById(ControlID + '_RouteLocation_RadioButtonCustomer').checked == true) {
			try{document.getElementById(ControlID + '_RouteLocation_CustomerLocationControl_CboLocations').onchange();}catch(e11){}}
			else if (document.getElementById(ControlID + '_RouteLocation_RadioButtonSupplier').checked == true) {
			try{document.getElementById(ControlID + '_RouteLocation_SupplierLocationControl_CboLocations').onchange();}catch(e11){}
			}
			else if (document.getElementById(ControlID + '_RouteLocation_RadioButtonPlace').checked == true) {
			try{document.getElementById(ControlID + '_PlaceLocationControl_CboPlaceLocation_DropDown2').onchange();}catch(e11){}
			}
		} catch(ee2178){/*dont do anything*/}
		document.getElementById(LocationDiv).style.display = 'inline';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(AddressDiv).style.display = 'none';
		document.getElementById(ZoneDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
	if (RouteType =='PLACE')
	{	document.getElementById(LocationDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'inline';
		document.getElementById(AddressDiv).style.display = 'none';
		document.getElementById(ZoneDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
	if (RouteType =='ADDRESS')
	{	document.getElementById(LocationDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(AddressDiv).style.display = 'inline';
		document.getElementById(ZoneDiv).style.display = 'none';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
	if (RouteType =='ZONE')
	{	
		document.getElementById(LocationDiv).style.display = 'none';
		document.getElementById(PlaceDiv).style.display = 'none';
		document.getElementById(AddressDiv).style.display = 'none';
		document.getElementById(ZoneDiv).style.display = 'inline';
		document.getElementById(TxtCurrent).value = RouteType;
	}
	
}
		
function SetElementValue(ID,Type,TagName, XMLDOC)
		{	
			if (Type == 'INNERHTML')	
			{
			try {
				document.getElementById(ID).innerHTML = XMLDOC.getElementsByTagName(TagName)[0].childNodes[0].nodeValue}catch(xmldocer){ document.getElementById(ID).innerHTML = '';
			}
			}
			if (Type == 'VALUE')	
			{
			try {
				document.getElementById(ID).value = XMLDOC.getElementsByTagName(TagName)[0].childNodes[0].nodeValue}catch(xmldocer){ document.getElementById(ID).value = '';
			}
			}
}
function GetElementValue(TagName, XMLDOC)
{
	try
	{return XMLDOC.getElementsByTagName(TagName)[0].childNodes[0].nodeValue; }
	catch(getele) { return '';} 
}
function PanAlert(EventObj,Message,YesValueFunction,NoValueFunction)
{	
	var _AlertIframe = document.createElement("iframe");
	_AlertIframe.style.display = 'inline';		
	_AlertIframe.id = 'AlertIframe';
	_AlertIframe.setAttribute("frameBorder","0");
	_AlertIframe.src = '../../../../../Panorama/BusyBox.htm';
	
	var _AlertIframe1 = document.createElement("iframe");
	_AlertIframe1.style.display = 'inline';		
	_AlertIframe1.id = 'AlertIframe1';
	_AlertIframe1.setAttribute("frameBorder","0");
	_AlertIframe1.src = '../../../../../Panorama/blank.html';
	_AlertIframe1.setAttribute("allowTransparency","true");	

	document.body.appendChild(_AlertIframe);
	document.body.appendChild(_AlertIframe1);
	changeOpac(30,'AlertIframe');
	
	document.getElementById("AlertIframe").style.width = document.body.scrollWidth;
	document.getElementById("AlertIframe").style.height = document.body.scrollHeight;
	document.getElementById("AlertIframe").style.top= 0;
	document.getElementById("AlertIframe").style.left= 0;
	document.getElementById("AlertIframe").style.zIndex = 5000;
	document.getElementById("AlertIframe").style.position= "absolute";
	document.getElementById("AlertIframe").style.display = "inline";
	
	document.getElementById("AlertIframe1").style.width = document.body.clientWidth;
	document.getElementById("AlertIframe1").style.height = 200;
	document.getElementById("AlertIframe1").style.top= document.body.clientHeight/2 - 100;
	document.getElementById("AlertIframe1").style.left= 0
	document.getElementById("AlertIframe1").style.zIndex = 5222222	;
	document.getElementById("AlertIframe1").style.position= "absolute";
	document.getElementById("AlertIframe1").style.display = "inline";
	//window.scroll(0,0);
	CreateButtons(EventObj, Message,YesValueFunction, NoValueFunction);
	
}

function CreateButtons(EventObj,Message,YesValueFunction, NoValueFunction)
{
	
	var mydoc = document.getElementById("AlertIframe1").contentWindow.document;
	var YesButton = mydoc.createElement("input");YesButton.type = 'button';YesButton.value = 'Yes';	YesButton.style.width = '50px';
	var NoButton = mydoc.createElement("input");NoButton.type = 'button';NoButton.value = 'No';	NoButton.style.width = '50px';
	var input = mydoc.createElement("input");input.type = 'text';input.value = '';input.id='TT1';
	input.style.display= 'none';
	
	var newEl = mydoc.createElement('TABLE');
	newEl.id = 'AlertTable'
	newEl.style.width = '300px';
	newEl.setAttribute('align','center');
	
	
	var tmp = mydoc.createElement('TBODY');
	newEl.appendChild(tmp);
	newEl.setAttribute('cellPadding',5);

	//First Row
	var row = mydoc.createElement('TR');
	var container = mydoc.createElement("TD");
	var theData = mydoc.createTextNode("System Alert");
	//container.className = 'Header';
	container.colSpan = 2;
	container.align = 'left';
	container.style.backgroundColor= '#330099';
	container.style.fontSize = '10px';
	container.style.fontWeight = 'bolder';
	container.style.textDecoration = 'underline';
	container.style.height = '12px';
	container.style.color = 'white';
	
	container.appendChild(theData);
	
	row.appendChild(container);
	tmp.appendChild(row);
	

	//Second Row
	var row = mydoc.createElement('TR');
	var container = mydoc.createElement("TD");
	var theData = mydoc.createTextNode(Message);
	container.colSpan = 2;
	container.align = 'center';
	container.appendChild(theData);
	row.appendChild(container);
	tmp.appendChild(row);

	//Third Row
	var row = mydoc.createElement('TR');
	var container = mydoc.createElement("TD");
	container.appendChild(YesButton);
	container.align = 'right';
	row.appendChild(container);
	var container = mydoc.createElement("TD");
	container.align = 'left';
	container.appendChild(NoButton);
	row.appendChild(container);
	tmp.appendChild(row);


	//Append whole table
	mydoc.appendChild(newEl);
		

	YesButton.onclick = function() {mydoc.getElementById('TT1').value = 'YES'; 
								parent.document.body.removeChild(document.getElementById("AlertIframe1"));
								parent.document.body.removeChild(document.getElementById("AlertIframe"));
								if (YesValueFunction == 'SubmitForm')
								{   
									try
										{	document.forms(0).__EVENTARGUMENT.value = '';
											document.forms(0).__EVENTTARGET.value = EventObj.id;
											document.forms(0).submit();
										}
									catch(e22) { 
											var __EVENTTARGET = document.createElement("input");
											__EVENTTARGET.type = 'hidden';
											__EVENTTARGET.id = '__EVENTTARGET';
											__EVENTTARGET.name = '__EVENTTARGET';
											var __EVENTARGUMENT = document.createElement("input");
											__EVENTARGUMENT.type = 'hidden';
											__EVENTARGUMENT.id = '__EVENTARGUMENT';
											__EVENTARGUMENT.name = '__EVENTARGUMENT';
											myform = document.forms(0);
											__EVENTTARGET.value = EventObj.id.split("$").join(":");
											__EVENTARGUMENT.value = '';
											myform.appendChild(__EVENTTARGET);
											myform.appendChild(__EVENTARGUMENT);
											myform.submit();
										}
									
								}
								else if(YesValueFunction) {
										var script=document.createElement('script');
										script.setAttribute('type','text/javascript');
										script.text = YesValueFunction + '();';
										alert(script.text);
										document.getElementsByTagName('head').item(0).appendChild(script);
										}
								}
	NoButton.onclick = function() {mydoc.getElementById('TT1').value = 'NO';
								parent.document.body.removeChild(document.getElementById("AlertIframe1"));
								parent.document.body.removeChild(document.getElementById("AlertIframe"));
								if (NoValueFunction) {var script=document.createElement('script');
										script.setAttribute('type','text/javascript');
										script.text = NoValueFunction + '();'
										try{document.getElementsByTagName('head').item(0).appendChild(script);}catch(e223){}
									}	
								}
	
	//mydoc.appendChild(YesButton);
	//mydoc.appendChild(NoButton);
	mydoc.appendChild(input);	

}

}
catch(MainFrameWorkError)
{	JavascriptHandler(MainFrameWorkError.message + " in MainFrameWork.js", "MainFrameWork.js", -1)	}	




function VesselChanged(cboVesselName,LloydNo)
		{	
			if (document.getElementById(cboVesselName).value == '')
			{
				document.getElementById(LloydNo).value = '';
			
			}
			else
			{
				ChangeVesselHandler(document.getElementById(cboVesselName).value,LloydNo);
			}
		}
		function ChangeVesselHandler(VesselName,LloydNo ) 
		{
			var mytime = new Date();
			var winname = mytime.getTime();
			var requestUrl = "../../../../../Panorama/Export/Voyage/VoyageEditor.aspx?&DoWhat=vesselchange&Vessel=" + VesselName + "&timer=" + winname;
			var XmlHttp  = MainCreateXMLHTTP();	
			if(XmlHttp)
			{	
				XmlHttp.onreadystatechange = function () 
				{ 
					if(XmlHttp.readyState == 4)
					{				
						var arrOpt = XmlHttp.responseText.split("||");
						for(var i = 0; i<= arrOpt.length-1;i++)
						{	
							var arrVal = arrOpt[i].split(":");
							if(arrVal[0] == 'LloydNumber')
							{			
								document.getElementById(LloydNo).value = arrVal[1];
							}
						}
					} 
				}
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);		
		}
			
    };
	function LoadingPortChanged(LoadingPort,LoadingTerminal)
	{	
		if (document.getElementById(LoadingPort).value == '')
		{	
			document.getElementById(LoadingTerminal).value = '';
			document.getElementById(LoadingTerminal).disabled = true;
			
		}
		else
		{
			ChangePortHandler(document.getElementById(LoadingPort).value,LoadingTerminal);
		}
	}
	function ChangePortHandler(LoadingPort, LoadingTerminal,ApplicationName,DefaultToSingleValue) 
	{
		var mytime = new Date();
		var winname = mytime.getTime();
		var requestUrl = "../../../../../Panorama/Export/Voyage/VoyageEditor.aspx?&DoWhat=loadingportchange&LoadingPort=" + LoadingPort + "&timer=" + winname;
		MakeRequestHandler(LoadingTerminal,requestUrl,'No values loaded','','');
	}

 	function LoadingPortChangedShipment(LoadingPort,Vessel,VoyageSchedule,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,Operator,DischargePort,IsImport,lnkVoyage)
	{	
		if (document.getElementById(LoadingPort).value == '')
		{	
			document.getElementById(Vessel).value = '';
			document.getElementById(Vessel).disabled = true;
			
			document.getElementById(VesselOperator).value = '';
			document.getElementById(Operator).value = '';
			document.getElementById(DischargePort).value = '';
			document.getElementById(Operator).disabled = true;
			document.getElementById(DischargePort).disabled = true;
			
			document.getElementById(Terminal).value = '';
			document.getElementById(SupplierLocation).value = '';
			document.getElementById(VoyageETA).value = '';
			document.getElementById(VoyageETD).value = '';
			document.getElementById(ActualArrival).value = '';
			document.getElementById(ActualDeparture).value = '';
			document.getElementById(ReceivingDate).value = '';
			document.getElementById(CutoffDate).value = '';
			
			document.getElementById(lnkVoyage).innerText = 'Add New';
			document.getElementById(lnkVoyage).disabled = true;
			document.getElementById(lnkVoyage).onclick = function(){return false;};
			
			
		}
		else
		{
		    var linkurl = '../Voyage/VoyageEditor.aspx?LoadingPortID=' + document.getElementById(LoadingPort).value;
		   
    		 document.getElementById(lnkVoyage).disabled = false;
    	 	document.getElementById(lnkVoyage).onclick = function(){try { var mytime = new Date();var WinKSName = 'VoyageEditor' +  mytime.getTime() + mytime.getMilliseconds();var width,height;width = screen.availWidth - 150;height = screen.availHeight - 150; var windowstyle; windowstyle = 'screenX=0,screenY=0,menubar=yes,toolbar=yes,status=1,scrollbars=yes,resizable=1,left=50,top=50,width='+width+',height='+height;mywindow = window.open(linkurl + '&' + mytime.getTime() + mytime.getMilliseconds(),WinKSName,windowstyle);return false;}catch(e){}};
           document.getElementById(lnkVoyage).style.textDecoration = "underline";
           document.getElementById(lnkVoyage).style.cursor = "hand";
           
			ChangePortHandler2(document.getElementById(LoadingPort).value,Vessel,VoyageSchedule,'',IsImport);
		}
	}
	function ChangePortHandler2(LoadingPort, Vessel,VoyageSchedule,SearchType,IsImport) 
	{
		var mytime = new Date();
		var winname = mytime.getTime();
		var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=loadingportchange&LoadingPort=" + LoadingPort + "&VoyageScheduleID=" + VoyageSchedule + "&IsImport=" + IsImport + "&timer=" + winname;
		MakeRequestHandler(Vessel,requestUrl,'No values loaded','','');
	}
	
	
	function RefreshVesselList(LoadingPort,cboVesselName,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,IsImport,Operator,DischargePort,LineOperator,RouteID,lnkVoyage) {
	if (document.getElementById(lnkVoyage).innerText == 'Add New') {
	 ChangePortHandler2(document.getElementById(LoadingPort).value,cboVesselName,document.getElementById(cboVesselName).value,'',IsImport);
	}
	else {
	  VesselChangedShipment(LoadingPort,cboVesselName,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,IsImport,Operator,DischargePort,LineOperator,RouteID,lnkVoyage);	
	}

	
	
	 
	}

	
	function VesselChangedShipment(LoadingPort,cboVesselName,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,IsImport,Operator,DischargePort,LineOperator,RouteID,lnkVoyage) {

	if (document.getElementById(cboVesselName).value == '')
		{      
		
			//ChangePortHandler2(document.getElementById(LoadingPort).value,cboVesselName,document.getElementById(cboVesselName).value,'',IsImport);
							
			document.getElementById(VesselOperator).value = '';
			document.getElementById(Operator).value = '';
			document.getElementById(DischargePort).value = '';
			document.getElementById(Operator).disabled = true;
			document.getElementById(DischargePort).disabled = true;
			
			document.getElementById(Terminal).value = '';
			document.getElementById(SupplierLocation).value = '';
			document.getElementById(VoyageETA).value = '';
			document.getElementById(VoyageETD).value = '';
			document.getElementById(ActualArrival).value = '';
			document.getElementById(ActualDeparture).value = '';
			document.getElementById(ReceivingDate).value = '';
			document.getElementById(CutoffDate).value = '';
			document.getElementById(lnkVoyage).innerText = 'Add New';
	
	       var linkurl = '../Voyage/VoyageEditor.aspx?LoadingPortID=' + document.getElementById(LoadingPort).value;
		
			document.getElementById(lnkVoyage).onclick = function(){try { var mytime = new Date();var WinKSName = 'VoyageEditor' +  mytime.getTime() + mytime.getMilliseconds();var width,height;width = screen.availWidth - 150;height = screen.availHeight - 150; var windowstyle; windowstyle = 'screenX=0,screenY=0,menubar=yes,toolbar=yes,status=1,scrollbars=yes,resizable=1,left=50,top=50,width='+width+',height='+height;mywindow = window.open(linkurl + '&' + mytime.getTime() + mytime.getMilliseconds(),WinKSName,windowstyle);return false;}catch(e){}};
           document.getElementById(lnkVoyage).style.textDecoration = "underline";
           document.getElementById(lnkVoyage).style.cursor = "hand";
			
		
						
		}
			else
			{
			
			 document.getElementById(lnkVoyage).innerText = 'Edit';
	         var linkurl = '../Voyage/VoyageEditor.aspx?ScheduleID=' + document.getElementById(cboVesselName).value ;
             document.getElementById(lnkVoyage).style.textDecoration = "underline";
           document.getElementById(lnkVoyage).style.cursor = "hand";
          
          document.getElementById(lnkVoyage).onclick = function(){try{var mytime = new Date();var WinKSName = 'VoyageEditor' +  mytime.getTime() + mytime.getMilliseconds();var width,height;width = screen.availWidth - 150;height = screen.availHeight - 150; var windowstyle; windowstyle = 'screenX=0,screenY=0,menubar=yes,toolbar=yes,status=1,scrollbars=yes,resizable=1,left=50,top=50,width='+width+',height='+height;mywindow = window.open(linkurl + '&' + mytime.getTime() + mytime.getMilliseconds(),WinKSName,windowstyle);	return false;}catch(e){}};
			
		 		 
			ChangeVesselHandlerShipment(document.getElementById(cboVesselName).value,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,IsImport);
			  ChangeOperator(document.getElementById(cboVesselName).value,Operator,document.getElementById(LineOperator).innerText);
			    ChangeDischargePort(document.getElementById(cboVesselName).value,DischargePort,document.getElementById(RouteID).innerText);

          
			   
			}
		

}

 


 function ChangeVesselHandlerShipment(VesselName,VesselOperator,Terminal,SupplierLocation,VoyageETA,VoyageETD,ActualArrival,ActualDeparture,ReceivingDate,CutoffDate,IsImport) 
		{
			var mytime = new Date();
			var winname = mytime.getTime();
			var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=vesselchange&Vessel=" + VesselName + "&IsImport=" + IsImport + "&timer=" + winname;
			var XmlHttp  = MainCreateXMLHTTP();	
			if(XmlHttp)
			{	
				XmlHttp.onreadystatechange = function () 
				{ 
					if(XmlHttp.readyState == 4)
					{				
						var arrOpt = XmlHttp.responseText.split(";");
						for(var i = 0; i<= arrOpt.length-1;i++)
						{	
							var arrVal = arrOpt[i].split("=");
							if(arrVal[0] == 'VesselOperator')
							{			
								document.getElementById(VesselOperator).value = arrVal[1];
							}
							
							if(arrVal[0] == 'Terminal')
							{			
								document.getElementById(Terminal).value = arrVal[1];
							}
							if(arrVal[0] == 'SupplierLocation')
							{			
								document.getElementById(SupplierLocation).value = arrVal[1];
							}
								if(arrVal[0] == 'VoyageETA')
							{			
								document.getElementById(VoyageETA).value = arrVal[1];
							}
								if(arrVal[0] == 'VoyageETD')
							{			
								document.getElementById(VoyageETD).value = arrVal[1];
							}
									if(arrVal[0] == 'ActualArrival')
							{			
								document.getElementById(ActualArrival).value = arrVal[1];
							}
									if(arrVal[0] == 'ActualDeparture')
							{			
								document.getElementById(ActualDeparture).value = arrVal[1];
							}
									if(arrVal[0] == 'ReceivingDate')
							{			
								document.getElementById(ReceivingDate).value = arrVal[1];
							}
									if(arrVal[0] == 'CutoffDate')
							{			
								document.getElementById(CutoffDate).value = arrVal[1];
							}
							
							
						}
					} 
				}
				
	    	     
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);		
		}
			
             
    }
    
   function ChangeOperator(Vessel,Operator,LineOperator) 
	{
     
		var mytime = new Date();
		var winname = mytime.getTime();
		var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=operatorchange&Vessel=" + Vessel  + "&LineOperatorID=" + LineOperator + "&timer=" + winname;
	  		MakeRequestHandler(Operator,requestUrl,'No values loaded' ,'','');
	    
	   
	}
	
	function ChangeDischargePort(Vessel, DischargePort,RouteID) 
	{

		var mytime = new Date();
		var winname = mytime.getTime();
		var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=dischargeportchange&Vessel=" + Vessel + "&RouteID=" + RouteID + "&timer=" + winname;
		MakeRequestHandler(DischargePort,requestUrl,'No values loaded','','');
	   
		
	}
	
	
	
	function DischargedPortChangedShipment(DischargePort,FinalDestID,FinalDestText,ETADate,DocCutOffDate,ShipmentType) {

 
	if (document.getElementById(DischargePort).value == '')
		{  
	   document.getElementById(ETADate).value = '';
	   document.getElementById(DocCutOffDate).value = '';
	       document.getElementById(ETADate).value = 'DD/MM/YYYY';
			document.getElementById(DocCutOffDate).value = 'DD/MM/YYYY';
	         
	        document.getElementById(ETADate).className = 'readonly';
	      //  document.getElementById(ETADate).setAttribute('readOnly','true');
            document.getElementById(ETADate).disabled =true;
            document.getElementById("ETAdate_button1").disabled = true;
   	                 
			document.getElementById(DocCutOffDate).className = 'readonly';	
		 //  document.getElementById(DocCutOffDate).setAttribute('readOnly','true');
            document.getElementById(DocCutOffDate).disabled =true;
            document.getElementById('DocCutoffDate_button1').disabled =true;
		}
			else
			{
  			                    	   
			
			
		
			document.getElementById(ETADate).value = 'DD/MM/YYYY';
			document.getElementById(DocCutOffDate).value = 'DD/MM/YYYY';
			
			document.getElementById(ETADate).className = '';
		   document.getElementById(ETADate).removeAttribute('readOnly');
			document.getElementById(ETADate).disabled =false;
			document.getElementById("ETAdate_button1").disabled = false;
			document.getElementById("ETAdate_DivMain").style.display="none";
			
			document.getElementById(DocCutOffDate).className = '';
			document.getElementById(DocCutOffDate).removeAttribute('readOnly');
			document.getElementById(DocCutOffDate).disabled = false;
			document.getElementById('DocCutoffDate_button1').disabled =false;
			document.getElementById("DocCutoffDate_DivMain").style.display="none";
			 
			 
			ChangeDischargedPortSelectedHandlerShipment(document.getElementById(DischargePort).value,ETADate,DocCutOffDate,FinalDestID,FinalDestText,ShipmentType);
			
			}
	
	

	
	}
	
	
	function ChangeDischargedPortSelectedHandlerShipment(DischargePort,ETADate,DocCutOffDate,FinalDestID,FinalDestText,ShipmentType) 
		{ 
		
     	      		
			var mytime = new Date();
			var winname = mytime.getTime();
			var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=dischargeportselectedchange&DischargePort=" + DischargePort + "&timer=" + winname;
			var XmlHttp  = MainCreateXMLHTTP();	
			if(XmlHttp)
			{ 
			
				XmlHttp.onreadystatechange = function () 
				{ 
					if(XmlHttp.readyState == 4)
					{				
					
										
						var arrOpt = XmlHttp.responseText.split(";");
						for(var i = 0; i<= arrOpt.length-1;i++)
						{	
							var arrVal = arrOpt[i].split("=");
						  
						
							if(arrVal[0] == 'ETADate')
							{			
							    if (arrVal[1] != '') {  
								document.getElementById(ETADate).value = arrVal[1];
						       }
							}
							
							if(arrVal[0] == 'DocCutoffDate')
							{			
				               if (arrVal[1] != '') {  		
								document.getElementById(DocCutOffDate).value = arrVal[1];
							  }
							}
							
																
								if(arrVal[0] == 'UnLocode')
							{			
				               if (arrVal[1] != '') {  		
				               
				               	var objFinalDest = document.getElementById(FinalDestText);
		                         if (ShipmentType == 'COASTAL')  {
		            		         objFinalDest.value = arrVal[1];
  	                                 objFinalDest.style.color = 'black';
  	                              } 				               		            
							
							  }
							}
								
							
							if(arrVal[0] == 'UNLocodeID')
							{			
				               if (arrVal[1] != '') {  		
				               
				               	var objFinalDest = document.getElementById(FinalDestText);
		                         if (ShipmentType == 'COASTAL')  {
		            		         document.getElementById(FinalDestID).value = arrVal[1];
  	                             } 		
				               
				            
							
							  }
							}	
								
								
								
								
													
							
						}
					} 
				}
		  
		    
	    
	    	     
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);		
		}
			
             
    }
    
	
	function GetShipmentReference(ShipmentID,Reference) {

	if (ShipmentID == '')
		{  
 
	       document.getElementById(Reference).value = '';
						
		}
			else
			{
			
		ChangeShipmentReference(ShipmentID,Reference);
 
			}
	
	

	
	}
	
	
	function SetContainerRequiredDehireDate(HireDateField,RequiredDehireDateField,ShipmentTypeID,CustomerID) { 
	//	 if (document.getElementById(RequiredDehireDateField).value == '' || document.getElementById(RequiredDehireDateField).value == 'DD/MM/YYYY') {
	  var HireDate = document.getElementById(HireDateField).value;
	  	var mytime = new Date();
		
			//alert(document.getElementById(HireDateField).value + '~' + ContainerType);
			document.getElementById(RequiredDehireDateField).value = '';
			
			var winname = mytime.getTime();
						//var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?HireDate=" + HireDate + "&ContainerType=" + ContainerType + "&ApplicationName=getcontainerreqdehiredate";
			var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/LocationHandler.aspx?HireDate=" + HireDate + "&ShipmentTypeID=" + ShipmentTypeID + "&CustomerID=" + CustomerID +"&SearchType=getcontainerreqdehiredate";
			var XmlHttp  = MainCreateXMLHTTP();	
			if(XmlHttp)
			{ 
			
				XmlHttp.onreadystatechange = function () 
				{ 
					if(XmlHttp.readyState == 4)
					{			
			   
					var arrOpt = XmlHttp.responseText;
					
					if (arrOpt.length > 10 ) {  
					//  alert(arrOpt.indexOf('<'));
					 }
					 else {
					document.getElementById(RequiredDehireDateField).value = arrOpt;
				    }
				   
				    				
					} 
				}
		  
		    
	    
	    	     
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);		
		 }
			
	  
	  
	// }
	
	}
	
	
	
	function ChangeShipmentReference(ShipmentID,Reference) 
		{ 
     	      		
			var mytime = new Date();
			var winname = mytime.getTime();
			
			//var requestUrl = "../../../../../Panorama/Export/Shipment/ShipmentEditor.aspx?&DoWhat=dischargeportselectedchange&DischargePort=" + DischargePort + "&timer=" + winname;
			var requestUrl = "../../../../../Panorama/CRM/Controls/Ajax/GenericAJAXHandler.aspx?ShipmentID=" + ShipmentID + "&ApplicationName=getshipmentreference";
			var XmlHttp  = MainCreateXMLHTTP();	
			if(XmlHttp)
			{ 
			
				XmlHttp.onreadystatechange = function () 
				{ 
					if(XmlHttp.readyState == 4)
					{				
			
					var arrOpt = XmlHttp.responseText;
					document.getElementById(Reference).value = arrOpt;
				
				
					} 
				}
		  
		    
	    
	    	     
			XmlHttp.open("GET", requestUrl,  true);
			XmlHttp.send(null);		
		 }
			
             
    }
	

	
	
	