function SwitchPfields (v,count) {
  var x,i,elem;
  i=1;
  if (v == 1) i = 0;
  for (x=1;x<=count;x++) {
    elem = document.getElementById('p'+v+'item'+x);
    if (elem) elem.style.display='inline';
    elem = document.getElementById('p'+i+'item'+x);
    if (elem) elem.style.display='none';
  }
  elem = document.getElementById('p'+v+'head');
  if (elem) elem.style.display='inline';
  elem = document.getElementById('p'+i+'head');
  if (elem) elem.style.display='none';
}
function auto_state(frm) {
  if (frm.country.value != 0) {
    if (frm.country.value == '') {
      frm.state.options[0].selected=true;
      frm.state.disabled=false;
    } else {
      frm.state.options[1].selected=true;
      frm.state.disabled=true;
    }
    frm.state.options[1].disabled=false;
  } else {
    frm.state.options[0].selected=true;
    frm.state.disabled=false;
    frm.state.options[1].disabled=true;
  }
}

function validate_subscribe(frm) {
  var tmp;
  if (frm.firstname.value == '') {
    alert('Please enter your First Name.');
    return false;
  }
  tmp = frm.firstname.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 2 || tmp.lenght > 24 || tmp.match(/^[a-z\-]+$/i) == null) {
    alert('Your First Name must have 2-24 letters.');
    return false;
  }
  if (frm.lastname.value == '') {
    alert('Please enter your Last Name.');
    return false;
  }
  tmp = frm.lastname.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 2 || tmp.lenght > 24 || tmp.match(/^[a-z\-]+$/i) == null) {
    alert('Your Last Name must have 2-24 letters.');
    return false;
  }
  if (frm.email.value == '') {
    alert('Please enter your E-mail Address.');
    return false;
  }
  tmp = frm.email.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i) == null) {
    alert('Invalid E-Mail Address.');
    return false;
  }
  if (frm.remail.value == '') {
    alert('Please re-enter your E-Mail Address.');
    return false;
  }
  if (tmp != frm.remail.value.replace(/^\s*(.*?)\s*$/,"$1")) {
    alert('E-Mail Addresses does not match.');
    return false;
  }
  if (frm.phone.value == '') {
    alert('Please enter your Phone Number.');
    return false;
  }
  tmp = frm.phone.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.match(/^[0-9\-\.\(\)\s]+$/) == null || tmp.length < 6) {
    alert('Invalid Phone Number.');
    return false;
  }
  if (frm.country.value == '') {
    alert('Please select your Country.');
    return false;
  }
  if (frm.city.value == '') {
    alert('Please enter your City.');
    return false;
  }
  tmp = frm.city.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.match(/^[a-z\-\.\s]+$/i) == null || tmp.length < 3) {
    alert('Invalid City Name.');
    return false;
  }
  if (frm.state.value == '') {
    alert('Please select your State.');
    return false;
  }
  if (frm.zip.value == '') {
    alert('Please enter your Zip Code.');
    return false;
  }
  tmp = frm.zip.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 3 || tmp.length > 18) {
    alert('Invalid Zip Code.');
    return false;
  }
  if (frm.reference.value == '') {
    alert('Please select how did you hear about us.');
    return false;
  }
  if (frm.username.value == '') {
    alert('Please choose your Username.');
    return false;
  }
  tmp = frm.username.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 4 || tmp.lenght > 10 || tmp.match(/^[a-z0-9]+$/i) == null) {
    alert('Username must be 4-10 alphanumeric characters.');
    return false;
  }
	
  if (frm.password.value == '') {
    alert('Please choose your Password.');
    return false;
  }
  if (frm.password.value.length < 6 || frm.password.value.lenght > 16) {
    alert('Password must be 6-16 characters.');
    return false;
  }
  if (frm.rpassword.value == '') {
    alert('Please re-enter your Password.');
    return false;
  }
  if (frm.rpassword.value != frm.password.value) {
    alert('Passwords does not match.');
    return false;
  }
}



