function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function Left(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}


// FUNCTION TO MANAGE 2 WAY SELECT
function fn_Change2waySelect(element,selectType,cleartxt){

	var theElement = document.getElementById(element).value;
	var outputText = document.getElementById('selectOutputTxt').value;
	var typeid = document.getElementById('typeid').value;

	if (element == 'select1'){ // ADD SELECTED VALUE
		if (outputText != ''){outputText = outputText + '!|!'} // IF NOT EMPTY ADD SEPERATOR
		outputText = outputText + theElement; // ADD VALUE
		document.getElementById('selectOutputTxt').value = outputText;
	}else if (element == 'select2'){ // REMOVE SELECTED VALUE, NEED TO REMOVE
		outputText = outputText.replace(theElement,''); // REMOVE VALUE
		outputText = outputText.replace('!|!!|!','!|!'); // FIX DOUBLE SEPERATOR
		if (outputText == '!|!'){outputText = ''} // IF ONLY SEPERATOR, SO CLEAR
		document.getElementById('selectOutputTxt').value = outputText;
	}

	if (cleartxt == 1) {outputText = '';};
	
	// NOW REFRESH THE SELECT DIVISION
	var URL = "../scripts/updateSelect.asp?type=" + selectType + "&str=" + outputText + "&typeid=" + typeid + "&rnd=" + Math.random();
	
	xmlReq = null;
	if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
	else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	if(xmlReq==null) return; // Failed to create the request

	xmlReq.onreadystatechange = function()
	{
		switch(xmlReq.readyState)
		{
		case 0: // Uninitialized
			break;
		case 1: // Loading
			break;
		case 2: // Loaded
			break;
		case 3: // Interactive
			break;
		case 4: // Done!
			document.getElementById('updateBox').innerHTML = xmlReq.responseText;
			break;
		default:
			break;
	    }
    }
	xmlReq.open ('GET', URL, true);
	xmlReq.send (null);
}



// FUNCTION TO CHANGE CMS EDITOR CONTENT BASED ON SELECTED PAGE TYPE
function fn_cmsPageType(){
	// HIDE ELEMENTS
	document.getElementById('cms_direct').style.display = "none";
	document.getElementById('cms_page_1').style.display = "none";
	document.getElementById('cms_page_2').style.display = "none";
	document.getElementById('cms_page_3').style.display = "none";
	document.getElementById('cms_page_4').style.display = "none";
	
	if (document.getElementById('page_type').value == 1) {
		document.getElementById('cms_page_1').style.display = "";
		document.getElementById('cms_page_2').style.display = "";
		document.getElementById('cms_page_3').style.display = "";
		document.getElementById('cms_page_4').style.display = "";
	} else if (document.getElementById('page_type').value == 2) {
		document.getElementById('cms_direct').style.display = "";
	}	
}

// FUNCTION VALIDATE CMS FORM AND TO PROVIDE PROGRESS BAR DURING UPLOAD
function cmsUpload(formName,action_value) {
	cmsForm = formName;
	cmsAction = action_value;
	cmsAlert = '';
	fn_cmsValidate();
}
var cmsAlert = ''
var cmsForm = ''
var cmsAction = ''

// FUNCTION TO VALIDATE CMS FORM
function fn_cmsValidate() {
	var URL = "../scripts/updateCMSValidateURL.asp?url=" + document.getElementById('page_url').value
	fn_xmlReq (URL , fn_cmsValidateUpdate);
}
function fn_cmsValidateUpdate(){
	if (xmlReqReturnValue != ''){cmsAlert = cmsAlert + xmlReqReturnValue + '\n'}
	if (document.getElementById('url_text').value == '') {cmsAlert = cmsAlert + 'URL Text is Required.\n'}
		
	if (document.getElementById('page_type').value == 0) {// MAKE SURE A PAGE TYPE IS SELECTED
		cmsAlert = cmsAlert + 'Page Type is Required.\n';
	} else if (document.getElementById('page_type').value == 1) {
		if (document.getElementById('page_title').value == '') {cmsAlert = cmsAlert + 'Page Title is Required.\n'}
//		if (document.getElementById('page_body').value == '') {cmsAlert = cmsAlert + 'Page Body is Required.\n'}
		if (document.getElementById('meta_title_article').value == '') {cmsAlert = cmsAlert + 'Meta Title is Required.\n'}
		if (document.getElementById('meta_description').value == '') {cmsAlert = cmsAlert + 'Meta Description is Required.\n'}
		if (document.getElementById('meta_keywords').value == '') {cmsAlert = cmsAlert + 'Meta Keyword(s) are Required.\n'}
	} else if (document.getElementById('page_type').value == 2) {
		if (document.getElementById('direct_file_name').value == '') {cmsAlert = cmsAlert + 'File Name is Required.\n'}
	}
	
	if (cmsAlert != ''){
		alert (cmsAlert);
	} else {	
		document.getElementById('form_action').value = cmsAction;
		theFeats =   "height=120,width=500,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
		theUniqueID = (new Date()).getTime() % 1000000000;
		window.open("../scripts/progressbar.asp?ID=" + theUniqueID, theUniqueID, theFeats);
		document.getElementById('unique_upload_id').value = theUniqueID;
		document.getElementById(cmsForm).submit();
	}
}

