﻿// JScript File

  function CopyToClipBoard(copytext) {
    var myText = document.getElementById(copytext);
	Copied = myText.createTextRange();
	Copied.execCommand("Copy");
  }

  function showhideLayer(layerID,w,h){   
    var popUp = document.getElementById(layerID);
    var popUpAnchor = document.getElementById(layerID + 'Anchor');
  
    var position = getElemPos(popUpAnchor);
    var myTop = position.top;
    
    var popButton = document.getElementById(layerID + 'Button');
  
    popUp.style.width = w + "px";   
    popUp.style.height = h + "px";   
  
    if (popUp.style.visibility == "visible"){
      popUp.style.visibility = "hidden";
      popButton.className = 'show_choices';
      }
    else{
      popUp.style.top = myTop + 32 + "px";
      popUp.style.visibility = "visible";
      popButton.className = 'hide_choices';
      }
  }

// Show pop-up layer
  function hideCheckLayersAdmin(inLayerID){
    var currLayer = inLayerID
    var Cat_popUp = document.getElementById('popCategories');

    var Cat_popButton = document.getElementById('popCategoriesButton');
        
    if (currLayer != 'popCategories') {
      Cat_popUp.style.visibility = "hidden";
      Cat_popButton.className = 'show_choices';
    }
  }

