function hideDiv()
{
  var tableRow = document.getElementById('country_div');
   tableRow.style.display = 'none';

   var tableRow1 = document.getElementById('state_div');
   tableRow1.style.display = 'none';

}
function createCountryField(f)
{
if(f.value=='Other')
{
   document.getElementById("state_div").innerHTML="";
var html="<td><b>Other Country</b></td>";
html=html+"<td><input type='text' name='county_other'id='county_other' value=''  autocomplete='Off' size='22' > </td>";
document.getElementById("country_div").innerHTML=html;
}
else
    if(f.value=='India')
        {
       document.getElementById("country_div").innerHTML="";
       createStateField();
        }
else
    {
        document.getElementById("country_div").innerHTML="";
          document.getElementById("state_div").innerHTML="";
  
    }
}

function createStateField()
{
getState();

}




function trim(a)
	{

	  return a.replace(/^\s+|\s+$/,'');
	}

function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{
			try{
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}

		return xmlhttp;
    }

	function getState()
        {
	   var strURL="InfiniteMLM/ajax/findState.php";
		var req = getXMLHTTP();

		if (req) {

			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
                                            
						document.getElementById('state_div').innerHTML=trim(req.responseText);
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}
			}
			req.open("GET", strURL, true);
			//alert(strURL);
			req.send(null);
		}
	}











//validate registration..............
function validate_register(register_form)
{

var numberRegex = /^[0-9]+/;
var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

var username = register_form.username.value;
var password = register_form.password.value;
var cpassword = register_form.cpassword.value;
var company = register_form.company.value;
var fullname = register_form.fullname.value;
var phone = register_form.phone.value;
var email = register_form.email.value;
var country = register_form.country.value;
var location = register_form.location.value;
var mlm_plan = register_form.mlm_plan.value;
var other_country="";
var state="";


if(country == "Other")
{
 other_country=register_form.county_other.value;
   }
if(country == "India")
	{
 state=register_form.india_state.value;
	}

//alert(other_country);

 if(username == "")
   {
  
  inlineMsg('username','You must enter your  User name...',4);
  return false;
  }
    
if(password == "")
   {
  
  inlineMsg('password','You must enter your Password...',4);
  return false;
  }
 
 if(cpassword == "")
   {
  inlineMsg('cpassword','You must enter your Confirm Password...',4);
  return false;
  
  }if(password!=cpassword)
  {
  
   inlineMsg('cpassword','Password is Incorrect...',4);
	     return false;
	}
	
	      
	if(company=="")
 {
 inlineMsg('company','Please enter your Company Name...',4);
 return false;
 }
 
 if(fullname=="")
 {
 inlineMsg('fullname','Please specify your Full Name...',4);
 return false;
 }
 
 if(phone=="")
 {
 inlineMsg('phone','Please enter your Phone number...',4);
 return false;
 }
   if(!phone.match(numberRegex)) {
    inlineMsg('phone','You have entered an invalid Phone number.');
   return false;
 }
 
 
  if(email=="")
 {
 inlineMsg('email','Please enter your email address...',4);
 return false;
 }
  if(!email.match(emailRegex)) {
    inlineMsg('email','You have entered an invalid email.');
   return false;
 }
 if(country == "")
   {
  inlineMsg('country','You must Select your Country...',4);
  return false;
   }
   if(country == "Other")
       {
         if(other_country == "")
             {

   inlineMsg('county_other','You must Enter other Country Name...',4);
  return false;
             }
       }
    if(country == "India")
    {
   if(state == "")
       {
    inlineMsg('india_state','Please Type Your state Here ...',4);
   return false;
       }

  }
  if(location == "")
   {
  inlineMsg('location','You must enter your Location...',4);
  return false;
  }
  if(mlm_plan == "")
   {
  inlineMsg('mlm_plan','You must Select MLM plan...',4);
  return false;
  }
  
  
 return true;
		
}