function cmsLinkConfirm(link_id,link_action){
	if (link_action == 'delete'){
		if (confirm('Are you sure you want to delete this link?')){
			document.getElementById('form_action_' + link_id).value = link_action;
			document.getElementById('update_link_form_' + link_id).submit();
		}
	} else {
		document.getElementById('form_action_' + link_id).value = link_action;
		document.getElementById('update_link_form_' + link_id).submit();
	}
}


// FUNCTION TO CLEAR FIELD VALUE
function clearField(sField){
	var theElement = document.getElementById(sField);
	theElement.value='';
	return false;
}

// FUNCTION TO CONFIRM RECEIPT OF LABELS
function fn_confirmReceipt(){
	if (confirm('Are you sure you want to confirm receipt of these labels, and add them into stock?')){
		return true;
	} else {
		return false;
	}
}

// FUNCTION TO CONFIRM LABEL ORDER IS OK
function fn_confirmAuth(){
	if (confirm('Are you sure you want to authorise this label request?\n\nThis can not be undone.')){
		return true;
	} else {
		return false;
	}
}

// FUNCTION TO CONFIRM LABEL WASTAGE
function fn_confirmWastage(){
	if (confirm('Are you sure you want to record this label as Wasted?\n\nThis action can not be undone.')){
		return true;
	} else {
		return false;
	}
}

// FUNCTION TO CONFIRM STOCK ADJUSTMENT
function fn_confirmAdjustment(){
	if (confirm('Are you sure you want to adjust stock for this product?\n\nThis action can not be undone.')){
		return true;
	} else {
		return false;
	}
}

// FUNCTION TO CHECK IF MORE LABELS ARE TO BE ISSUED
function fn_moreLabels(){
	if (confirm('Do you want to issue another label to this project?\n\nClick OK to issue another label\nClick Cancel to view this label')){
		document.getElementById('more_records').value = 'true';
	} else {
		document.getElementById('more_records').value = 'false';
	}
}

// FUNCTION TO PROVIDE PROGRESS BAR DURING UPLOAD
function uploadForm(formName) {
  theFeats =   "height=120,width=500,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
  theUniqueID = (new Date()).getTime() % 1000000000;
  window.open("../scripts/progressbar.asp?ID=" + theUniqueID, theUniqueID, theFeats);
  document.getElementById('unique_upload_id').value = theUniqueID;
  document.getElementById(formName).submit();
}

// FUNCTION TO LOAD AND CHANGE PORTAL TABS
function fn_portalTab(tab_name){
	// HIDE TAB ELEMENTS
	document.getElementById('contTab').setAttribute('class', '');
	document.getElementById('prodTab').setAttribute('class', '');
	document.getElementById('docsTab').setAttribute('class', '');
	document.getElementById('termTab').setAttribute('class', '');
	// HIDE CONTENT ELEMENTS
	document.getElementById('cont').style.display="none";
	document.getElementById('prod').style.display="none";
	document.getElementById('docs').style.display="none";
	document.getElementById('term').style.display="none";
	// SHOW TAB & CONTENT ELEMENTS
	document.getElementById(tab_name + 'Tab').setAttribute('class', 'active');
	document.getElementById(tab_name).style.display="";
}
// FUNCTION TO LOAD AND CHANGE PORTAL TABS
function fn_pportalTab(tab_name){
	// HIDE TAB ELEMENTS
	document.getElementById('contTab').setAttribute('class', '');
	document.getElementById('prodTab').setAttribute('class', '');
	// HIDE CONTENT ELEMENTS
	document.getElementById('cont').style.display="none";
	document.getElementById('prod').style.display="none";
	// SHOW TAB & CONTENT ELEMENTS
	document.getElementById(tab_name + 'Tab').setAttribute('class', 'active');
	document.getElementById(tab_name).style.display="";
}

