  function loadjscssfile(filename, filetype){
                 if (filetype=="js"){
                  var fileref=document.createElement('script');
                  fileref.setAttribute("type","text/javascript");
                  fileref.setAttribute("src", filename);
                 }
                 else if (filetype=="css"){ //if filename is an external CSS file
                  var fileref=document.createElement("link");
                  fileref.setAttribute("rel", "stylesheet");
                  fileref.setAttribute("type", "text/css");
                  fileref.setAttribute("href", filename);
                 }
                 if (typeof fileref!="undefined")
                  document.getElementsByTagName("head")[0].appendChild(fileref);
                }
               
               
 function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   if (sText=='') IsNumber=false;
   return IsNumber;
  
  }

  $(function() {
      loadjscssfile("scripts/thickbox.js", "js");
      loadjscssfile("design/thickbox.css", "css");

      if ($("#ctl00_pagecontent_chkFree").is(":checked")) { $("#divPrice").hide(); }

      $("#ctl00_pagecontent_chkPPC").click(function() {
          if ($("#ctl00_pagecontent_chkPPC").is(":checked"))
          { $("#ctl00_pagecontent_chkPPC").parent().prev().hide(); $("#ctl00_pagecontent_txtPPC").val(''); }
          else
          { $("#ctl00_pagecontent_chkPPC").parent().prev().show(); }
      });
      $("#ctl00_pagecontent_chkPPL").click(function() {
          if ($("#ctl00_pagecontent_chkPPL").is(":checked"))
          { $("#ctl00_pagecontent_chkPPL").parent().prev().hide(); $("#ctl00_pagecontent_txtPPL").val(''); }
          else
          { $("#ctl00_pagecontent_chkPPL").parent().prev().show(); }
      });
      $("#ctl00_pagecontent_chkPPS").click(function() {
          if ($("#ctl00_pagecontent_chkPPS").is(":checked"))
          { $("#ctl00_pagecontent_chkPPS").parent().prev().hide(); $("#ctl00_pagecontent_txtPPS").val(''); }
          else
          { $("#ctl00_pagecontent_chkPPS").parent().prev().show(); }
      });

      $("#chkLink").click(function() {
          if ($("#chkLink").is(":checked")) {
              $("#divLink").show();
          }
          else {
              $("#divLink").hide();
          }
      });

      /// Canceling postback on Enter press and making gray background for edited fields
      $(".inputvalues").bind('keypress', function trapEnter(event) {
          $(this).css('background-color', '#f0f0f0');
          var e = event ? event : window.event;
          var key = 0;
          if (e.keyCode) { key = e.keyCode; }
          else if (typeof (e.which) != 'undefined') { key = e.which; }
          if (key == 13) { return false; }
      });



      /// Form validation on click
      $("#ctl00_pagecontent_btnNext").bind('click', function(event) {

          var problems = '';
          //Name, Description is omitted.
          if ($("#ctl00_pagecontent_txtName").val().length < 5)
          { $("#ctl00_pagecontent_txtName").css('background-color', '#ffffcd'); problems = problems + '\n\rAffiliate program name not given.'; }
          else
          { $("#ctl00_pagecontent_txtName").css('background-color', '#f0f0f0'); }

          if ($("#ctl00_pagecontent_txtDesc").val().length < 5)
          { $("#ctl00_pagecontent_txtDesc").css('background-color', '#ffffcd'); problems = problems + '\n\rAffiliate program description not given.'; }
          else
          { $("#ctl00_pagecontent_txtDesc").css('background-color', '#f0f0f0'); }

          //rates
          if ((!$("#ctl00_pagecontent_chkPPC").is(":checked")) && ($("#ctl00_pagecontent_txtPPC").val() == ''))
          { $("#ctl00_pagecontent_txtPPC").css('background-color', '#ffffcd'); problems = problems + '\n\rPPC rates not filled in or not disabled.'; }
          if ((!$("#ctl00_pagecontent_chkPPL").is(":checked")) && ($("#ctl00_pagecontent_txtPPL").val() == ''))
          { $("#ctl00_pagecontent_txtPPL").css('background-color', '#ffffcd'); problems = problems + '\n\rPPL rates not filled in or not disabled.'; }
          if ((!$("#ctl00_pagecontent_chkPPS").is(":checked")) && ($("#ctl00_pagecontent_txtPPS").val() == ''))
          { $("#ctl00_pagecontent_txtPPS").css('background-color', '#ffffcd'); problems = problems + '\n\rPPS rates not filled in or not disabled.'; }

          //Cookie, payment, tracking,
          if ($("#ctl00_pagecontent_txtMinPayout").val().length < 2)
          { $("#ctl00_pagecontent_txtMinPayout").css('background-color', '#ffffcd'); problems = problems + '\n\rMinimal Payout not given.'; }
          else
          { $("#ctl00_pagecontent_txtMinPayout").css('background-color', '#f0f0f0'); }

          if ($("#ctl00_pagecontent_txtPayMethods").val().length < 5)
          { $("#ctl00_pagecontent_txtPayMethods").css('background-color', '#ffffcd'); problems = problems + '\n\rPayment methods not given.'; }
          else
          { $("#ctl00_pagecontent_txtPayMethods").css('background-color', '#f0f0f0'); }

          if ($("#ctl00_pagecontent_txtTracking").val().length < 5)
          { $("#ctl00_pagecontent_txtTracking").css('background-color', '#ffffcd'); problems = problems + '\n\rAffiliate tracking not given.'; }
          else
          { $("#ctl00_pagecontent_txtTracking").css('background-color', '#f0f0f0'); }

          if ($("#ctl00_pagecontent_txtCookie").val().length < 1)
          { $("#ctl00_pagecontent_txtCookie").css('background-color', '#ffffcd'); problems = problems + '\n\rCookie lifetime not given.'; }
          else
          { $("#ctl00_pagecontent_txtCookie").css('background-color', '#f0f0f0'); }
          
          //real time statistics not mentioned
          if ($("#lirealtime input[@type='radio']:checked").size() == 0)
          { $("#lirealtime input[@type='radio']").css('background-color', '#ffffcd'); problems = problems + '\n\rPlease mark weather you provide real time statistics or not.'; }
          else
          { $("#lirealtime input[@type='radio']").css('background-color', '#f0f0f0'); }

          //international not mentioned
          if ($("#liinternational input[@type='radio']:checked").size() == 0)
          { $("#liinternational input[@type='radio']").css('background-color', '#ffffcd'); problems = problems + '\n\rPlease mark weather you accept international affiliates.'; }
          else
          { $("#liinternational input[@type='radio']").css('background-color', '#f0f0f0'); }


          // Category not selected.
          if ($("#ctl00_pagecontent_lblSelectedCat").html() == '') { alert('please select a category for your item.'); return false; }

          if (problems != '')
          { alert('Can not submit Item. Please make the following corrections:\n\r' + problems); return false; }
          else {
              $("#ctl00_pagecontent_btnNext").attr('title', 'inaction');
              $("body").css('background-color', 'gray');
              $("#processing").css({ 'position': 'absolute', 'z-index': '999', 'font-size': '20px', 'line-height': '24px', 'color': 'black', 'border': '2px solid red', 'padding': '25px', 'background-color': '#f0f0f0', 'left': '30%', 'top': '100%' });
              $("#processing").show();
          }

      });
  })                                                  