// form validation function //
function validate(contact) {

  var txtname = contact.txtname.value;
  var txtemail=contact.txtemail.value;
  var txtmobile=contact.txtmobile.value;
  var txtservice=contact.txtservice.value; 
  var numberRegex = /^[0-9]+/;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  

 
  if(txtname== "")
  {
   
    inlineMsg('txtname','<strong>Error</strong><br />You must Enter your Name.',4);
    return false;
  }
  
  if(txtemail== "")
  {
    inlineMsg('txtemail','<strong>Error</strong><br />You must Enter your E-mail id.',4);
    return false;
  }
    if(!txtemail.match(emailRegex))
	{
    inlineMsg('txtemail','<strong>Error</strong><br />You have entered an invalid email.',4);
    return false;
  }
  if(txtmobile=="")
  {
    inlineMsg('txtmobile','<strong>Error</strong><br />You must enter Your phone number.',4);
    return false;
  }
 
     
      if(txtservice== "")
  {
    inlineMsg('txtservice','<strong>Error</strong><br />You must Type Service.',4);
    return false;
  }
 
  return true;
}






// form validation select plan //
function validate_select_plan_binary(select_plan) {

 
    var product = select_plan.product[0].checked;
	 
    var product1 = select_plan.product[1].checked;
	
	  var passcod = select_plan.passcod[0].checked;
	  
      var passcod1 = select_plan.passcod[1].checked;
	  
	  var  payout = select_plan.payout.value;
	  var  captcha = select_plan.captcha.value;
	  var  pair = select_plan.pair.value;
	   


	   if(payout=='week')
	  {
	  
	  var  week_start = select_plan.week_start.value;
	
	  }
	  
	   
 
      if(product== false && product1 == false)
      {
    inlineMsg('product','<strong>Error</strong><br />You must select one',4);
    return false;
  }
    if(passcod== false && passcod1 == false)
      {
    inlineMsg('passcod','<strong>Error</strong><br />You must select one',4);
    return false;
  }
   if(payout == '')
      {
    inlineMsg('payout','<strong>Error</strong><br />You must select payout release',4);
    return false;
  }
  
  

	
	
    if(payout=='week')
	  {
	   if(week_start == '')
      {
    inlineMsg('week_start','<strong>Error</strong><br />You must select starting date',4);
    return false;
  }
	  }
	  if(pair == '')
      {
    inlineMsg('pair','<strong>Error</strong><br />You must select pair scheme',4);
    return false;
  }
  
   if(captcha == '')
      {
    inlineMsg('captcha-form','<strong>Error</strong><br />You must enter validation code',4);
    return false;
  }
  

 
  return true;
}


function validate_select_plan_matrix(select_plan) {

	var numberRegex = /^[0-9]+/;
    var product = select_plan.product[0].checked;
	 
    var product1 = select_plan.product[1].checked;
	
	  var passcod = select_plan.passcod[0].checked;
	  
      var passcod1 = select_plan.passcod[1].checked;
	  
	  var  payout = select_plan.payout.value;
	  var  captcha = select_plan.captcha.value;
	  var  width_cieling = select_plan.width_cieling.value;
	  var  depth_cieling = select_plan.depth_cieling.value;
	   


	   if(payout=='week')
	  {
	  
	  var  week_start = select_plan.week_start.value;
	
	  }
	  
	   
 
      if(product== false && product1 == false)
      {
    inlineMsg('product','<strong>Error</strong><br />You must select one',2);
    return false;
  }
    if(passcod== false && passcod1 == false)
      {
    inlineMsg('passcod','<strong>Error</strong><br />You must select one',2);
    return false;
  }
   if(payout == '')
      {
    inlineMsg('payout','<strong>Error</strong><br />You must select payout release',4);
    return false;
  }
  
  

	
	
    if(payout=='week')
	  {
	   if(week_start == '')
      {
    inlineMsg('week_start','<strong>Error</strong><br />You must select starting date',4);
    return false;
  }
	  }
	  
	  
	  if(width_cieling == '')
      {
    inlineMsg('width_cieling','<strong>Error</strong><br />You must Enter width ceiling',4);
    return false;
  }
  
   if((!width_cieling.match(numberRegex)) || (width_cieling == 0))
      {
    inlineMsg('width_cieling','<strong>Error</strong><br />Width ceiling must be a Non zero Number',4);
    return false;
  }
  
  if(depth_cieling == '' )
      {
    inlineMsg('depth_cieling','<strong>Error</strong><br />You must enter depth ceiling',4);
    return false;
  }
  
   if((!depth_cieling.match(numberRegex)) || (depth_cieling == 0))
      {
    inlineMsg('depth_cieling','<strong>Error</strong><br />Depth ceiling must be a Non zero Number',4);
    return false;
  }

   if(captcha == '')
      {
    inlineMsg('captcha-form','<strong>Error</strong><br />You must enter validation code',4);
    return false;
  }
  

 
  return true;
}