// FUNCTION TO LOAD AND CHANGE PORTAL TABS
function fn_companyTab(tab_name){
	// HIDE TAB ELEMENTS
	document.getElementById('compTab').setAttribute('class', '');
	document.getElementById('uploTab').setAttribute('class', '');
	document.getElementById('premTab').setAttribute('class', '');
	// HIDE CONTENT ELEMENTS
	document.getElementById('comp').style.display="none";
	document.getElementById('uplo').style.display="none";
	document.getElementById('prem').style.display="none";
	// SHOW TAB & CONTENT ELEMENTS
	document.getElementById(tab_name + 'Tab').setAttribute('class', 'active');
	document.getElementById(tab_name).style.display="";
}

// FUNCTION TO RESET LICENCE FORM
function fn_resetLicenceForm(){
	document.getElementById("licenceSectors").style.display="";
	document.getElementById("licenceProducts").style.display="none";
	document.getElementById("licenceApplication").style.display="none";
}


// FUNCTION TO SHOW PARENT PRODUCT WHERE CHECKBOX IS CHECKED
function fn_parentProductCheckbox(){

	if (document.product_form.ParentProduct.checked){
		document.getElementById("parent_product").style.display="";
	} else {
		document.getElementById("parent_product").style.display="none";
	}
}

// FUNCTION TO SHOW PRODUCT DROPDOWN WHERE THE PRODUCT IS A FABRICATORS, AND THE FABRICATOR HAS LICENCED OR MULTIPLE PTODUCTS
function fn_coreCheckbox(){
	if (document.product_form.core_product.checked){
		document.getElementById("product_core_list").style.display="";
	} else {
		document.getElementById("product_core_list").style.display="none";
	}
}

// FUNCTION TO SHOW CORRECT PARTS OF APPLICATION FORM FOR DIFFERENT APPLICATION TYPES
function fn_UpdateApplicationForm(AppType){
	if (AppType == 'Regulator') {
		document.getElementById("appQMS").style.display="none";
		document.getElementById("appDoc").style.display="none";
		document.getElementById("appLogo").style.display="none";
		document.getElementById("info_text").innerHTML = "Please Note: Regulator applications are restricted to access by bona fide regulators and enforcement authorities. Applicant's credentials will be checked before granting access to the site."
	} else {
		document.getElementById("appQMS").style.display="";
		document.getElementById("appDoc").style.display="";
		document.getElementById("appLogo").style.display="";
		document.getElementById("info_text").innerHTML = "Please Note: All registrations are subject to IFC verification and may take up to 72 hours to be completed."
	}
}

// FUNCTION TO SHOW ISO PART OF FORM WHEN ISO CHECKBOX IS CHECKED
function fn_isoCheckbox(){

	if (document.registration_form.iso_status.checked){
		document.getElementById("iso_section_1").style.display="";
		document.getElementById("iso_section_2").style.display="";
		document.getElementById("iso_section_3").style.display="";
		document.getElementById("iso_section_4").style.display="";
		document.getElementById("iso_section_5").style.display="";
	} else {
		document.getElementById("iso_section_1").style.display="none";
		document.getElementById("iso_section_2").style.display="none";
		document.getElementById("iso_section_3").style.display="none";
		document.getElementById("iso_section_4").style.display="none";
		document.getElementById("iso_section_5").style.display="none";
	}
}