function validate_subscribe_free(frm) {
  var tmp;
  if (frm.firstname.value == '') {
    alert('Please enter your First Name.');
    return false;
  }
  tmp = frm.firstname.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 2 || tmp.lenght > 24 || tmp.match(/^[a-z\-]+$/i) == null) {
    alert('Your First Name must have 2-24 letters.');
    return false;
  }
  if (frm.lastname.value == '') {
    alert('Please enter your Last Name.');
    return false;
  }
  tmp = frm.lastname.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 2 || tmp.lenght > 24 || tmp.match(/^[a-z\-]+$/i) == null) {
    alert('Your Last Name must have 2-24 letters.');
    return false;
  }
  if (frm.email.value == '') {
    alert('Please enter your E-mail Address.');
    return false;
  }
  tmp = frm.email.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i) == null) {
    alert('Invalid E-Mail Address.');
    return false;
  }
  if (frm.reference.value == '') {
    alert('Please select how did you hear about us.');
    return false;
  }
  if (frm.username.value == '') {
    alert('Please choose your Username.');
    return false;
  }
  tmp = frm.username.value.replace(/^\s*(.*?)\s*$/,"$1");
  if (tmp.length < 4 || tmp.lenght > 10 || tmp.match(/^[a-z0-9]+$/i) == null) {
    alert('Username must be 4-10 alphanumeric characters.');
    return false;
  }
	
  if (frm.password.value == '') {
    alert('Please choose your Password.');
    return false;
  }
  if (frm.password.value.length < 6 || frm.password.value.lenght > 16) {
    alert('Password must be 6-16 characters.');
    return false;
  }
  if (frm.rpassword.value == '') {
    alert('Please re-enter your Password.');
    return false;
  }
  if (frm.rpassword.value != frm.password.value) {
    alert('Passwords does not match.');
    return false;
  }
}


function chkUser(uname){
	var xmlhttp;
                if (window.XMLHttpRequest)
                  {
                  // code for IE7+, Firefox, Chrome, Opera, Safari
                          xmlhttp=new XMLHttpRequest();
                  }
                else if (window.ActiveXObject)
                  {
                  // code for IE6, IE5
                          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                else
                  {
                          alert("Your browser does not support XMLHTTP!");
                  }
                xmlhttp.onreadystatechange=function()
                {
                        if(xmlhttp.readyState != 4)
                                {
                                        document.getElementById('waitstate').style.display = "block";
                            }
                        if(xmlhttp.readyState==4)
                                  {
                                        document.getElementById('waitstate').style.display = "none";
					if(xmlhttp.responseText == 'less'){
                                                document.getElementById('divid').innerHTML = "<div style='color:red'><b>Username should be atleast 4 characters</b></div>";
                                        }
					if(xmlhttp.responseText == 'yes'){
						document.getElementById('divid').innerHTML = "<div style='color:red'><b>Username already exists</b></div>";
					}
					if(xmlhttp.responseText == 'no') {
	                                        document.getElementById('divid').innerHTML = "<div style='color:green'><b>Username available</b></div>";
					}
                                  }
                }
                var url = "../commonfiles/ajax/userTest.php";
                url = url+"?username="+uname;
                xmlhttp.open("GET",url,true);
                xmlhttp.send(null);
}


function validate_subscribe2(frm,sw) {
  var tmp;
  if (sw == 1) {
    if (frm.firstName.value == '') {
      alert('Please enter first name on the card.');
      return false;
    } 
    if (frm.lastName.value == '') {
      alert('Please enter last name on the card.');
      return false;
    }
    if (frm.ccnumber.value == '') {
      alert('Please enter Credit Card Number.');
      return false; 
    }
    tmp = frm.ccnumber.value.replace(/[\s\-]/g,'');
    if (tmp.match(/^[0-9]{15,16}$/) == null) {
      alert('Invalid Credit Card Number.');
      return false;
    }
    if (frm.ccmonth.value == '' || frm.ccyear.value == '') {
      alert('Please select Credit Card Expiration Date.');
      return false;
    }
    if (frm.cvv.value == '') {
      alert('Please enter Card Verification Code.');
      return false; 
    }
    tmp = frm.cvv.value.replace(/\s/g,'');
    if (tmp.match(/^[0-9]{3,4}$/) == null) {
      alert('Invalid Card Verification Code.');
      return false;
    }
    if (frm.address1.value == '') {
      alert('Please enter billing address.');
      return false;
    }
    if (frm.city.value == '') {
      alert('Please enter city.');
      return false;
    }
    if (frm.country.value == '') {
      alert('Please enter country.');
      return false;
    }
    if (frm.state.value == '') {
      alert('Please enter state.');
      return false;
    }
    if (frm.bzip.value == '') {
      alert('Please enter Billing zip code.');
      return false; 
    }
  }
}



function validate_subscribe3(frm,sw) {
  var tmp;
  if (sw == 1) {
    if (frm.email.value == '') {
        alert('Please enter your E-mail Address.');
            return false;
     }

    tmp = frm.email.value.replace(/^\s*(.*?)\s*$/,"$1");

    if (tmp.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/i) == null) {
          alert('Invalid E-Mail Address.');
            return false;
    }
    if (frm.firstName.value == '') {
      alert('Please enter first name on the card.');
      return false;
    }
    if (frm.lastName.value == '') {
      alert('Please enter last name on the card.');
      return false;
    }
    if (frm.ccnumber.value == '') {
      alert('Please enter Credit Card Number.');
      return false;
    }
    tmp = frm.ccnumber.value.replace(/[\s\-]/g,'');
    if (tmp.match(/^[0-9]{15,16}$/) == null) {
      alert('Invalid Credit Card Number.');
      return false;
    }
    if (frm.ccmonth.value == '' || frm.ccyear.value == '') {
      alert('Please select Credit Card Expiration Date.');
      return false;
    }
    if (frm.cvv.value == '') {
      alert('Please enter Card Verification Code.');
      return false;
    }
    tmp = frm.cvv.value.replace(/\s/g,'');
    if (tmp.match(/^[0-9]{3,4}$/) == null) {
      alert('Invalid Card Verification Code.');
      return false;
    }
    if (frm.address1.value == '') {
      alert('Please enter billing address.');
      return false;
    }
    if (frm.city.value == '') {
      alert('Please enter city.');
      return false;
    }
    if (frm.country.value == '') {
      alert('Please enter country.');
      return false;
    }
    if (frm.state.value == '') {
      alert('Please enter state.');
      return false;
    }
    if (frm.bzip.value == '') {
      alert('Please enter Billing zip code.');
      return false;
    }
  }
}

