
    function submitForm(frmtoSubmit){
        if(frmtoSubmit){
            frmtoSubmit.submit();
        }
    }
    function submitFormName(frmtoSubmit){
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id==frmtoSubmit){
                document.forms[i].submit();
            }
        }
    }
    
    function performsearch(){
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmmainsearch'){
                document.forms[i].submit();
            }
        }
    }
    function refreshpage(frmtosubmit,type){
         for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id==frmtosubmit){
                    myform = document.forms[i];
            }
        }
        mybtn = document.getElementById("hdsecurelogin");
        if(mybtn){
            mybtn.value=type;
        }
        if(myform){
            myform.submit();
        }
    }

	function SubmitEnter(e,frmtosubmit,functiontocall){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;

		if (keycode == 13)
		{
            if(frmtosubmit){
                eval(functiontocall);
            } 
		   return false;
		}
		else
		{
			return true;
		}
    }	
    
    function doConfirm(frmToSubmit){
        window.open("popup.htm","","width=150,height=50,toolbar=no,menubar=no");
    }
    var winConfirm = null;
    var winConfirm1 = null;
    var winConfirm2 = null;
    var winConfirm3 = null;
    
    function showQuoteConfirm(){
      var windowWidth = 250;
      var windowHeight = 100;
      var locX = ( screen.width - windowWidth ) / 2;
      var locY = ( screen.height - windowHeight ) / 2;
      var windowFeatures = "width=" + windowWidth
                         + ",height=" + windowHeight
                         + ",screenX=" + locX
                         + ",screenY=" + locY
                         + ",left=" + locX
                         + ",top=" + locY;
    
      /* Close window first to make sure that our window has */
      /* the desired features */
    
      if ( ( winConfirm != null )
        && !winConfirm.closed )
      {
        winConfirm.close();
      }
    
      /* Open the new confirm */
      winConfirm = open( "", "winConfirm", windowFeatures );
    
      /* Write to the confirm box */
      var theHTML = '<HEAD><TITLE>Please choose...</TITLE>'
                + '<style>'
                + 'body {'
                + '	font-family: Verdana, Arial, Helvetica, sans-serif;'
                + '	font-size: 8.5pt;'
                + '	font-style: normal;'
                + '	line-height: normal;'
                + '	font-weight: normal;'
                + '	font-variant: normal;'
                + ' margin: 0px;'
                + '	padding: 0px;'
                + '}'
                + '</style>' 
                + '</HEAD>'
                + '<BODY BGCOLOR="#FFFFFF">'
                  + '<br><CENTER><B>'
                  + 'Would you like a quote for the product you are viewing ?'
                  + '</B><FORM NAME="buttonForm">'
                  + '<INPUT TYPE="button" VALUE=" Yes  "'
                  + ' ONCLICK="opener.buttonClicked(1);self.close();">'
                  + '&nbsp;'
                  + '<INPUT TYPE="button" VALUE="  No  "'
                  + ' ONCLICK="opener.showSelectConfirm();self.close();">'
                  + '</FORM></BODY>';
    
      winConfirm.document.writeln( theHTML );
    }
    
    function showSelectConfirm(){
      var windowWidth = 250;
      var windowHeight = 110;
      var locX = ( screen.width - windowWidth ) / 2;
      var locY = ( screen.height - windowHeight ) / 2;
      var windowFeatures = "width=" + windowWidth
                         + ",height=" + windowHeight
                         + ",screenX=" + locX
                         + ",screenY=" + locY
                         + ",left=" + locX
                         + ",top=" + locY;
    
      /* Close window first to make sure that our window has */
      /* the desired features */
    
      if ( ( winConfirm1 != null )
        && !winConfirm1.closed )
      {
        winConfirm1.close();
      }
    
      /* Open the new confirm */
      winConfirm1 = open( "", "winConfirm1", windowFeatures );
      
      /* Write to the confirm box */
      var theHTML = '<HEAD><TITLE>Please choose...</TITLE>'
                    + '<style>'
                    + 'body {'
                    + '	font-family: Verdana, Arial, Helvetica, sans-serif;'
                    + '	font-size: 8.5pt;'
                    + '	font-style: normal;'
                    + '	line-height: normal;'
                    + '	font-weight: normal;'
                    + '	font-variant: normal;'
                    + ' margin: 0px;'
                    + '	padding: 0px;'
                    + '}'
                    + '</style>'   
                    + '</HEAD>'
                  + '<BODY BGCOLOR="#FFFFFF">'
                  + '<br><CENTER><B>'
                  + 'Would you like a quote for products or an integrated system ?'
                  + '</B><FORM NAME="buttonForm">'
                  + '<INPUT TYPE="button" VALUE=" Products  "'
                  + ' ONCLICK="opener.buttonClicked(0,0);self.close();">'
                  + '&nbsp;'
                  + '<INPUT TYPE="button" VALUE="  System  "'
                  + ' ONCLICK="opener.buttonClicked(0,1);self.close();">'
                  + '</FORM></BODY>';
    
      winConfirm1.document.writeln( theHTML );
    }
    
    function showSystemConfirm(){
      var windowWidth = 250;
      var windowHeight = 100;
      var locX = ( screen.width - windowWidth ) / 2;
      var locY = ( screen.height - windowHeight ) / 2;
      var windowFeatures = "width=" + windowWidth
                         + ",height=" + windowHeight
                         + ",screenX=" + locX
                         + ",screenY=" + locY
                         + ",left=" + locX
                         + ",top=" + locY;
    
      /* Close window first to make sure that our window has */
      /* the desired features */
    
      if ( ( winConfirm2 != null )
        && !winConfirm2.closed )
      {
        winConfirm2.close();
      }
    
      /* Open the new confirm */
      winConfirm2 = open( "", "winConfirm2", windowFeatures );
    
      /* Write to the confirm box */
      var theHTML = '<HEAD><TITLE>Please choose...</TITLE>'
                    + '<style>'
                    + 'body {'
                    + '	font-family: Verdana, Arial, Helvetica, sans-serif;'
                    + '	font-size: 8.5pt;'
                    + '	font-style: normal;'
                    + '	line-height: normal;'
                    + '	font-weight: normal;'
                    + '	font-variant: normal;'
                    + ' margin: 0px;'
                    + '	padding: 0px;'
                    + '}'
                    + '</style>'   
                  + '  </HEAD>'
                  + '<BODY BGCOLOR="#FFFFFF">'
                  + '<br><CENTER><B>'
                  + 'Would you like Jiskoot to recommend the system components or would you like to select them ?'
                  + '</B><FORM NAME="buttonForm">'
                  + '<INPUT TYPE="button" VALUE=" Recommend  "'
                  + ' ONCLICK="opener.sendmessage(\'frmcalc\',0);self.close();">'
                  + '&nbsp;'
                  + '<INPUT TYPE="button" VALUE="  Select  "'
                  + ' ONCLICK="opener.sendmessage(\'frmcalc\',1);self.close();">'
                  + '</FORM></BODY>';
    
      winConfirm2.document.writeln( theHTML );
    }
    
    function showSystemConfirm1(){
      var windowWidth = 250;
      var windowHeight = 150;
      var locX = ( screen.width - windowWidth ) / 2;
      var locY = ( screen.height - windowHeight ) / 2;
      var windowFeatures = "width=" + windowWidth
                         + ",height=" + windowHeight
                         + ",screenX=" + locX
                         + ",screenY=" + locY
                         + ",left=" + locX
                         + ",top=" + locY;
    
      /* Close window first to make sure that our window has */
      /* the desired features */
    
      if ( ( winConfirm3 != null )
        && !winConfirm3.closed )
      {
        winConfirm3.close();
      }
    
      /* Open the new confirm */
      winConfirm3 = open( "", "winConfirm3", windowFeatures );
    
      /* Write to the confirm box */
      var theHTML = '<HEAD><TITLE>Please choose...</TITLE>'
                    + '<style>'
                    + 'body {'
                    + '	font-family: Verdana, Arial, Helvetica, sans-serif;'
                    + '	font-size: 8.5pt;'
                    + '	font-style: normal;'
                    + '	line-height: normal;'
                    + '	font-weight: normal;'
                    + '	font-variant: normal;'
                    + ' margin: 0px;'
                    + '	padding: 0px;'
                    + '}'
                    + '</style>'     
                  + '</HEAD>'
                  + '<BODY BGCOLOR="#FFFFFF">'
                  + '<br><CENTER><B>'
                  + 'Would you like a standard system or would you like to select the components ?'
                  + '</B><FORM NAME="buttonForm">'
                  + '<INPUT TYPE="button" VALUE=" Standard  "'
                  + ' ONCLICK="opener.sendmessage(\'frmQuote\',0);self.close();">'
                  + '&nbsp;'
                  + '<INPUT TYPE="button" VALUE="  Select  "'
                  + ' ONCLICK="opener.sendmessage(\'frmQuote\',1);self.close();">'
                  + '</FORM></BODY>';
    
      winConfirm3.document.writeln( theHTML );
    }
    
    function buttonClicked( buttonChoice,typechoice )
    {
        var objfrm;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmQuote'){
                objfrm = document.forms[i];
            }
        }        
        if(objfrm){
            if(buttonChoice ==1 && objfrm.issystem.value==1){
                objfrm.technology.value=1;
                showSystemConfirm1();
            }else{    
                objfrm.prod.value=buttonChoice;
                objfrm.issystem.value=0;
                objfrm.technology.value=typechoice;
                objfrm.submit();
           }     
        }
    }
    
    function sendmessage(frmname, buttonChoice)
    {
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id==frmname){
                objfrm = document.forms[i];
            }
        }    
        objfrm.recommend.value=buttonChoice;
        objfrm.submit();
    }
    
    function msgConfirm(message){
		if (confirm (message))
			return true;
		else
			return false;
    }
    
    function validate_marineinput(objfrm){
        var bRetval = false;
        var app=0;var linesize=0;
        if(objfrm.application){
            app = objfrm.application.value;    
        }
        switch(app){
            case "1": // marine loading
                bRetval=true;
            break;
            case "2": // marine unoading
                //linesize=converttoinch(document.frmcalc.InternalDiamter.value);
                //if(linesize < 16){
                    if(converttom3(objfrm.minimumflowrate.value,"min",objfrm)>250){
                        return msgConfirm("Are you sure that your minimum flow rate low enough? In marine unloading applications the minimum flow rate is normally less than 250m3/hr when stripping and at start-up");
                    }else{
                        bRetval=true;
                    }
                //}else
                //    bRetval=true;
            break;
            case "3": //pipeline
                bRetval=true;
            break;
        }

        return bRetval;
    }
    
    function validate_vel(objfrm){
        bRetVal = false;
        try{
            var maxvel=0;
            var ID=0;
            ID = converttoinch(objfrm.InternalDiamter.value,objfrm);
            IntD = ID * 0.0254;
            maxvel = (converttom3(objfrm.maximumflowrate.value,"max",objfrm) / (900*Math.PI* Math.pow(IntD,2)));
            if(maxvel > 8){
                return msgConfirm("Are sure you maximum flow rate is low enough? The current velocity is higher than 8 m/s and this is high for this duty");
            }else{
                 bRetval=true;
            }
        }catch(e){
            bRetval=true;    
        }
        return bRetval;
    }
    
    function validate_minvis(objfrm){
        if(converttocst(objfrm.Viscosity.value,objfrm) < 1.5){
            return msgConfirm("Are you sure the viscosity is correct. This is a low viscosity and this will dramatically affect the natural mixing.");
        }else if(converttocst(objfrm.Viscosity.value,objfrm) >250){
            return msgConfirm("Are you sure the viscosity is correct. This is a high viscosity for this type of application.");
        }
        return true;    
    }
    
    function validate_density(objfrm){
        var SG = objfrm.API.value;
        if (SG < 10){
            SG = SG * 1000;                
        }else if (SG >= 10 && SG <= 100){
            SG = 141.5*1000/(131.5+SG);
        }
        if( SG < 650 || SG > 950){
            return msgConfirm("Are you sure the density is correct. Please check the figure entered.");
        }
        return true;
    }

    function converttoinch(pVal,objfrm){
        if(objfrm.internaldiametertype.value=="mm"){
            return pVal/25.4;
        }else
            return pVal;
    }

    function converttom3(pVal,pType,objfrm){
        var flowtype;
        if(pType=="min"){
            flowtype=objfrm.minflowratetype.value;
        }else if(pType=="max"){
            flowtype=objfrm.maxflowratetype.value;
        }
        if(flowtype=="bbl"){
            return pVal/6.2898108;
        }else{
            return pVal;
        }
    }
    
    function converttocst(pVal,objfrm){
        if(objfrm.viscositytype.value=="cp"){
            //var SG = document.frmcalc.API.value/1000;
            var SG = objfrm.API.value;
            if (SG >100){
                SG = SG /1000;                
            }else if (SG >= 10 && SG <= 100){
                SG = 141.5*1000/(131.5+SG);
            }
            return pVal/SG;
        }else
            return pVal;
    }
    function performcalc(){
        var bRetVal=false;
        var objfrm;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            bRetVal =validate_marineinput(objfrm);
            if(bRetVal)
                bRetVal=validate_vel(objfrm);
            if(bRetVal)
                bRetVal=validate_minvis(objfrm);
            if(bRetVal)
                bRetVal=validate_density(objfrm);
            if(bRetVal){
                objfrm.submit();
            }
        }
    }
    
    function validateSelection(){
        var validator=false;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            if(objfrm.elements['productid[]']){
                if(objfrm.elements['productid[]'].length){//more than one product
                    var element =  objfrm.elements['productid[]'];   
                    for(var i=0;i<element.length;i++){
                        var quantityname = "quantity" + element[i].value;
                        var quantityelement = objfrm.elements[quantityname];
                        var quantity = quantityelement.value;
                        if(quantity > 0){
                            validator=true;
                            break;
                        }

                    }                       
                }else{//only one product
                    var quantityname = "quantity" + objfrm.elements['productid[]'].value;
                    var quantityelement = objfrm.elements[quantityname];
                    var quantity = quantityelement.value;
                    if(quantity > 0){
                        validator=false;                            
                    }else{
                        validator=true;
                    }
                }
            }
        }               
        if(!validator){
            alert("Please select a product");
            return;
        }
        objfrm.submit();
    }
    
    function validateProdSelection(){
        var validator=false;
        var systemselector = false;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            if(objfrm.parentproductid){
                if(objfrm.parentproductid.length){//more than one product
                    var element =  objfrm.parentproductid;   
                    for(var i=0;i<element.length;i++){
                        if(element[i].checked){
                            var subprodctname = "productid" + element[i].value+'[]';
                            var mybtn = objfrm.elements[subprodctname];
                            if(mybtn){
                                if(mybtn.length){//more than one product
                                    for(var j=0;j<mybtn.length;j++){
                                        if(mybtn[j].checked){
                                            validator=true;
                                            break;
                                        }
                                    }                       
                                }else{//only one product
                                    if(mybtn.checked){
                                        validator=true;
                                    }
                                }
                            }
                            //validator=true;
                            break;
                        }
                    }                       
                }else{//only one product
                    if(objfrm.parentproductid.checked){
                        var subprodctname = "productid" + objfrm.parentproductid.value+'[]';
                        var mybtn = objfrm.elements[subprodctname];
                        if(mybtn){
                            if(mybtn.length){//more than one product
                                for(var k=0;k<mybtn.length;k++){
                                    if(mybtn[k].checked){
                                        validator=true;
                                        break;
                                    }
                                }                       
                            }else{//only one product
                                if(mybtn.checked){
                                    validator=true;
                                }
                            }
                        }   
                        validator=true;
                    }
                }    
            }
            
            if(objfrm.system){
                if(objfrm.system.length){//more than one product
                    var element =  objfrm.system;   
                    for(var l=0;l<objfrm.system.length;l++){
                        if(element[l].checked){
                            validator=true;
                            systemselector=true;
                            break;
                        }
                    }                       
                }else{//only one product
                    if(objfrm.system.checked){
                        validator=true;
                        systemselector=true;
                    }
                }    
            }    
            if(!validator){
                alert("Please select a System/Product");
                return;
            }
            if(systemselector){
                showSystemConfirm();    
                //if(msgConfirm("If you would like a standard system click 'Yes'. If you would to select the components click 'No' ")){
                //    objfrm.recommend.value="1";
                //}
            }else{
                objfrm.submit();
            }
            
            //objfrm.submit();
        }                
        
    }
    
    function validateProdSelection1(){
        var validator=false;
        var systemselector = false;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            var mainprodctname = 'parentproductid' +'[]';
            var mymainproduct = objfrm.elements[mainprodctname];
            if(mymainproduct){
                if(mymainproduct.length){//more than one product
                    var  element =  mymainproduct;
                    for(var i=0;i<element.length;i++){
                        //if(element[i].checked){
                            var subprodctname = "productid" + element[i].value+'[]';
                            var mybtn = objfrm.elements[subprodctname];
                            if(mybtn){
                                if(mybtn.length){//more than one product
                                    for(var j=0;j<mybtn.length;j++){
                                        var quantityname = "quantity" + mybtn[j].value;
                                        var quantityelement = objfrm.elements[quantityname];
                                        var quantity = quantityelement.value;
                                        if(quantity > 0){
                                        //if(mybtn[i].checked){
                                            validator=true;
                                            break;
                                        }
                                    }                       
                                }else{//only one product
                                    var quantityname = "quantity" + mybtn.value;
                                    var quantityelement = objfrm.elements[quantityname];
                                    var quantity = quantityelement.value;
                                    if(quantity > 0){
                                    //if(mybtn.checked){
                                        validator=true;
                                    }
                                }
                            }
                            //validator=true;
                            break;
                        //}
                    }                       
                }else{//only one product
                    //if(objfrm.parentproductid.checked){
                        var subprodctname = "productid" + objfrm.parentproductid.value+'[]';
                        var mybtn = objfrm.elements[subprodctname];
                        if(mybtn){
                            if(mybtn.length){//more than one product
                                for(var k=0;k<mybtn.length;k++){
                                    var quantityname = "quantity" + mybtn[k].value;
                                    var quantityelement = objfrm.elements[quantityname];
                                    var quantity = quantityelement.value;
                                    if(quantity > 0){
                                    //if(mybtn[i].checked){
                                        validator=true;
                                        break;
                                    }
                                }                       
                            }else{//only one product
                                var quantityname = "quantity" + mybtn.value;
                                var quantityelement = objfrm.elements[quantityname];
                                var quantity = quantityelement.value;
                                if(quantity > 0){
                                //if(mybtn.checked){
                                    validator=true;
                                }
                            }
                        }   
                        validator=true;
                    //}
                }    
            }
            
            if(objfrm.system){
                if(objfrm.system.length){//more than one product
                    var element =  objfrm.system;   
                    for(var l=0;l<objfrm.system.length;l++){
                        if(element[l].checked){
                            validator=true;
                            systemselector=true;
                            break;
                        }
                    }                       
                }else{//only one product
                    if(objfrm.system.checked){
                        validator=true;
                        systemselector=true;
                    }
                }    
            }    
            if(!validator){
                alert("Please select a System/Product");
                return;
            }
            if(systemselector){
                showSystemConfirm();    
                //if(msgConfirm("If you would like a standard system click 'Yes'. If you would to select the components click 'No' ")){
                //    objfrm.recommend.value="1";
                //}
            }else{
                objfrm.submit();
            }
            
            //objfrm.submit();
        }                
        
    }
    
    function validateSysSelection(){
        var validator=false;
        var systemselector = false;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            if(objfrm.recsystem){
                if(objfrm.recsystem.length){//more than one product
                    var element =  objfrm.recsystem;   
                    for(var i=0;i<objfrm.recsystem.length;i++){
                        if(element[i].checked){
                            var subprodctname = "productid" + element[i].value+'[]';
                            var mybtn = objfrm.elements[subprodctname];
                            if(mybtn){
                                if(mybtn.length){//more than one product
                                    for(var j=0;j<mybtn.length;j++){
                                        if(mybtn[j].checked){
                                            validator=true;
                                            break;
                                        }
                                    }                       
                                }else{//only one product
                                    if(mybtn.checked){
                                        validator=true;
                                    }
                                }
                            }
                            //validator=true;
                            systemselector=true;
                            break;
                        }
                    }                       
                }else{//only one product
                    if(objfrm.recsystem.checked){
                        var subprodctname = "productid" + objfrm.recsystem.value+'[]';
                        var mybtn = objfrm.elements[subprodctname];
                        if(mybtn){
                            if(mybtn.length){//more than one product
                                for(var k=0;k<mybtn.length;k++){
                                    if(mybtn[k].checked){
                                        validator=true;
                                        break;
                                    }
                                }                       
                            }else{//only one product
                                if(mybtn.checked){
                                    validator=true;
                                }
                            }
                        }    
                        validator=true;
                        systemselector=true;
                    }
                }    
            }    
            if(!validator){
                alert("Please select a product");
                return;
            }
            /*if(systemselector){
                if(msgConfirm("Do you want to select a list of components or do you want Jiskoot to recommend ?")){
                    objfrm.recommend.value="1";
                }
            }*/
            
            objfrm.submit();
        }                
        
    }
    
    function validateSysSelection1(){
        var validator=false;
        var systemselector = false;
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmcalc'){
                objfrm = document.forms[i];
            }
        }
        if(objfrm){
            var mainprodctname = 'recsystem' +'[]';
            var mymainproduct = objfrm.elements[mainprodctname];
            if(mymainproduct){
                if(mymainproduct.length){//more than onesystem
                    for(var i=0;i<mymainproduct.length;i++){
                            var subprodctname = "productid" + mymainproduct[i].value+'[]';
                            var mybtn = objfrm.elements[subprodctname];
                            if(mybtn){
                                if(mybtn.length){//more than one product
                                    for(var j=0;j<mybtn.length;j++){
                                        var quantityname = "quantity" + mybtn[j].value;
                                        var quantityelement = objfrm.elements[quantityname];
                                        var quantity = quantityelement.value;
                                        if(quantity > 0){
                                            validator=true;
                                            break;
                                        }
                                    }                       
                                }else{//only one product
                                    var quantityname = "quantity" + mybtn.value;
                                    var quantityelement = objfrm.elements[quantityname];
                                    var quantity = quantityelement.value;
                                    if(quantity > 0){
                                        validator=true;
                                    }
                                }
                            }
                            systemselector=true;
                            //break;
                    }                       
                }else{//only one product
                        var subprodctname = "productid" + mymainproduct.value+'[]';
                        var mybtn = objfrm.elements[subprodctname];
                        if(mybtn){
                            if(mybtn.length){//more than one product
                                for(var k=0;k<mybtn.length;k++){
                                    var quantityname = "quantity" + mybtn[k].value;
                                    var quantityelement = objfrm.elements[quantityname];
                                    var quantity = quantityelement.value;
                                    if(quantity > 0){
                                        validator=true;
                                        break;
                                    }
                                }                       
                            }else{//only one product
                                var quantityname = "quantity" + mybtn.value;
                                var quantityelement = objfrm.elements[quantityname];
                                var quantity = quantityelement.value;
                                if(quantity > 0){
                                    validator=true;
                                }
                            }
                        }    
                //        validator=true;
                        systemselector=true;
                }    
            }   
            if(!validator){
                alert("Please select a product");
                return;
            }
            /*if(systemselector){
                if(msgConfirm("Do you want to select a list of components or do you want Jiskoot to recommend ?")){
                    objfrm.recommend.value="1";
                }
            }*/
            
            objfrm.submit();
        }                
        
    }
    
    function showhidediv(divid){
        oDiv = document.getElementById(divid);
        if(oDiv){
            if(oDiv.style.display=='block'){
                oDiv.style.display='none';        
                oImg = document.getElementById("img"+divid);
                if(oImg){
                    oImg.src="images/ftv2pnode.gif";        
                }
            }else{
                oDiv.style.display='block';
                oImg = document.getElementById("img"+divid);
                if(oImg){
                    oImg.src="images/ftv2mnode.gif";        
                }
            }        
        }
        DV=document.body.getElementsByTagName('div');
        if(DV){
            for (i=0;i<DV.length;i++){
                if (DV[i].id!=divid){
                    DV[i].style.display='none';  
                    oImg = document.getElementById("img"+DV[i].id);
                    if(oImg){
                        oImg.src="images/ftv2pnode.gif";        
                    }                          
                }
            }
        }
    }
    
    function onselectcp(){
        var myform;
        var selectviscosity="";
        for(var i=0;i<document.forms.length;i++){
            if(document.forms[i].id=='frmquestionnaire'){
                myform = document.forms[i];
            }
        }
        if(!myform) {
            return;
        }
        if(myform.viscosityunits){
            selectviscosity=myform.viscosityunits.options[myform.viscosityunits.selectedIndex].value;
        }
        if(selectviscosity=="cP"){
            var dayelement = myform.specificgravityunits;
            if(dayelement){
                var dayoptions = dayelement.options;
                for(var i=0;i<=dayoptions.length;i++){
                    if(dayoptions[i].value=="SG"){
                        dayoptions[i].selected=true;
                        break;
                    }
                }
            } 
            
        }
    }
	
	function trhighlight(oilid,trid,checkedbox,cachesession){
		var ptrid = trid;
		var trtohighlight = document.getElementById(ptrid);	
		
	 	var myurl = "crudesel.php" ; 
 		
 
		if(trtohighlight){
			if(checkedbox.checked){
				trtohighlight.className="trhighlight";
			}else{
				trtohighlight.className="";
			}
		}
	}
	
	function ValidateSel(){
		var objfrm = document.form1;
		var retval=true;
		var tempunit="";
		var selTemp="";
		var selpress="";
		/*if(!isChecked(objfrm)){
			alert("Please select a crude oil from the list.");
			return false;
		}*/
		openWind('specilhandle.php','vapor','top=150,left=300,width=350,height=250,scrollbars=yes');
		retval=false;
		return retval;
	}
	function ValidateSel1(){
		var objfrm = document.form1;
		var retval=true;
		var tempunit="";
		var selTemp="";
		var selpress="";
		var appselected="";
		
		if(objfrm.txtOPtemp.value.length==0){
			alert("Please enter your operating temperature.");
			return false;
		}
		if(objfrm.txtOPpress.value.length==0){
			alert("Please enter your operating pressue.");
			return false;
		}
		if( isNaN(objfrm.txtOPtemp.value) ){
			alert("Please enter a numerical value for the operating temperature");
			return false;
		}
		if( isNaN(objfrm.txtOPpress.value) ){
			alert("Please enter a numerical value for the operating pressure");
			return false;
		}
		if(objfrm.txtLineSize.value.length==0){
			alert("Please enter your Internal pipe diameter.");
			return false;
		}
		if(objfrm.txtmaxflowrate.value.length==0){
			alert("Please enter your maximum flowrate.");
			return false;
		}
		if(objfrm.txtminflowrate.value.length==0){
			alert("Please enter your minimum flowrate.");
			return false;
		}
		if( isNaN(objfrm.txtLineSize.value) ){
			alert("Please enter a numerical value for internal pipe diamter");
			return false;
		}
		if( isNaN(objfrm.txtmaxflowrate.value) ){
			alert("Please enter a numerical value for maximum flow rate");
			return false;
		}
		if( isNaN(objfrm.txtminflowrate.value) ){
			alert("Please enter a numerical value for minimum flow rate");
			return false;
		}
		if( objfrm.txtCrudeCost.value.length==0){
			alert("Please enter the cost of the crude oil");
			return false;
		}
		if( objfrm.txtcapacity.value.length==0){
			alert("Please enter the refinery capacity");
			return false;
		}
		if( isNaN(objfrm.txtCrudeCost.value) ){
			alert("Please enter a numerical value for the cost of crude oil");
			return false;
		}
		if( isNaN(objfrm.txtcapacity.value) ){
			alert("Please enter a numerical value for refinery capacity");
			return false;
		}
		txtmaxflowrate = objfrm.txtmaxflowrate.value;
		txtminflowrate=objfrm.txtminflowrate.value;
		if(txtminflowrate==txtmaxflowrate || parseFloat(txtmaxflowrate) <= parseFloat(txtminflowrate) || (parseFloat(txtmaxflowrate) -parseFloat(txtminflowrate) <=5) ){
			alert("The values entered for minimum and maximum flowrates are invalid.Please enter valid flowrates.");
			return false;
		}
			
		tempunit = objfrm.tempunit.options[objfrm.tempunit.selectedIndex].value;
		pressunit = objfrm.pressunit.options[objfrm.pressunit.selectedIndex].value;
		selTemp = objfrm.txtOPtemp.value;
		selpress = objfrm.txtOPpress.value;	
		if(tempunit=="fahrenheit"){
			selTemp = (objfrm.txtOPtemp.value - 32 ) / 1.8;	
		}
		if(pressunit=="psi"){
			selpress = (objfrm.txtOPpress.value ) / 14.503861;	
		}
		if(selTemp> 60){
			retval=msgConfirm("Your operating temperature is above 60C.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		if(selTemp< 5){
			//alert("This is a low operating temperature, please call us on the number below or enter your email address below and click send and we will contact you");
			alert("This is a low operating temperature, please call us on the number below or enter your email address using the enquiry form by clicking the Enquiry button and we will contact you");
			return false;
			
		}
		if(!validateoptemp(selTemp)){
			return false;
		}
		if(selpress> 150){
			if(pressunit=="psi"){
				retval=msgConfirm("Your operating pressure is higher than 2175 psi. This may have a significant impact the system design required. Are you sure this is correct?");				
			}else{
				retval=msgConfirm("Your operating pressure is higher than 150 bar . This may have a significant impact the system design required. Are you sure this is correct?");
			}
			if(!retval){
				return false;
			}
		}
		
		
		appselected = objfrm.samplingapplication.options[objfrm.samplingapplication.selectedIndex].value;
		if(tempunit=="fahrenheit"){
			selTemp = (objfrm.txtOPtemp.value - 32 ) / 1.8;	
		}
		if(pressunit=="psi"){
			selpress = (objfrm.txtOPpress.value ) / 14.503861;	
		}
		if((appselected == "Marine Loading" || appselected=="Marine UnLoading" || appselected=="Pipeline Transfer- unstabilised crude" || appselected=="Pipeline Transfer- stabilised crude") && (selTemp <5 || selTemp> 60 )){
			retval=msgConfirm("Your operating temperature is outside the normal range for " + appselected + " operations.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		
		if((appselected == "Marine Loading" ) && (selpress> 50 )){
			retval=msgConfirm("Your operating pressure is higher than normal for marine loading.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		if((appselected == "Marine UnLoading" ) && (selpress> 25 )){
			retval=msgConfirm("Your operating pressure is higher than normal for marine unloading.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		if((appselected == "Pipeline Transfer- unstabilised crude" || appselected == "Pipeline Transfer- stabilised crude") && (selpress> 100 )){
			retval=msgConfirm("Your operating pressure is higher than normal for pipeline transportation.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		if((appselected == "Production/Allocation" || appselected == "Production/Watercut") && (selpress> 150 )){
			retval=msgConfirm("Your operating pressure is higher than normal for production operations.  Are you sure this is correct?");
			if(!retval){
				return false;
			}
		}
		if(appselected == "Marine UnLoading"){
            if(converttom3(objfrm.txtminflowrate.value,"min",objfrm)>250){
                retval = msgConfirm("Are you sure that your minimum flow rate low enough? In marine unloading applications the minimum flow rate is normally less than 250m3/hr when stripping and at start-up");
                if(!retval){
					return false;
				}
            }
        }
        try{
            var maxvel=0;
            var ID=0;
            ID = converttoinch(objfrm.txtLineSize.value,objfrm);
            IntD = ID * 0.0254;
            maxvel = (converttom3(objfrm.txtmaxflowrate.value,"max",objfrm) / (900*Math.PI* Math.pow(IntD,2)));
            if(maxvel > 8){
                retval = msgConfirm("Are you sure that your maximum flow rate is low enough? The current velocity is higher than 8 m/s and this is high for this duty");
                if(!retval){
					return false;
				}
            }
        }catch(e){
            bRetval=true;    
        }
		
        if(selTemp> 40){
			openWind('vaporpressure.php','vapor','top=150,left=300,width=350,height=250,scrollbars=yes');
			retval=false;
			return false;
		}
        
		return retval;
	}
	function validateoptemp(optempcelsius){
		retval = validateoperatingtemppoints(optempcelsius,'PourPoint','pour point');
		if(!retval){
			return retval;
		}
		
		retval = validateoperatingtemppoints(optempcelsius,'CloudPoint','cloud point');
		if(!retval){
			return retval;
		}
		
		return true;
	}
	function validateoperatingtemppoints(optempcelsius,elementname, selement){
		var objfrm = document.form1;
		var objelements;
		if(objfrm.elements[elementname]){
			objelements = objfrm.elements[elementname];
		}			    
		//var objelements = objfrm.PourPoint1;
		if(objelements){
			if(objelements.length){
				for(var i=0;i<objelements.length;i++){
                    if(parseFloat (optempcelsius) < parseFloat (objelements[i].value)  ){
                        retval = msgConfirm("Your operating temperature is below your " + selement + ".  Are you sure this is correct?");
		                if(!retval){
							return false;
						}else{
							return true;
						}
                    }
                } 				
			}else{
				if(optempcelsius < objelements.value  ){
                    retval = msgConfirm("Your operating temperature is below your " + selement + ".  Are you sure this is correct?");
	                if(!retval){
						return false;
					}
                }
			}
		}
		return true;
	}
	
	function ValidateSel2(){
		var objfrm = document.form1;
		var retval=true;
		var tempunit="";
		var selTemp="";
		var selpress="";
		var appselected="";
		
		
        var app="";var linesize=0;
        app = objfrm.hidSamplingApplication.value;    
        if(objfrm.txtLineSize.value.length==0){
			alert("Please enter your Internal pipe diameter.");
			return false;
		}
		if(objfrm.txtmaxflowrate.value.length==0){
			alert("Please enter your maximum flowrate.");
			return false;
		}
		if(objfrm.txtminflowrate.value.length==0){
			alert("Please enter your minimum flowrate.");
			return false;
		}
        if(app == "Marine UnLoading"){
            if(converttom3(objfrm.txtminflowrate.value,"min",objfrm)>250){
                retval = msgConfirm("Are you sure that your minimum flow rate low enough? In marine unloading applications the minimum flow rate is normally less than 250m3/hr when stripping and at start-up");
                if(!retval){
					return false;
				}
            }
        }
        try{
            var maxvel=0;
            var ID=0;
            ID = converttoinch(objfrm.txtLineSize.value,objfrm);
            IntD = ID * 0.0254;
            maxvel = (converttom3(objfrm.txtmaxflowrate.value,"max",objfrm) / (900*Math.PI* Math.pow(IntD,2)));
            if(maxvel > 8){
                retval = msgConfirm("Are you sure that your maximum flow rate is low enough? The current velocity is higher than 8 m/s and this is high for this duty");
                if(!retval){
					return false;
				}
            }
        }catch(e){
            bRetval=true;    
        }
		return retval;
	}
	function checkcloudpour(crudeoilid,optemp){
		if(navigator.appName == "Microsoft Internet Explorer")
    	{
        	objhttprequest  = new ActiveXObject("Microsoft.XMLHTTP");
    	}   
    	else
    	{
        	objhttprequest = new XMLHttpRequest();
    	}
	 	var myurl = "checkcloudpour.php" ;
	 	var returnval=""; 
		objhttprequest.open("GET", myurl + "?crudeoilid=" + escape(crudeoilid) + "&optemp=" + optemp, true);
		objhttprequest.onreadystatechange=function() {
			if (objhttprequest.readyState==4) {
				returnval =objhttprequest.responseText;
			} 
		}
		objhttprequest.send(null);
		return returnval;
	}
	
    function isChecked(objfrm){
	    if(objfrm){
    	    for(i=0;i< objfrm.elements.length;i++){
    		    if(objfrm.elements[i].checked)
    			    return true;
    	    }
    	}
    	return false;
	
    }
    
    function ValidateSampler(){
	    var objfrm = document.form1;
	    var selectedvalue="";
	    if(objfrm){
		    if(objfrm.currentsampler){
            	selectedvalue=objfrm.currentsampler.options[objfrm.currentsampler.selectedIndex].value;
        	}
	    }
	    if(selectedvalue.indexOf("Auto") != -1){//selected an auto sampler
	    	openWind('proved.php?sampler='+ selectedvalue,"proved","top=150,left=300,width=358,height=380,scrollbars=auto");
	    }
	    return false;
    }
    
    function Validateprove(){
	    var objfrm = document.form1;
	    var selectedvalue="";
	    var mixingtype="";
	    if(objfrm){
		    if(objfrm.rdoproved){
	            if(objfrm.rdoproved.length){
	                for(var i=0;i<objfrm.rdoproved.length;i++){
	                    if(objfrm.rdoproved[i].checked){
	                        selectedvalue=objfrm.rdoproved[i].value;
	                    }
	                }                       
	            }

            	
        	}
	    }
	    if(selectedvalue.length == 0){//selected an auto sampler
	    	alert("Please specify if your current smapler has been proved.");
	    	return false;
	    }
	    if(objfrm.cbomixingtype){
        	mixingtype=objfrm.cbomixingtype.options[objfrm.cbomixingtype.selectedIndex].value;
        }
        if(mixingtype.length == 0){//selected an auto sampler
			alert("Please select your current mixing type");
		    return false;
		}
        if(selectedvalue=="No"){
	        
    	}else if(selectedvalue=="Yes"){
	    	if(! Validateradiobut("rdoprocesschanged","Please indicate if process conditions or the fluids sampled have changed since it was proved.")){
				return false;
			}
			var provedcrude=objfrm.cboCrude.options[objfrm.cboCrude.selectedIndex].value;
			if( provedcrude.length==0 || provedcrude=="-1"){
				alert("Please select the crude used for proving");
				objfrm.cboCrude.focus();
		    	return false;
			}
			if(objfrm.txtProveLineSize.value.length==0){
				alert("Please enter the proving line size.");
				objfrm.txtProveLineSize.focus();
				return false;
			}
			if( isNaN(objfrm.txtProveLineSize.value) ){
				alert("Please enter a numerical value for the proving line size");
				objfrm.txtProveLineSize.focus();
				return false;
			}
			if(objfrm.txtProveAPI.value.length==0){
				alert("Please enter the API, density or SG.");
				objfrm.txtProveAPI.focus();
				return false;
			}
			if( isNaN(objfrm.txtProveAPI.value) ){
				alert("Please enter a numerical value for API, density or SG");
				objfrm.txtProveAPI.focus();
				return false;
			}
			if(objfrm.txtProveflowrate.value.length==0){
				alert("Please enter the proving flowrate.");
				objfrm.txtProveflowrate.focus();
				return false;
			}
			if( isNaN(objfrm.txtProveflowrate.value) ){
				alert("Please enter a numerical value for the proving flowrate");
				objfrm.txtProveflowrate.focus();
				return false;
			}
			if(objfrm.txtProveTotalwater1.value.length==0){
				alert("Please enter the total water.");
				objfrm.txtProveTotalwater1.focus();
				return false;
			}
			if( isNaN(objfrm.txtProveTotalwater1.value) ){
				alert("Please enter a numerical value for total water");
				objfrm.txtProveTotalwater1.focus();
				return false;
			}
			if(objfrm.txtProveDeviation1.value.length==0){
				alert("Please enter the Deviation.");
				objfrm.txtProveDeviation1.focus();
				return false;
			}
			if( isNaN(objfrm.txtProveDeviation1.value) ){
				alert("Please enter a numerical value for deviation");
				objfrm.txtProveDeviation1.focus();
				return false;
			}
			
    	}
    	selectedvalue="";
	    if(objfrm.rdoport){
            if(objfrm.rdoport.length){
                for(var i=0;i<objfrm.rdoport.length;i++){
                    if(objfrm.rdoport[i].checked){
                        selectedvalue=objfrm.rdoport[i].value;
                    }
                }                       
            }
        }
        if(selectedvalue.length == 0){//selected an auto sampler
	    	alert("Please confirm if your system has fixed or portable sample receivers.");
	    	return false;
	    }
	    return true;
    }
    
    function showinputs(){
	    var objfrm = document.form1;
	    var selectedvalue="";
	    if(objfrm){
		    if(objfrm.cbomixingtype){
            	selectedvalue=objfrm.cbomixingtype.options[objfrm.cbomixingtype.selectedIndex].value;
        	}
	    }
	    switch(selectedvalue){
		    case "Jetmix":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'none';
	                document.getElementById('InputPiping').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'none';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'hidden';
	                    document.InputPiping.visibility = 'hidden';
	                    document.InputMeter.visibility = 'hidden';
	                    document.InputPump.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'hidden';
	                    document.all.InputPiping.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'hidden';
	                } 
	            }
		    break;
		    case "Static":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'block';
	                document.getElementById('InputPiping').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'none';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'visible';
	                    document.InputPiping.visibility = 'hidden';
	                    document.InputMeter.visibility = 'hidden';
	                    document.InputPump.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'visible';
	                    document.all.InputPiping.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'hidden';
	                } 
	            }
		    break;
		    case "Piping":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'none';
	                document.getElementById('InputPiping').style.display = 'block';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'hidden';
	                    document.InputMeter.visibility = 'hidden';
	                    document.InputPump.visibility = 'hidden';
	                    document.InputPiping.visibility = 'visible';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'hidden';
	                    document.all.InputPiping.style.visibility = 'visible';
	                } 
	            }
	            showhidepipeinputs();
		    break;
		    case "Meter":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'block';
	                document.getElementById('InputPiping').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'none';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'hidden';
	                    document.InputMeter.visibility = 'visible';
	                    document.InputPiping.visibility = 'hidden';
	                    document.InputPump.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'visible';
	                    document.all.InputPiping.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'hidden';
	                } 
	            }
		    break;
		    case "Pump":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'none';
	                document.getElementById('InputPiping').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'block';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'hidden';
	                    document.InputMeter.visibility = 'hidden';
	                    document.InputPiping.visibility = 'hidden';
	                    document.InputPump.visibility = 'visible';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'hidden';
	                    document.all.InputPiping.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'visible';
	                } 
	            }
		    break;
		    default:
		    	if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('InputStatic').style.display = 'none';
	                document.getElementById('InputMeter').style.display = 'none';
	                document.getElementById('InputPiping').style.display = 'none';
	                document.getElementById('InputPump').style.display = 'none';
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.InputStatic.visibility = 'hidden';
	                    document.InputMeter.visibility = 'hidden';
	                    document.InputPiping.visibility = 'hidden';
	                    document.InputPump.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.InputStatic.style.visibility = 'hidden';
	                    document.all.InputMeter.style.visibility = 'hidden';
	                    document.all.InputPiping.style.visibility = 'hidden';
	                    document.all.InputPump.style.visibility = 'hidden';
	                } 
	            }
		    break;
		    
	    }
    }
    
    function showhidepipeinputs(){
	    var objfrm = document.form1;
	    var selectedvalue="";
	    if(objfrm){
		    if(objfrm.cboPipingType){
            	selectedvalue=objfrm.cboPipingType.options[objfrm.cboPipingType.selectedIndex].value;
        	}
	    }
	    if(selectedvalue=="Elbow"){
		    //case "Elbow":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('Piping_Elbow').style.display = 'block';
	                //document.getElementById('InputPiping').style.display = 'none';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.Piping_Elbow.visibility = 'visible';
	                    //document.getElementById('InputPiping').style.display = 'hidden';
	                }else { // IE 4
	                    document.all.Piping_Elbow.style.visibility = 'visible';
	                    //document.getElementById('InputPiping').style.display = 'hidden';
	                } 
	            }
		    //break;
	    }else if(selectedvalue=="Contraction" || selectedvalue=="Enlargement" || selectedvalue=="Orifice" || selectedvalue=="Circular Mitre Bends" || selectedvalue=="Swing check valve" || selectedvalue=="Angle valve" || selectedvalue=="Globe valve" || selectedvalue=="Gate valve"){
		    //case "Contraction","Enlargement":
			    if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('Piping_Elbow').style.display = 'none';
	                document.getElementById('Piping_Other').style.display = 'block';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.Piping_Elbow.visibility = 'hidden';
	                    document.Piping_Other.visibility = 'visible';
	                }else { // IE 4
	                    document.all.Piping_Elbow.style.visibility = 'hidden';
	                    document.all.Piping_Other.style.visibility = 'visible';
	                } 
	            }
		    //break;
	    }else{
		    //default:
		    	if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('Piping_Elbow').style.display = 'none';
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.Piping_Elbow.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.Piping_Elbow.style.visibility = 'hidden';
	                } 
	            }
		    //break;
		    
	    }
    }
    
    function Validateradiobut(elementname,errormessage){
	    var objfrm = document.form1;
	    var selectedvalue="";
	    if(objfrm){
		    if(objfrm.elements[elementname]){
			    var objelement = objfrm.elements[elementname];
	            if(objelement.length){
	                for(var i=0;i<objelement.length;i++){
	                    if(objelement[i].checked){
	                        selectedvalue=objelement[i].value;
	                    }
	                }                       
	            }

            	
        	}
	    }
	    if(selectedvalue.length == 0){//selected an auto sampler
	    	alert(errormessage);
	    	return false;
	    }
	    return true;
    }
    
    function ValidateSel3(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("sampler","Please select your sampler")){
			return false;
		}
		
		return true;
	}
	function ValidateSel4(){
		var objfrm = document.form1;
		var retval=true;
		if( objfrm.txtCrudeCost.value.length==0){
			alert("Please enter the cost of the crude oil");
			return false;
		}
		if( objfrm.txtcapacity.value.length==0){
			alert("Please enter the refinery capacity");
			return false;
		}
		if( isNaN(objfrm.txtCrudeCost.value) ){
			alert("Please enter a numerical value for the cost of crude oil");
			return false;
		}
		if( isNaN(objfrm.txtcapacity.value) ){
			alert("Please enter a numerical value for refinery capacity");
			return false;
		}
		
		return true;
	}
	
	function ValidateSel5(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdolossesaccept","Please specify if the losses are acceptable")){
			return false;
		}
		
		return true;
	}
	
	function Validateaddcrude(){
		var objfrm = document.form1;
		var retval=true;
		if( objfrm.txtName.value.length==0){
			alert("Please enter the name of the crude oil");
			objfrm.txtName.focus();
			return false;
		}
		if( objfrm.txtAPI.value.length==0){
			alert("Please enter the API/Density of the crude oil");
			objfrm.txtAPI.focus();
			return false;
		}
		
		/*if( objfrm.txtCloudPoint1.value.length==0){
			alert("Please enter the Cloud point of the crude oil");
			objfrm.txtCloudPoint1.focus();
			return false;
		}
		if( objfrm.txtPourPoint1.value.length==0 ){
			alert("Please enter the Pour point of the crude oil");
			objfrm.txtPourPoint1.focus();
			return false;
		}*/
		
		if( isNaN(objfrm.txtAPI.value) ){
			alert("Please enter a numerical value for API/Density");
			objfrm.txtAPI.focus();
			return false;
		}
		
		if( objfrm.txtCloudPoint1.value.length>0){
			if( isNaN(objfrm.txtCloudPoint1.value) ){
				alert("Please enter a numerical value for Cloud Point");
				objfrm.txtCloudPoint1.focus();
				return false;
			}
		}
		if( objfrm.txtPourPoint1.value.length>0){
			if( isNaN(objfrm.txtPourPoint1.value)  ){
				alert("Please enter a numerical value for Pour Point");
				objfrm.txtPourPoint1.focus();
				return false;
			}
		}		
		
		if( objfrm.txtT1.value.length>0){
			if( isNaN(objfrm.txtT1.value) ){
				alert("Please enter a numerical value for temperature");
				objfrm.txtT1.focus();
				return false;
			}				
		}
		if( objfrm.txtT2.value.length>0){
			if( isNaN(objfrm.txtT2.value) ){
				alert("Please enter a numerical value for temperature");
				objfrm.txtT2.focus();
				return false;
			}				
		}
		if( objfrm.txtV1.value.length>0){
			if( isNaN(objfrm.txtV1.value) ){
				alert("Please enter a numerical value for viscosity");
				objfrm.txtV1.focus();
				return false;
			}				
		}
		if( objfrm.txtV2.value.length>0){
			if( isNaN(objfrm.txtV2.value) ){
				alert("Please enter a numerical value for viscosity");
				objfrm.txtV2.focus();
				return false;
			}				
		}
		/*if( objfrm.txtRVP1.value.length>0){
			if( isNaN(objfrm.txtRVP1.value) ){
				alert("Please enter a numerical value for Vapor pressure");
				return false;
			}				
		}*/
		/*if( objfrm.txtRVP2.value.length>0){
			if( isNaN(objfrm.txtRVP2.value) ){
				alert("Please enter a numerical value for Vapor pressure");
				return false;
			}				
		}*/
		//if( objfrm.txtRVP1.value.length>0 &&  objfrm.txtRVP2.value.length>0){
		if( objfrm.txtRVP2.value.length>0){
			var enteredrvp=objfrm.txtRVP2.value;
			srvpunit = objfrm.rvpunit.options[objfrm.rvpunit.selectedIndex].value;
			if(srvpunit=="psi"){
				enteredrvp=converttobar(enteredrvp);
			}
			enteredrvp = parseFloat(enteredrvp);
			if(enteredrvp > 1){
				retval = msgConfirm("Your vapour pressure is above 1 bar. Is this correct? If you are using the sample for density analysis and need to ensure that the light ends are not lost, check the density box below . If not please click ok to proceed or cancel to change the RVP");
				if(!retval){
					objfrm.txtRVP2.focus();
					return false;
				}
			}
		}
		
		if( objfrm.txtV1.value.length==0 && objfrm.txtV2.value.length==0 ){
			apidens = objfrm.txtAPI.value;
			openWind('viscositywarning.php?api='+ apidens,'Warning','top=150,left=270,width=350,height=150,scrollbars=yes');
			return false;
		}
			
		return true;
	}
	
	function ValidateSel5_3(){
		var objfrm = document.form1;
	    var selectedvalue="";
	    selectedvalue = objfrm.cbomixingtype.options[objfrm.cbomixingtype.selectedIndex].value;
	    if(selectedvalue.length==0){
		    alert("Please select a mixer system");
		    return false;
	    }
	    return checksamplerselection();
		//return true;
	}
	function ValidateSel5_2(){
		var objfrm = document.form1;
		var retval=true;
		
		/*if(! Validateradiobut("rdoMixerChoice","Please choose to either ignore mixing or choose new mixer")){
			return false;
		}*/
		if(! Validateradiobut("rdoDrainChoice","Can the line can be drained to install the mixer?")){
			return false;
		}
		if(! Validateradiobut("rdoFlowturndown","Is the flow turndown greater than 4:1")){
			return false;
		}
		if(! Validateradiobut("rdopressuredrop","Is a pressure drop higher than 0.5 bar acceptable?")){
			return false;
		}
		return true;
	}
	function ValidateSel5_1_1_1(){
		var objfrm = document.form1;
		var retval=true;
		
		
		if(! Validateradiobut("rdoDrainChoice","Can the line can be drained to install the mixer?")){
			return false;
		}
		if(! Validateradiobut("rdoFlowturndown","Is the flow turndown greater than 4:1")){
			return false;
		}
		if(! Validateradiobut("rdopressuredrop","Is a pressure drop higher than 0.5 bar acceptable?")){
			return false;
		}
		return true;
	}
	function ValidateSel5_4(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoDrainChoice","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_8(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoFlowturndown","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_10(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdopressuredrop","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_10_1(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdopressuredrop","Please choose a preferred mixing system")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_11(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoCross","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_12(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoCabinet","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_13(){
		var objfrm = document.form1;
		var retval=true;
		
		/*if(! Validateradiobut("rdoSample","Please choose Yes or No")){
			return false;
		}*/
		
		return true;
	}
	function ValidateSel5_9(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoChoseJetmix","Please choose Yes or No")){
			return false;
		}
		
		return true;
	}
	function ValidateSel5_7(){
		var objfrm = document.form1;
		var retval=true;
		
		if(! Validateradiobut("rdoAnalyser","Please select an answer for all the questions")){
			return false;
		}
		if(! Validateradiobut("rdoCross","Please select an answer for all the questions ")){
			return false;
		}
		if(! Validateradiobut("rdoCabinet","Please select an answer for all the questions ")){
			return false;
		}
		//if(! Validateradiobut("rdoSample","Please select an answer for all the questions")){
		//	return false;
		//}
		return true;
	}
	
	function systemproved(){
		var objfrm = document.form1;
		var selectedvalue="";
		if(objfrm.rdoproved){
			var objelement = objfrm.rdoproved;
            if(objelement.length){
                for(var i=0;i<objelement.length;i++){
                    if(objelement[i].checked){
                        selectedvalue=objelement[i].value;
                    }
                }                       
            }
            if(selectedvalue=="Yes"){
	            if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('divSystemProved').style.display = 'block';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.divSystemProved.visibility = 'visible';
	                }else { // IE 4
	                    document.all.divSystemProved.style.visibility = 'visible';
	                } 
	            }
            }else{
	            if (document.getElementById) { // DOM3 = IE5, NS6
	                document.getElementById('divSystemProved').style.display = 'none';
	                
	            }else {
	                if (document.layers) { // Netscape 4
	                    document.divSystemProved.visibility = 'hidden';
	                }else { // IE 4
	                    document.all.divSystemProved.style.visibility = 'hidden';
	                } 
	            }
            }
		}
	}
	
	function autofillAPI(){
		var objfrm = document.form1;
	    var selectedvalue="";
	    selectedvalue = objfrm.cboCrude.options[objfrm.cboCrude.selectedIndex].value;
	    if(selectedvalue=="-1"){
		    addcrude();
		    return false;
	    }
	    if(objfrm){
		    if(objfrm.cboCrude){
            	if(objfrm.cboCrude.selectedIndex > 1){
	            	API = JSCrudeArray[objfrm.cboCrude.selectedIndex];	
	            	objfrm.txtProveAPI.value=	API;
            	}
        	}
	    }	
	}
	function Validateviscositycalc(){
		var objfrm = document.form1;
		var retval=true;
		if( objfrm.txtT1.value.length==0 || objfrm.txtV1.value.length==0 || objfrm.txtT2.value.length==0 || objfrm.txtV2.value.length==0){
			alert("Please enter all the values");
			return false;
		}
		
		
		if( isNaN(objfrm.txtT1.value) ||isNaN(objfrm.txtV1.value) ||isNaN(objfrm.T2.value) ||isNaN(objfrm.V2.value)){
			alert("Please enter a numerical value for all values");
			return false;
		}
		
		return true;
	}
	function Validatedensitycalc(){
		var objfrm = document.form1;
		var retval=true;
		if( objfrm.txtAPI.value.length==0  || objfrm.txtOPtemp.value.length==0){
			alert("Please enter all the values");
			return false;
		}
		
		
		if( isNaN(objfrm.txtAPI.value) ||isNaN(objfrm.txtOPtemp.value) ){
			alert("Please enter a numerical value for all values");
			return false;
		}
		
		return true;
	}
	function openViscCalc(){
		var sURL = "viscositycalc.php?callback=yes&T1=" + document.form1.txtT1.value + "&T2="+document.form1.txtT2.value + "&V1="+document.form1.txtV1.value + "&V2="+document.form1.txtV2.value;
		openWind(sURL,'ViscCalc','top=250,left=300,width=410,height=350,scrollbars=yes');
	}
	function openDensCalc(){
		var sURL = "densitycalc.php?callback=yes&API=" + document.form1.txtAPI.value;
		openWind(sURL,'ViscCalc','top=150,left=300,width=450,height=550,scrollbars=yes');
	}
	
	function flowclick(bValue,elementname){
		sMessage="Your calculated flow is ";
		var objfrm = document.form1;
		objelement = objfrm.elements[elementname];
		selectedvalue="";
		if(objelement){
	        if(objelement.length){
	            for(var i=0;i<objelement.length;i++){
	                if(objelement[i].checked){
	                    selectedvalue=objelement[i].value;
	                }
	            }                       
           }
        }else{
	        return;
        }
		if(bValue){
			sMessage+="more";
		}else{
			sMessage+="less";
		}
		sMessage+=" than 4:1.  Are you sure you manually want to over-ride this?";
		if( (bValue && selectedvalue=="No" ) || (!bValue && selectedvalue=="Yes") ){
			retval = msgConfirm(sMessage);
			if(!retval){ // do not want to override this
				if( (bValue && selectedvalue=="No" ) ){
					for(var i=0;i<objelement.length;i++){
		                if(objelement[i].value=="Yes"){
		                    objelement[i].checked=true;
		                }
	            	}	
				}else if(!bValue && selectedvalue=="Yes"){
					for(var i=0;i<objelement.length;i++){
		                if(objelement[i].value=="No"){
		                    objelement[i].checked=true;
		                }
	            	}
				}
			}
		}
	}
	
	function Enquiry(){
		openWind('Enquiry.php','Enquiry','top=150,left=300,width=450,height=450,scrollbars=yes');
		//retval=false;
		//return retval;
	}
	function ValidateEnquiry(){
		if( document.form1.txtEmail.value.length==0  || document.form1.txtTelephone.value.length==0){
			alert("Please enter all the values");
			return false;
		}
		return true;
	}
	
	function converttobar(psivalue){
		
		return (psivalue ) / 14.503861;	
		
	}
	function Val512(){
		var objfrm = document.form1;
	    var selectedvalue="";
	    var mixingtype="";
	    if(objfrm){
		    if(objfrm.rdomixingacceptable){
	            if(objfrm.rdomixingacceptable.length){
	                for(var i=0;i<objfrm.rdomixingacceptable.length;i++){
	                    if(objfrm.rdomixingacceptable[i].checked){
	                        selectedvalue=objfrm.rdomixingacceptable[i].value;
	                    }
	                }                       
	            }

            	
        	}
	    }
	    if(selectedvalue == "to look at the savings you can make from this change"){
	    	alert("A mixer will have no improvement over your existing sampler as it is not installed in the pipeline. Please click below to change your sampler type to see improvements.");
	    	return false;
	    }
	    return true;
	}
	
function karlfischer(){
	var selectedvalue="";
	var fileredirect="karlfischer.php";
	openWind(fileredirect,'change','top=150,left=300,width=500,height=500,scrollbars=yes');
	
}