// FUNCTION TO MANAGE NEWS PERMISSION CHECKBOXES
function fn_checkPer(check_type){

	if (check_type == 1){
		if (document.cms_editor_form.per_pub.checked){
			document.getElementById("per_man").checked = true;
			document.getElementById("per_dis").checked = true;
			document.getElementById("per_fab").checked = true;
			document.getElementById("per_reg").checked = true;
		}
	} else {
		if (document.cms_editor_form.per_man.checked == false){
			document.getElementById("per_pub").checked = false;
		}
		if (document.cms_editor_form.per_dis.checked == false){
			document.getElementById("per_pub").checked = false;
		}
		if (document.cms_editor_form.per_fab.checked == false){
			document.getElementById("per_pub").checked = false;
		}
		if (document.cms_editor_form.per_reg.checked == false){
			document.getElementById("per_pub").checked = false;
		}
		
	//	if (document.cms_editor_form.per_man.checked && document.cms_editor_form.per_dis.checked && document.cms_editor_form.per_fab.checked && document.cms_editor_form.per_reg.checked ){
	//		document.getElementById("per_pub").checked = true;
	//	}
	}
}

// FUNCTION TO SHOW 'OTHER' BOX ON FORM
function fn_showOther(element){
	var theElement = document.getElementById(element).value;

	if (theElement == 'other'){
		document.getElementById(element).style.width='300px';
		document.getElementById(element+'other').style.display="inline";
	}else{
		document.getElementById(element).style.width='300px';
		document.getElementById(element+'other').style.display="none";
	}
}

// FUNCTION TO CHECK THE LENGTH OF THE FIELD
function fn_checkLength(element,maxlength,message){
	var theMessage = document.getElementById(message);
	if (element.value.length < parseInt(maxlength) + parseInt(1)){
		theMessage.innerHTML = element.value.length + "/" + maxlength;
	}
	else{
		element.value = element.value.substring(0,maxlength);
		theMessage.innerHTML = "<b><font color=red>Maximum number of characters exceeded!</font></b>"
	}
}
// ALL AJAX FUNCTIONS ARE BELOW

// FUNCTION TO RENAME DOCUMENT UPLOAD - CAN'T USE COMMON AJAX FUNCTION BECAUSE OF COMPLEXITY
function fn_renameUpload(action_id, upload_id){
	if (action_id == '1'){ // show rename fields
		document.getElementById("new_doc_name_" + upload_id).style.display="";	
		document.getElementById("sc_doc_name_" + upload_id).style.display="";	
		document.getElementById("doc_name_" + upload_id).style.display="none";	
		document.getElementById("r_doc_name_" + upload_id).style.display="none";
	} else if (action_id == '2'){ // save changes
		if (confirm('Are you sure you want to Rename this file?')){ 
			var theFilename = document.getElementById("new_doc_name_" + upload_id).value;
			// BUILD THE QUERY NOW
			var URL = "../scripts/updateUpload.asp?a=update&u=" + upload_id + "&n=" + theFilename + "&rnd=" + Math.random();

			xmlReq = null;
			if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
			else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
			if(xmlReq==null) return; // Failed to create the request

			xmlReq.onreadystatechange = function()
			{
				switch(xmlReq.readyState)
				{
				case 0: // Uninitialized
					break;
				case 1: // Loading
					break;
				case 2: // Loaded
					break;
				case 3: // Interactive
					break;
				case 4: // Done!
					if (xmlReq.responseText == '1'){
						alert('New Filename already exists, unable to continue');
					} else if (xmlReq.responseText == '2'){
						alert('Old file does not exist, unable to continue');
					} else if (xmlReq.responseText == '3'){
						alert('Rename Failed');
					} else {
						document.getElementById("doc_name_" + upload_id).innerHTML = xmlReq.responseText;
						document.getElementById("new_doc_name_" + upload_id).style.display="none";	
						document.getElementById("sc_doc_name_" + upload_id).style.display="none";	
						document.getElementById("doc_name_" + upload_id).style.display="";	
						document.getElementById("r_doc_name_" + upload_id).style.display="";	
						alert('Document Renamed Successfully');
					}
					break;
				default:
					break;
		      }
		    }
			xmlReq.open ('GET', URL, true);
			xmlReq.send (null);
		}
	} else if (action_id == '3'){ // Cancel Changes
		document.getElementById("new_doc_name_" + upload_id).style.display="none";	
		document.getElementById("sc_doc_name_" + upload_id).style.display="none";	
		document.getElementById("doc_name_" + upload_id).style.display="";	
		document.getElementById("r_doc_name_" + upload_id).style.display="";
	}  
}