//Pay Pal Functions start here

function generateCC(){
                var cc_number = new Array(16);
                var cc_len = 16;
                var start = 0;
                var rand_number = Math.random();

                switch(document.confirm.ctype.value)
        {
                        case "Visa":
                                cc_number[start++] = 4;
                                break;
                        case "Discover":
                                cc_number[start++] = 6;
                                cc_number[start++] = 0;
                                cc_number[start++] = 1;
                                cc_number[start++] = 1;
                                break;
                        case "MasterCard":
                                cc_number[start++] = 5;
                                cc_number[start++] = Math.floor(Math.random() * 5) + 1;
                                break;
                        case "Amex":
                                cc_number[start++] = 3;
                                cc_number[start++] = Math.round(Math.random()) ? 7 : 4 ;
                                cc_len = 15;
                                break;
        }

        for (var i = start; i < (cc_len - 1); i++) {
                        cc_number[i] = Math.floor(Math.random() * 10);
        }

                var sum = 0;
                for (var j = 0; j < (cc_len - 1); j++) {
                        var digit = cc_number[j];
                        if ((j & 1) == (cc_len & 1)) digit *= 2;
                        if (digit > 9) digit -= 9;
                        sum += digit;
                }

                var check_digit = new Array(0, 9, 8, 7, 6, 5, 4, 3, 2, 1);
                cc_number[cc_len - 1] = check_digit[sum % 10];

                document.confirm.ccnumber.value = "";
                for (var k = 0; k < cc_len; k++) {
                        document.confirm.ccnumber.value += cc_number[k];
                }
        }




//Hide Show a div on MouseOver and MouseOut

function ShowDivOnMouseOver(txt){
	document.getElementById('def').style.display = 'block';
	if(txt=="value"){
		document.getElementById('def1').innerHTML = "Sabrient Value Score";
		document.getElementById('def2').innerHTML = "The Sabrient Value Score measures the relationship between a company's stock price and its intrinsic value, as indicated by earnings and balance sheet attributes, with an emphasis on earnings. Also considered are cash flow measures and fundamental valuation ratios. The higher the score, the more undervalued the stock.";
	}
	else if(txt=="growth"){
		document.getElementById('def1').innerHTML = "Sabrient Growth Score";
		document.getElementById('def2').innerHTML = "The Sabrient Growth Score reflects a company's historical and projected earnings growth, revenue and sales growth, projected cash flow, analyst activity, and changes in earnings estimates, each over various time periods. The higher the score, the better the combined performance of these key measures.";
	}
	else{
		document.getElementById('def1').innerHTML = "Sabrient Momentum Score";
                document.getElementById('def2').innerHTML = "The Sabrient Momentum Score measures a company's earnings and price momentum, evenly weighted, and augmented by group strength, money flow, and relative volume. Core technical factors include current price relative to periodic highs and moving averages. The higher the score, the stronger the combined price and earnings momentum.";
	}
}

function ShowDivOnMouseOut(){
        document.getElementById('def').style.display = 'none';
}