function validate_select_plan_unilevel(select_plan) {


	var numberRegex = /^[0-9]+/;
    var product = select_plan.product[0].checked;
	 
    var product1 = select_plan.product[1].checked;
	
	  var passcod = select_plan.passcod[0].checked;
	  
      var passcod1 = select_plan.passcod[1].checked;
	  
	  var  payout = select_plan.payout.value;
	  var  captcha = select_plan.captcha.value;
	  
	  var  depth_cieling = select_plan.depth_cieling.value;
	   


	   if(payout=='week')
	  {
	  
	  var  week_start = select_plan.week_start.value;
	
	  }
	  
	   
 
      if(product== false && product1 == false)
      {
    inlineMsg('product','<strong>Error</strong><br />You must select one',2);
    return false;
  }
    if(passcod== false && passcod1 == false)
      {
    inlineMsg('passcod','<strong>Error</strong><br />You must select one',2);
    return false;
  }
   if(payout == '')
      {
    inlineMsg('payout','<strong>Error</strong><br />You must select payout release',4);
    return false;
  }
  
  

	
	
    if(payout=='week')
	  {
	   if(week_start == '')
      {
    inlineMsg('week_start','<strong>Error</strong><br />You must select starting date',4);
    return false;
  }
	  }
	  
	  
	  
  
  if(depth_cieling == '')
      {
    inlineMsg('depth_cieling','<strong>Error</strong><br />You must enter depth ceiling',4);
    return false;
  }
  
   if((!depth_cieling.match(numberRegex)) || (depth_cieling == 0))
      {
    inlineMsg('depth_cieling','<strong>Error</strong><br />Depth ceiling must be a Non zero Number',4);
    return false;
  }

   if(captcha == '')
      {
    inlineMsg('captcha-form','<strong>Error</strong><br />You must enter validation code',4);
    return false;
  }
  

 
  return true;
}






// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}



function hidediv() 
{

setHieght();
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideShow').style.visibility = 'hidden';
}
else
 {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'hidden';
}
else { // IE 4
document.all.hideShow.style.visibility = 'hidden';
}
}

setHieght();
} 

function  setHieght()
{

document.getElementById('hideShow').style.height="0px";
document.getElementById("hideShow").height = "0px";

}



function validateQuote(contact) {




  var txtname = contact.txtname.value;
  var txtemail=contact.txtemail.value;
  var txtmobile=contact.txtmobile.value;
  var txtservice=contact.txtservice.value; 

  
   var numberRegex = /^[0-9]+/;
  var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  

 
  if(txtname== "")
  {
   
    inlineMsg('txtname','<strong>Error</strong><br />You must Enter your Name.',2);
    return false;
  }
  
  if(txtemail== "")
  {
    inlineMsg('txtemail','<strong>Error</strong><br />You must Enter your E-mail id.',2);
    return false;
  }
    if(!txtemail.match(emailRegex))
	{
    inlineMsg('txtemail','<strong>Error</strong><br />You have entered an invalid email.',2);
    return false;
  }
  if(txtmobile=="")
  {
    inlineMsg('txtmobile','<strong>Error</strong><br />You must enter Your phone number.',2);
    return false;
  }
   if(!txtmobile.match(numberRegex)) {
    inlineMsg('txtmobile','<strong>Error</strong><br />You have entered an invalid Phone number.');
   return false;
 }
 if(txtservice== "")
  {
    inlineMsg('txtservice','<strong>Error</strong><br />You must Type Service.',2);
    return false;
  }
 
  return true;
}

// START OF MESSAGE SCRIPT //


var MSGTIMER = 20;
var MSGSPEED = 10;
var MSGOFFSET = 10;
var MSGHIDE = 100;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) 
{
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}