function fn_renameCMSUpload(action_id, upload_id){
	if (action_id == '1'){ // show rename fields
		document.getElementById("new_doc_name_" + upload_id).style.display="";	
		document.getElementById("sc_doc_name_" + upload_id).style.display="";	
		document.getElementById("doc_name_" + upload_id).style.display="none";	
		document.getElementById("r_doc_name_" + upload_id).style.display="none";
	} else if (action_id == '2'){ // save changes
		if (confirm('Are you sure you want to Rename this file?')){ 
			var theFilename = document.getElementById("new_doc_name_" + upload_id).value;
			// BUILD THE QUERY NOW
			var URL = "../scripts/updateCMSUpload.asp?a=update&u=" + upload_id + "&n=" + theFilename + "&rnd=" + Math.random();

			xmlReq = null;
			if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
			else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
			if(xmlReq==null) return; // Failed to create the request

			xmlReq.onreadystatechange = function()
			{
				switch(xmlReq.readyState)
				{
				case 0: // Uninitialized
					break;
				case 1: // Loading
					break;
				case 2: // Loaded
					break;
				case 3: // Interactive
					break;
				case 4: // Done!
					if (xmlReq.responseText == '1'){
						alert('New Filename already exists, unable to continue');
					} else if (xmlReq.responseText == '2'){
						alert('Old file does not exist, unable to continue');
					} else if (xmlReq.responseText == '3'){
						alert('Rename Failed');
					} else {
						document.getElementById("doc_name_" + upload_id).innerHTML = xmlReq.responseText;
						document.getElementById("new_doc_name_" + upload_id).style.display="none";	
						document.getElementById("sc_doc_name_" + upload_id).style.display="none";	
						document.getElementById("doc_name_" + upload_id).style.display="";	
						document.getElementById("r_doc_name_" + upload_id).style.display="";	
						alert('Document Renamed Successfully');
					}
					break;
				default:
					break;
		      }
		    }
			xmlReq.open ('GET', URL, true);
			xmlReq.send (null);
		}
	} else if (action_id == '3'){ // Cancel Changes
		document.getElementById("new_doc_name_" + upload_id).style.display="none";	
		document.getElementById("sc_doc_name_" + upload_id).style.display="none";	
		document.getElementById("doc_name_" + upload_id).style.display="";	
		document.getElementById("r_doc_name_" + upload_id).style.display="";
	}  
}

// FUNCTION DELETE CMS PAGE - ONLY SHOWN ON PAGE LIST PAGE
function fn_cmsDeletePage(page_id,cms_type) {
	if (confirm('Are you sure you want to delete this page?\nPlease note any sub pages will also be deleted.')){
	if (confirm('Are you really sure?\nThis can not be undone.')){
		var URL = "../scripts/updateCMSDeleteArticle.asp?article_id=" + page_id + "&cms_type=" + cms_type
		fn_xmlReq (URL , fn_cmsDeletePageUpdate);
	} else {return false;}
	} else {return false;}
}
function fn_cmsDeletePageUpdate(){
	document.getElementById('cms_page_list').innerHTML = xmlReqReturnValue;
	alert('Page Deleted Successfully.');
}

// FUNCTION TO CONFIRM RECEIPT OF LABELS INTO STOCK
function fn_receiveStock(movement_id){
	if (confirm('Are you sure you want to confirm receipt, and add to stock?')){
		var URL = "../scripts/updateStockMovement.asp?id=" + movement_id + "&action=1"
		fn_xmlReq (URL , fn_receiveStockUpdate);
	}
}
function fn_receiveStockUpdate(){
	document.getElementById('my_stock').innerHTML = xmlReqReturnValue;
	alert('Received, and added to Stock.');
}

// FUNCTION TO CONFIRM RECEIPT OF LABELS INTO STOCK
function fn_cancelStock(movement_id,company_id){
	if (confirm('Are you sure you want to cancel this stock movement?')){
		var URL = "../../scripts/updateStockMovement.asp?id=" + movement_id + "&c=" + company_id + "&action=2"
		fn_xmlReq (URL , fn_cancelStockUpdate);
	}
}
function fn_cancelStockUpdate(){
	document.getElementById('my_stock').innerHTML = xmlReqReturnValue;
	alert('Stock Movement Cancelled.');
}