// Show pop-up layer
  function hideCheckLayers(inLayerID){
    var currLayer = inLayerID
    var Cat_popUp = document.getElementById('popCategories');
    var Sec_popUp = document.getElementById('popSectors');
    var Spe_popUp = document.getElementById('popSpecialisms');
    var Reg_popUp = document.getElementById('popTravelRegions');
    var Bas_popUp = document.getElementById('popBasedRegions');

    var Cat_popButton = document.getElementById('popCategoriesButton');
    var Sec_popButton = document.getElementById('popSectorsButton');
    var Spe_popButton = document.getElementById('popSpecialismsButton');
    var Reg_popButton = document.getElementById('popTravelRegionsButton');
    var Bas_popButton = document.getElementById('popBasedRegionsButton');
        
    if (currLayer != 'popCategories') {
      Cat_popUp.style.visibility = "hidden";
      Cat_popButton.className = 'show_choices';
    }
    if (currLayer != 'popSectors') {
      Sec_popUp.style.visibility = "hidden";
      Sec_popButton.className = 'show_choices';
    }    
    if (currLayer != 'popSpecialisms') {
      Spe_popUp.style.visibility = "hidden";
      Spe_popButton.className = 'show_choices';
    }    
    if (currLayer != 'popTravelRegions') {
      Reg_popUp.style.visibility = "hidden";
      Reg_popButton.className = 'show_choices';
    }
    if (currLayer != 'popBasedRegions') {
      Bas_popUp.style.visibility = "hidden";
      Bas_popButton.className = 'show_choices';
    }
  }

  function fnFromCheckToText(inCheckbox, inTextbox) {

    var objCheckbox = findObj(inCheckbox);
    var objTextbox = findObj(inTextbox);

    var objAction = findObj('hidAct_' + inCheckbox);

    strInsValue = objCheckbox.value;
    action = objAction.value;

    if (action == "1") {
      // Remove date from TextArea
      var strValue = objTextbox.value;
      idx = strValue.indexOf(strInsValue); 
      if (idx != -1) {
        strValue = strValue.replace(strInsValue + '; ', '');
        objTextbox.value = strValue;
        objAction.value = 0;
      }
      if (strValue == "") {
        objTextbox.value = "Please use the button on the right to select and remove data";
        objTextbox.style.color = "gray";
      }
    }
    else {
      // Add date to TextArea
      var strValue = objTextbox.value;
      idx2 = strValue.indexOf("Please use")
      if (idx2 != -1) {
        objTextbox.value = "";
        objTextbox.style.color = "black";
      }
      objTextbox.value = objTextbox.value + objCheckbox.value + '; ';
      objAction.value = 1;
    }
  }

  function fnMemberON(){
    var vMember = document.getElementById('MemberSearch');
    var vSupplier = document.getElementById('SupplierSearch');
    var vConsultant = document.getElementById('ConsultantSearch');
		
    vMember.className = 'iof_show';
    vSupplier.className = 'iof_hide';
    vConsultant.className = 'iof_hide';

    var vMemberResults = document.getElementById('Mem_Results');
    var vSupplierResults = document.getElementById('Sup_Results');
    var vConsultantResults = document.getElementById('Con_Results');
		
    vMemberResults.className = 'iof_show';
    vSupplierResults.className = 'iof_hide';
    vConsultantResults.className = 'iof_hide';
    
    var vMemberButton = document.getElementById('MemberSearch_Button');
    var vSupplierButton = document.getElementById('SupplierSearch_Button');
    var vConsultantButton = document.getElementById('ConsultantSearch_Button');

    vMemberButton.className = 'iof_member_on';
    vSupplierButton.className = 'iof_supplier_off';
    vConsultantButton.className = 'iof_consultant_off';
    
    var vCurrTab = document.getElementById('hidCurrTab');
    hidCurrTab.value = 'M';
  }


  function fnSupplierON(){
    var vMember = document.getElementById('MemberSearch');
    var vSupplier = document.getElementById('SupplierSearch');
    var vConsultant = document.getElementById('ConsultantSearch');
		
    vMember.className = 'iof_hide';
    vSupplier.className = 'iof_show';
    vConsultant.className = 'iof_hide';

    var vMemberResults = document.getElementById('Mem_Results');
    var vSupplierResults = document.getElementById('Sup_Results');
    var vConsultantResults = document.getElementById('Con_Results');
		
    vMemberResults.className = 'iof_hide';
    vSupplierResults.className = 'iof_show';
    vConsultantResults.className = 'iof_hide';
    
    var vMemberButton = document.getElementById('MemberSearch_Button');
    var vSupplierButton = document.getElementById('SupplierSearch_Button');
    var vConsultantButton = document.getElementById('ConsultantSearch_Button');

    vMemberButton.className = 'iof_member_off';
    vSupplierButton.className = 'iof_supplier_on';
    vConsultantButton.className = 'iof_consultant_off';
    
    var vCurrTab = document.getElementById('hidCurrTab');
    hidCurrTab.value = 'S';
  }


  function fnConsultantON(){
    var vMember = document.getElementById('MemberSearch');
    var vSupplier = document.getElementById('SupplierSearch');
    var vConsultant = document.getElementById('ConsultantSearch');
		
    vMember.className = 'iof_hide';
    vSupplier.className = 'iof_hide';
    vConsultant.className = 'iof_show';

    var vMemberResults = document.getElementById('Mem_Results');
    var vSupplierResults = document.getElementById('Sup_Results');
    var vConsultantResults = document.getElementById('Con_Results');
		
    vMemberResults.className = 'iof_hide';
    vSupplierResults.className = 'iof_hide';
    vConsultantResults.className = 'iof_show';
    
    var vMemberButton = document.getElementById('MemberSearch_Button');
    var vSupplierButton = document.getElementById('SupplierSearch_Button');
    var vConsultantButton = document.getElementById('ConsultantSearch_Button');

    vMemberButton.className = 'iof_member_off';
    vSupplierButton.className = 'iof_supplier_off';
    vConsultantButton.className = 'iof_consultant_on';
    
    var vCurrTab = document.getElementById('hidCurrTab');
    hidCurrTab.value = 'C';
  }


  function fnAreaSelected(){
    var myHeader = document.getElementById('MainHeader');
    var myButton = document.getElementById('MainButton');

    myHeader.className = 'iof_header_off';
    myButton.className = 'iof_button_off';
  }
  
  
  function fnHideAll(){
    var offFormArea1 = document.getElementById('MemberSearch');
    var offFormArea2 = document.getElementById('SupplierSearch');
    var offFormArea3 = document.getElementById('ConsultantSearch');
    var offButton1 = document.getElementById('MemberSearch_Button');
    var offButton2 = document.getElementById('SupplierSearch_Button');
    var offButton3 = document.getElementById('ConsultantSearch_Button');
    var myHeader = document.getElementById('MainHeader');
	var myButton = document.getElementById('MainButton');
	var myTab = document.getElementById('hidCurrTab');

	if(myButton.className == 'iof_button_off') {
	  offFormArea1.className = 'iof_hide';
	  offFormArea2.className = 'iof_hide';
      offFormArea3.className = 'iof_hide';
	  offButton1.className = 'iof_member_off';
	  offButton2.className = 'iof_supplier_off';
      offButton3.className = 'iof_consultant_off';
	  myHeader.className = 'iof_header_on';
	  myButton.className = 'iof_button_on';
	}else{
      if (myTab.value == 'M'){
	    offButton1.className = 'iof_member_on';
	    offFormArea1.className = 'iof_show';
	  }else{
	    offButton1.className = 'iof_member_off';
	    offFormArea1.className = 'iof_hide';
	  }
      if (myTab.value == 'S'){
	    offButton2.className = 'iof_supplier_on';
	    offFormArea2.className = 'iof_show';
	  }else{
	    offButton2.className = 'iof_supplier_off';
	    offFormArea2.className = 'iof_hide';
	  }
      if (myTab.value == 'C'){
	    offButton3.className = 'iof_consultant_on';
        offFormArea3.className = 'iof_show';
	  }else{
	    offButton3.className = 'iof_consultant_off';
        offFormArea3.className = 'iof_hide';	    
	  }	  	  
	  myHeader.className = 'iof_header_off';
	  myButton.className = 'iof_button_off';
	}
  }
  
  function fnClearCheckboxes(){
  
    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input'); 

    //cycle trough the input fields 
    for(var i=0; i < inputs.length; i++) { 

        //check if the input is a checkbox 
	if(inputs[i].getAttribute('type') == 'checkbox' || inputs[i].getAttribute('type') == 'radio') { 
             
            var img = document.getElementById('checkImage'+i);

            inputs[i].checked = '';
            
            //check if the checkbox is checked 
            if(inputs[i].checked) { 
                img.src = imgTrue; 
            } else { 
                img.src = imgFalse; 
            } 
    } 
    
    if(Left(inputs[i].getAttribute('id'), 7) == 'hidAct_'){
        inputs[i].value = '0';
    }
  }
  
    var chkMember_Individual = document.getElementById('Mem_chkMember_Individual');
    var chkMember_Organisation = document.getElementById('Mem_chkMember_Organisation');
    var chkMember_Corporate = document.getElementById('Mem_chkMember_Corporate');
    chkMember_Individual.checked = 'checked';
    chkMember_Organisation.checked = 'checked';
    chkMember_Corporate.checked = 'checked';
    document.getElementById('checkImage8').src = imgTrue;
    document.getElementById('checkImage9').src = imgTrue;
    document.getElementById('checkImage10').src = imgTrue;
  }


  function fnMemClearCriteria(){
    var txtOrganisation = document.getElementById('Mem_txtOrganisation');
    var txtForenames = document.getElementById('Mem_txtForenames');
    var txtSurname = document.getElementById('Mem_txtSurname');
    var txtJobTitle = document.getElementById('Mem_txtJobTitle');
    var txtTown = document.getElementById('Mem_txtTown');
    var txtCounty = document.getElementById('Mem_txtCounty');
    var txtPostcode = document.getElementById('Mem_txtPostcode');
    
    txtOrganisation.value = '';
    txtForenames.value = '';
    txtSurname.value = '';
    txtJobTitle.value = '';
    txtTown.value = '';
    txtCounty.value = '';
    txtPostcode.value = '';
    
    fnClearCheckboxes();
  }
  
  function fnMemSubmit(){
    var txtOrganisation = document.getElementById('Mem_txtOrganisation');
    var txtForenames = document.getElementById('Mem_txtForenames');
    var txtSurname = document.getElementById('Mem_txtSurname');
    var txtJobTitle = document.getElementById('Mem_txtJobTitle');
    var txtTown = document.getElementById('Mem_txtTown');
    var txtCounty = document.getElementById('Mem_txtCounty');
    var txtPostcode = document.getElementById('Mem_txtPostcode');

    status='';

    if ((txtOrganisation.value != "") || (txtForenames.value != "") || (txtSurname.value != "") || (txtJobTitle.value != "") || (txtTown.value != "") || (txtCounty.value != "") || (txtPostcode.value != "")){
    	document.all.frmMemberSearch.submit();	
    }else{
	    alert('You must enter at least one search criteria.');
    	return false;
    }
  }  
  
  
  function fnSupClearCriteria(){
    var txtOrganisation = document.getElementById('Sup_txtOrganisation');
    var txtForenames = document.getElementById('Sup_txtForenames');
    var txtSurname = document.getElementById('Sup_txtSurname');
    var txtTown = document.getElementById('Sup_txtTown');
    var txtCounty = document.getElementById('Sup_txtCounty');
    var txtPostcode = document.getElementById('Sup_txtPostcode');
    var txbCategories = document.getElementById('Sup_txbCategories');

    txtOrganisation.value = '';
    txtForenames.value = '';
    txtSurname.value = '';
    txtTown.value = '';
    txtCounty.value = '';
    txtPostcode.value = '';
    txbCategories.value = 'Please use the button on the right to select and remove data';
    txbCategories.style.color = "gray";
    
    fnClearCheckboxes();
  }

  function fnSupSubmit(){
    var txtOrganisation = document.getElementById('Sup_txtOrganisation');
    var txtForenames = document.getElementById('Sup_txtForenames');
    var txtSurname = document.getElementById('Sup_txtSurname');
    var txtTown = document.getElementById('Sup_txtTown');
    var txtCounty = document.getElementById('Sup_txtCounty');
    var txtPostcode = document.getElementById('Sup_txtPostcode');
    var txbCategories = document.getElementById('Sup_txbCategories');

    status='';

    if ((txtOrganisation.value != "") || (txtForenames.value != "") || (txtSurname.value != "") || (txtTown.value != "") || (txtCounty.value != "") || (txtPostcode.value != "") || (txbCategories.value != "Please use the button on the right to select and remove data")){
    	document.all.frmSupplierSearch.submit();	
    }else{
	    alert('You must enter at least one search criteria.');
    	return false;
    }
  }  
  
    
  function fnConClearCriteria(){
    var txtOrganisation = document.getElementById('Con_txtOrganisation');
    var txtForenames = document.getElementById('Con_txtForenames');
    var txtSurname = document.getElementById('Con_txtSurname');
    var txtJobTitle = document.getElementById('Con_txtJobTitle');
    var txtTown = document.getElementById('Con_txtTown');
    var txtCounty = document.getElementById('Con_txtCounty');
    var txtPostcode = document.getElementById('Con_txtPostcode');
    var txbSectors = document.getElementById('Con_txbSectors');
    var txbSpecialisms = document.getElementById('Con_txbSpecialisms');
    var txbBasedRegions = document.getElementById('Con_txbBasedRegions');
    var txbTravelRegions = document.getElementById('Con_txbTravelRegions');

    txtOrganisation.value = '';
    txtForenames.value = '';
    txtSurname.value = '';
    txtJobTitle.value = '';
    txtTown.value = '';
    txtCounty.value = '';
    txtPostcode.value = '';
    txbSectors.value = 'Please use the button on the right to select and remove data';
    txbSectors.style.color = "gray";
    txbSpecialisms.value = 'Please use the button on the right to select and remove data';
    txbSpecialisms.style.color = "gray";
    txbBasedRegions.value = 'Please use the button on the right to select and remove data';
    txbBasedRegions.style.color = "gray";
    txbTravelRegions.value = 'Please use the button on the right to select and remove data';
    txbTravelRegions.style.color = "gray";
    
    fnClearCheckboxes();
  }
  
  function fnConSubmit(){
    var txtOrganisation = document.getElementById('Con_txtOrganisation');
    var txtForenames = document.getElementById('Con_txtForenames');
    var txtSurname = document.getElementById('Con_txtSurname');
    var txtJobTitle = document.getElementById('Con_txtJobTitle');
    var txtTown = document.getElementById('Con_txtTown');
    var txtCounty = document.getElementById('Con_txtCounty');
    var txtPostcode = document.getElementById('Con_txtPostcode');
    var txbSectors = document.getElementById('Con_txbSectors');
    var txbSpecialisms = document.getElementById('Con_txbSpecialisms');
    var txbBasedRegions = document.getElementById('Con_txbBasedRegions');
    var txbTravelRegions = document.getElementById('Con_txbTravelRegions');

    status='';

    if ((txtOrganisation.value != "") || (txtForenames.value != "") || (txtSurname.value != "") || (txtJobTitle.value != "") || (txtTown.value != "") || (txtCounty.value != "") || (txtPostcode.value != "") || (txbSectors.value != "Please use the button on the right to select and remove data") || (txbSpecialisms.value != "Please use the button on the right to select and remove data") || (txbBasedRegions.value != "Please use the button on the right to select and remove data") || (txbTravelRegions.value != "Please use the button on the right to select and remove data")){
    	document.all.frmConsultantSearch.submit();
    }else{
	    alert('You must enter at least one search criteria.');
    	return false;
    }
  }
