      function clearForms() {
        var i;
        for (i = 0; (i < document.forms.length); i++) {
          document.forms[i].reset();
        }
      }
      function download(){
        if(confirm("This code is free to download and use on non-profit websites only.\n\nIf your website makes a profit, is transactional or shows ads please upgrade.\n\nTo access your download please show you agree and understand by clicking 'OK'\n\nClicking 'Cancel' will redirect you to PayPal so you can pay the required upgrade fee. \n\nBefore you upgrade please ensure the code works on your site and meets your expectations.\n\nThe code is available to download without upgrading so you can assess it works.")){
          window.location="?dl";
        }else{
          window.location="?volume=49999";
        }
      }
      function generate_function_call(){
      	var iphone = document.getElementById('iphone_form').value;
        if(iphone==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like the iPhone to be handled");
          document.theform.iphone_form.focus();
          return;
        }
        if(iphone=='redirect'){
        	var iphoneurl = document.getElementById('iphoneurl').value;
          if(iphoneurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you like to redirect iPhone users?");
            document.theform.iphoneurl.focus();
            return;
          }else{
            var iphone = "'"+iphoneurl+"'";
          }
        }
      	var android = document.getElementById('android_form').value;
        if(android==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like Android phones to be handled");
          document.theform.android_form.focus();
          return;
        }
        if(android=='redirect'){
        	var androidurl = document.getElementById('androidurl').value;
          if(androidurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you like to redirect Android users?");
            document.theform.androidurl.focus();
            return;
          }else{
            var android = "'"+androidurl+"'";
          }
        }
      	var opera = document.getElementById('opera_form').value;
        if(opera==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like Opera Mini browsers to be handled");
          document.theform.opera_form.focus();
          return;
        }
        if(opera=='redirect'){
        	var operaurl = document.getElementById('operaurl').value;
          if(operaurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you ike to redirect Opera Mini users?");
            document.theform.operaurl.focus();
            return;
          }else{
            var opera = "'"+operaurl+"'";
          }
        }
      	var blackberry = document.getElementById('blackberry_form').value;
        if(blackberry==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like Blackberry devices to be handled");
          document.theform.blackberry_form.focus();
          return;
        }
        if(blackberry=='redirect'){
        	var blackberryurl = document.getElementById('blackberryurl').value;
          if(blackberryurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you ike to redirect Blackberry users?");
            document.theform.blackberryurl.focus();
            return;
          }else{
            var blackberry = "'"+blackberryurl+"'";
          }
        }
      	var windows = document.getElementById('windows_form').value;
        if(windows==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like Windows Mobile devices to be handled");
          document.theform.windows_form.focus();
          return;
        }
      	var palm = document.getElementById('palm_form').value;
        if(palm=='redirect'){
        	var palmurl = document.getElementById('palmurl').value;
          if(palmurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you ike to redirect Palm OS users?");
            document.theform.palmurl.focus();
            return;
          }else{
            var palm = "'"+palmurl+"'";
          }
        }
      	var windows = document.getElementById('windows_form').value;
        if(windows==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select how you would like Windows Mobile devices to be handled");
          document.theform.windows_form.focus();
          return;
        }
        if(windows=='redirect'){
        	var windowsurl = document.getElementById('windowsurl').value;
          if(windowsurl.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Where would you ike to redirect Windows Mobile users?");
            document.theform.windowsurl.focus();
            return;
          }else{
            var windows = "'"+windowsurl+"'";
          }
        }
      	var mobile_redirect = document.getElementById('mobile_redirect_form').value;
        if(mobile_redirect==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select where you would like mobile browsers to be redirected");
          document.theform.mobile_redirect_form.focus();
          return;
        }
        if(mobile_redirect=='true'){
        	var mobile_redirect = document.getElementById('mobile_redirect_url').value;
          if(mobile_redirect.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            document.theform.mobile_redirect_url.focus();
            alert("Where would you like to redirect mobile browsers to?");
            return;
          }else{
            var mobile_redirect = "'"+mobile_redirect+"'";
          }
        }
      	var desktop_redirect = document.getElementById('desktop_redirect_form').value;
        if(desktop_redirect==''){
          document.getElementById("generated_function").innerHTML = "" ;
          alert ("Please select where you would like desktop browsers to be redirected");
          document.theform.desktop_redirect_form.focus();
          return;
        }
        if(desktop_redirect=='true'){
        	var desktop_redirect = document.getElementById('desktop_redirect_url').value;
          if(desktop_redirect.length<10){
            document.getElementById("generated_function").innerHTML = "" ;
            alert("Please select the URL you would like desktop browsers to be redirected to");
            document.theform.desktop_redirect_url.focus();
            return;
          }else{
            var desktop_redirect = "'"+desktop_redirect+"'";
          }
        }
        document.getElementById("generated_function").innerHTML = "<h2>PHP Code<\/h2><p><b>Use this function to detect mobile handsets as set by the conditions above.<\/b><\/p><p><code>include('<a href='?dl' onclick='javascript:download(); return false;'>mobile_device_detect.php<\/a>');<br \/>mobile_device_detect("+iphone+","+android+","+opera+","+blackberry+","+palm+","+windows+","+mobile_redirect+","+desktop_redirect+");<\/code><\/p>" ;
      } // ends generate_function_call
      function iphone(option){
        if(option=='redirect'){
          document.getElementById("iphone").innerHTML = "<p>Where do you want iPhone users redirect to: <input type='text' name='iphoneurl' id='iphoneurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("iphone").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function android(option){
        if(option=='redirect'){
          document.getElementById("android").innerHTML = "<p>Where do you want Android users redirecting to: <input type='text' name='androidurl' id='androidurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("android").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function opera(option){
        if(option=='redirect'){
          document.getElementById("opera").innerHTML = "<p>Where do you want Opera Mini users redirecting to: <input type='text' name='operaurl' id='operaurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("opera").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function blackberry(option){
        if(option=='redirect'){
          document.getElementById("blackberry").innerHTML = "<p>Where do you want Blackberry users redirecting to: <input type='text' name='blackberryurl' id='blackberryurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("blackberry").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function palm(option){
        if(option=='redirect'){
          document.getElementById("palm").innerHTML = "<p>Where do you want Palm OS users redirecting to: <input type='text' name='palmurl' id='palmurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("palm").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function windows(option){
        if(option=='redirect'){
          document.getElementById("windows").innerHTML = "<p>Where do you want Windows Mobile users redirecting to: <input type='text' name='windowsurl' id='windowsurl' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("windows").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function mobile_redirect(option){
        if(option=='true'){
          document.getElementById("mobile_redirect").innerHTML = "<p>Where do you want mobile visitors redirecting to: <input type='text' name='mobile_redirect_url' id='mobile_redirect_url' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("mobile_redirect").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
      function desktop_redirect(option){
        if(option=='true'){
          document.getElementById("desktop_redirect").innerHTML = "<p>Where do you want desktop visitors redirecting to: <input type='text' name='desktop_redirect_url' id='desktop_redirect_url' value='http://'\/><\/p>" ;
        }else{
          document.getElementById("desktop_redirect").innerHTML = "<p>&nbsp;<\/p>" ;
        }
      }
        function externalLinks()
        {
            if (!document.getElementsByTagName) return;
            var anchors = document.getElementsByTagName("a");
            for ( var i=0; i < anchors.length; i++ )
            {
                var anchor = anchors[i];
                if ( anchor.getAttribute("href") && anchor.getAttribute("rel") == "external" )
                {
                    if ( anchor.getAttribute("className") )
                    {
                        anchor.target = anchor.getAttribute("className");
                    }
                    else
                    {
                        anchor.target = "_blank";
                    }
                }
            }
        }