// FUNCTION TO DELETE UPLOADED DOCUMENT / LOGO
function fn_deleteCMSUpload(upload_type,upload_id){
	if (confirm('Are you sure you want to delete this file?'))
	{ if (upload_type == 1){
		var URL = "../scripts/updateCMSUpload.asp?a=delete&f=" + upload_type + "&u=" + upload_id
	} else{
		var URL = "../../updateCMSUpload.asp?a=delete&f=" + upload_type + "&u=" + upload_id
	}
		fn_xmlReq (URL , fn_deleteCMSUploadUpload);
	}
}
function fn_deleteCMSUploadUpload(){
	var retVal = xmlReqReturnValue;
	if (retVal == 'IN USE'){
		alert ('Unable to delete this file.\nIt is currently in use.');
	} else {
		var upload_id = Left(retVal,retVal.indexOf("!!"));
		var alert_msg = retVal.replace(upload_id + '!!','');
		alert (alert_msg);
		document.getElementById("cms_file_" + upload_id).style.display="none";
	}
}

// FUNCTION TO LOAD LIST OF SUITABLE LABELS FOR A PRODUCT
function fn_UpdateLabelListing(product_id){
	document.getElementById('sel_lab_ref').innerHTML = '<img src="../images/loading_small.gif" alt="Loading Data" title="Loading Data" style="margin:0;padding:0;">';
	var URL = "../scripts/updateLabelList.asp?product_id=" + product_id
	fn_xmlReq (URL , fn_UpdateLabelListingUpdate);
}
function fn_UpdateLabelListingUpdate(){
	document.getElementById('sel_lab_ref').innerHTML = xmlReqReturnValue;
}

// FUNCTION TO RE SEQUENCE CMS ARTICLE LIST
function fn_cmsSequence(article_id,seq_change,cms_type){
	var URL = "../scripts/updateCmsSequence.asp?article_id=" + article_id + "&change=" + seq_change + "&cms_type=" + cms_type
	fn_xmlReq (URL , fn_cmsSequenceUpdate);
}
function fn_cmsSequenceUpdate(){
	document.getElementById('cms_page_list').innerHTML = xmlReqReturnValue;
	alert ('Article Sequence Changed');
}


// FUNCTION TO LOAD PRODUCT LABEL REQUEST FORM
function fn_selectProductLicence(product_id){
	if (product_id == 0){
		document.getElementById('labelForm').innerHTML = xmlReq.responseText;
		document.getElementById("productSelect").style.display="";
		document.getElementById("labelForm").style.display="none";
	} else {
		// BUILD THE QUERY NOW
		var URL = "../scripts/updateLabelForm.asp?product_id=" + product_id
		fn_xmlReq (URL , fn_selectProductLicenceUpdate);
	}
}
function fn_selectProductLicenceUpdate(){
	document.getElementById('labelForm').innerHTML = xmlReqReturnValue;
	document.getElementById("productSelect").style.display="none";
	document.getElementById("labelForm").style.display="";
}

// FUNCTION TO LOAD SECTOR PRODUCTS
function fn_showLicenceProducts(sector_id){
	var URL = "../scripts/updateLicenceForm.asp?sector_id=" + sector_id + "&product_id=0"
	fn_xmlReq (URL , fn_showLicenceProductsUpdate);
}
function fn_showLicenceProductsUpdate(){
	document.getElementById('licenceProducts').innerHTML = xmlReqReturnValue;
	document.getElementById("licenceSectors").style.display="none";
	document.getElementById("licenceProducts").style.display="";
	document.getElementById("licenceApplication").style.display="none";
}

// FUNCTION TO LOAD LICENCE FORM FOR SELECTED PRODUCT
function fn_showLicenceForm(product_id,sector_id){
	var URL = "../scripts/updateLicenceForm.asp?product_id=" + product_id + "&sector_id=" + sector_id
	fn_xmlReq (URL , fn_showLicenceFormUpdate);
}
function fn_showLicenceFormUpdate(){
	document.getElementById('licenceApplication').innerHTML = xmlReqReturnValue;
	document.getElementById("licenceSectors").style.display="none";
	document.getElementById("licenceProducts").style.display="none";
	document.getElementById("licenceApplication").style.display="";
}

// FUNCTION TO DELETE UPLOADED DOCUMENT / LOGO
function fn_deleteUpload(upload_type,upload_id,company_id){
	if (confirm('Are you sure you want to delete this file?'))
	{
		var URL = "../scripts/updateUpload.asp?a=delete&f=" + upload_type + "&u=" + upload_id + "&c=" + company_id
//		var URL = "../scripts/deleteUpload.asp?f=" + upload_type + "&u=" + upload_id + "&c=" + company_id
		fn_xmlReq (URL , fn_deleteUploadUpload);
		if (upload_type == 1){ // Company Doc
			document.getElementById("comp_doc_" + upload_id).style.display="none";
		} else if (upload_type == 2){ // Company Logo
			document.getElementById("comp_logo").style.display="none";
		} else if (upload_type == 3){ // Product Doc
		
		} else if (upload_type == 4){ // Company Doc
			document.getElementById("comp_doc_" + upload_id).style.display="none";	
		} else if (upload_type == 5){ // Company Doc
			document.getElementById("comp_doc_" + upload_id).style.display="none";	
		} else if (upload_type == 6){ // Company Doc
			document.getElementById("comp_doc_" + upload_id).style.display="none";	
		} else if (upload_type == 7){ // Portal Banner
			document.getElementById("portal_banner").style.display="none";
		} else if (upload_type == 8){ // Company Cert
			document.getElementById("comp_doc_" + upload_id).style.display="none";	
		} else if (upload_type == 9){ // Product Cert
			document.getElementById("comp_doc_" + upload_id).style.display="none";
		}
	}
}
function fn_deleteUploadUpload(){
	alert (xmlReqReturnValue);
}

// FUNCTION TO UPDATE COMPANIES MAIN CONTACT
function fn_UpdateMainContact(contact_id){
	var URL = "../scripts/updateMainContact.asp?contact_id=" + contact_id
	fn_xmlReq (URL , fn_UpdateMainContactUpdate);
}
function fn_UpdateMainContactUpdate(){
	alert (xmlReqReturnValue);
}

// FUNCTION TO CHECK IF THERE IS A LIST OF PRODUCT TYPES UNDER THIS SECTOR, AND IF SO ADD A 2 WAY DROPDOWN TO THE PAGE
function fn_UpdateProductSector(sector_id){
	var URL = "../scripts/updateProductSector.asp?id=" + sector_id
	document.getElementById('sectorid').value = sector_id;
	fn_xmlReq (URL , fn_UpdateProductSectorUpdate);
}
function fn_UpdateProductSectorUpdate(){
	if (xmlReqReturnValue == '1') {
		document.getElementById("productTypes").style.display="";
		document.getElementById('sector_types').value = 1;
		fn_ChangeProductTypes();
		} else {
		document.getElementById("productTypes").style.display="none";
		document.getElementById('sector_types').value = 0;
		fn_ChangeProductTypes();
	}
}

// FUNCTION TO UPDATE PRODUCT TYPES ON SCREEN
function fn_ChangeSelect(element,selectType,cleartxt){
	var sector_id = document.getElementById('sectorid').value;
	var URL = "../scripts/updateProductTypes.asp?typeid=" + sector_id
	fn_xmlReq (URL , fn_ChangeSelectUpdate);
}
function fn_ChangeSelectUpdate(){
	document.getElementById('updateBox2').innerHTML = xmlReqReturnValue;
}

// FUNCTION TO UPDATE PRODUCT TYPES ON SCREEN
function fn_ChangeProductTypes(){
	var sector_id = document.getElementById('sectorid').value;
	// NOW REFRESH THE SELECT DIVISION
	var URL = "../scripts/updateProductTypes.asp?typeid=" + sector_id + "&rnd=" + Math.random();
	fn_xmlReq (URL , fn_ChangeProductTypesUpdate);
}
function fn_ChangeProductTypesUpdate(){
	document.getElementById('updateBox').innerHTML = xmlReqReturnValue;
}

var xmlReqReturnValue 
// FUNCTION TO SEND XML REQUESTS
function fn_xmlReq(passedURL,theFunction){

	passedURL = passedURL + "&rnd=" + Math.random();

	xmlReq = null;
	if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
	else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	if(xmlReq==null) return; // Failed to create the request

	xmlReq.onreadystatechange = function()
	{
		switch(xmlReq.readyState)
		{
		case 0: // Uninitialized
			break;
		case 1: // Loading
			break;
		case 2: // Loaded
			break;
		case 3: // Interactive
			break;
		case 4: // Done!
			xmlReqReturnValue = xmlReq.responseText;
			theFunction()
			break;
		default:
			break;
      }
    }
	xmlReq.open ('GET', passedURL, true);
	xmlReq.send (null);
}