//report Upload Pin Numbers 10/10/09
function validate_file_excel(upload)
 {

   var userfile = upload.userfile.value;
 
  if(userfile == "") {
  inlineMsg('userfile','You must select File to Upload...',4);
  return false;
  }
   return true;
		
}


///

//report Upload Pin Numbers 10/10/09
function validate_file_excel_tra(upload)
 {
   var tra_det_club = upload.tra_det_club.value;
   var tra_date = upload.tra_date.value;
   var tra_place = upload.tra_place.value;
   var userfile = upload.userfile.value;
 if(tra_det_club == "") {
  inlineMsg('tra_det_club','You must select club...',4);
  return false;
  }
  if(tra_date == "") {
  inlineMsg('tra_date','You must select Date...',4);
  return false;
  }
  if(tra_place == "") {
  inlineMsg('tra_place','You must Enter Place...',4);
  return false;
  }
  if(userfile == "") {
  inlineMsg('userfile','You must select File to Upload...',4);
  return false;
  }
   return true;
		
}

//
function validate_week_exe(weekly_join_exe)
 {
  var from_exe = weekly_join_exe.from_exe.value;
  var to_exe = weekly_join_exe.to_exe.value;
  
  
  if(from_exe == "") {
  inlineMsg('jscal_trigger_Month1_exe','You must select from date...',4);
  return false;
  }
   if(to_exe == "") {
  inlineMsg('jscal_trigger_Month2_exe','You must select to date...',4);
  return false;
  }
  
   if(from_exe > to_exe) {
    inlineMsg('jscal_trigger_Month1_exe','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}



function validate_week_lead(weekly_join_lead)
 {
 
  var from_lead = weekly_join_lead.from_lead.value;
  var to_lead = weekly_join_lead.to_lead.value;
  
  
  if(from_lead == "") {
  inlineMsg('jscal_trigger_Month1_lead','You must select from date...',4);
  return false;
  }
   if(to_lead == "") {
  inlineMsg('jscal_trigger_Month2_lead','You must select to date...',4);
  return false;
  }
  
   if(from_lead > to_lead) {
    inlineMsg('jscal_trigger_Month1_lead','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}



function validate_week_train(weekly_join_train)
 {

  var from_train = weekly_join_train.from_train.value;
  var to_train = weekly_join_train.to_train.value;
  
  
  if(from_train == "") {
  inlineMsg('jscal_trigger_Month1_train','You must select from date...',4);
  return false;
  }
   if(to_train == "") {
  inlineMsg('jscal_trigger_Month2_train','You must select to date...',4);
  return false;
  }
  
   if(from_train > to_train) {
    inlineMsg('jscal_trigger_Month1_train','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}




function validate_week_holi(weekly_join_holi)
 {

  var from_holi = weekly_join_holi.from_holi.value;
  var to_holi = weekly_join_holi.to_holi.value;
  
  
  if(from_holi == "") {
  inlineMsg('jscal_trigger_Month1_holi','You must select from date...',4);
  return false;
  }
   if(to_holi == "") {
  inlineMsg('jscal_trigger_Month2_holi','You must select to date...',4);
  return false;
  }
  
   if(from_holi > to_holi) {
    inlineMsg('jscal_trigger_Month1_holi','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}
//

///


// form validation function //
	
function validate_country()
{
var country = document.user_register.country.value;
	
 if(country == "India")
     {
        document.user_register.state.disabled=false;
		document.user_register.district.disabled=false;
	 }
	 else
	 {
	    document.user_register.state.disabled=true;
		document.user_register.district.disabled=true;
	 }	 
}

//tree validation
function validate_go(go)
 {  
 var go_id = go.go_id.value;
   
   if((go_id=='VISION') || (go_id=='') || (go_id.length<6))
  {
  inlineMsg('go_id','You must enter user Track ID...',4);
  return false;
  }
    
   return true;
}

	
function validate_contact_us(feedback_add)
 {
  var feedback_name = feedback_add.feedback_name.value;
  var feedback_company = feedback_add.feedback_company.value;
  var feedback_email = feedback_add.feedback_email.value;
  var feedback_phonenumber = feedback_add.feedback_phonenumber.value;
  var feedback_btime = feedback_add.feedback_btime.value;
  var feedback_comment = feedback_add.feedback_comment.value;
  var numberRegex = /^[0-9]+/;
  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
   
  if(feedback_name == "") {
  inlineMsg('feedback_name','You must enter your name...',4);
  return false;
  }
  if(feedback_company == "") {
  inlineMsg('feedback_company','You must enter your company name...',4);
  return false;
  }
  if(feedback_email == "") {
  inlineMsg('feedback_email','You must enter your email id...',4);
  return false;
  }
  if(!feedback_email.match(emailRegex)) {
    inlineMsg('feedback_email','You have entered an invalid email.',2);
    return false;
  }
  if(feedback_phonenumber == "") {
  inlineMsg('feedback_phonenumber','You must enter your phone number...',4);
  return false;
  }
   if(!feedback_phonenumber.match(numberRegex)) {
    inlineMsg('feedback_phonenumber','You have entered an invalid phone number.',2);
    return false;
  }
  
  if(feedback_btime == "") {
  inlineMsg('feedback_btime','You must enter your free time...',4);
  return false;
  }
  if(feedback_comment == "") {
  inlineMsg('feedback_comment','Your feedback please ...',4);
  return false;
  }
    
   return true;
		
}

function validate_change_pass_admin(change_pass_common)
 {
  var current_pwd_common = change_pass_common.current_pwd_common.value;
  var new_pwd_common = change_pass_common.new_pwd_common.value;
  var confirm_pwd_common = change_pass_common.confirm_pwd_common.value;
  
   
  if(current_pwd_common == "") {
  inlineMsg('current_pwd_common','You must enter your current password...',4);
  return false;
  }
  if(new_pwd_common == "") {
  inlineMsg('new_pwd_common','You must enter your new password...',4);
  return false;
  }
  if(new_pwd_common.length < 6 ) {
    inlineMsg('new_pwd_common','<strong>Error</strong><br />Password length should be more than 6...',4);
    return false;
  }
  if(confirm_pwd_common == "") {
  inlineMsg('confirm_pwd_common','You must enter your password again id...',4);
  return false;
  }
  if(confirm_pwd_common != new_pwd_common) {
    inlineMsg('confirm_pwd_common','<strong>Error</strong><br />Password Mismatch',4);
    return false;
  }

  
    
   return true;
		
}



function validate_profile_st(profile_reports)
 {
  var user_id = profile_reports.user_id.value;
  
  if(user_id == "") {
  inlineMsg('user_id','You must select user...',4);
  return false;
  }
 
   return true;
		
}

function validate_club_st(club_reports)
 {
  var club_id = club_reports.club_id.value;
  
  if(club_id == "") {
  inlineMsg('club_id','You must select Club...',4);
  return false;
  }
 
   return true;
		
}


function validate_club_wise(club_wiser)
 {
  var club_idw = club_wiser.club_idw.value;
  
  if(club_idw == "") {
  inlineMsg('club_idw','You must select Club...',4);
  return false;
  }
 
   return true;
		
}

function validate_profile_member(mem_reports)
 {
  var user_id1 = mem_reports.user_id1.value;
  
  if(user_id1 == "") {
  inlineMsg('user_id1','You must select user...',4);
  return false;
  }
 
   return true;
		
}

function validate_week(weekly_join)
 {
  var from = weekly_join.from.value;
  var to = weekly_join.to.value;
  
  
  if(from == "") {
  inlineMsg('jscal_trigger_Month1','You must select from date...',4);
  return false;
  }
   if(to == "") {
  inlineMsg('jscal_trigger_Month2','You must select to date...',4);
  return false;
  }
  
   if(from > to) {
    inlineMsg('jscal_trigger_Month1','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}


function validate_week_pay(weekly_join)
 {
  var from = weekly_join.from.value;
  var to = weekly_join.to.value;
  
  
  if(from == "") {
  inlineMsg('jscal_trigger_Month1','You must select from date...',4);
  return false;
  }
   if(to == "") {
  inlineMsg('jscal_trigger_Month2','You must select to date...',4);
  return false;
  }
  
   if(from > to) {
    inlineMsg('jscal_trigger_Month1','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}


function validate_week_bank(weekly_pay)
 {
  var from_pay1 = weekly_pay.from_pay1.value;
  var to_pay1 = weekly_pay.to_pay1.value;
  
  
  if(from_pay1 == "") {
  inlineMsg('jscal_trigger_Month31','You must select from date...',4);
  return false;
  }
   if(to_pay1 == "") {
  inlineMsg('jscal_trigger_Month41','You must select to date...',4);
  return false;
  }
  
   if(from_pay1 > to_pay1) {
    inlineMsg('jscal_trigger_Month41','You Must Select From & To Date Correctly',4);
    return false;
  }
 
 
   return true;
		
}

//for registrations..................
function validate_registration(user_register)
 {
  var password1 = user_register.password1.value;
  var password2 = user_register.password2.value;
  var full_name = user_register.full_name.value;
  var address = user_register.address.value;
  var town = user_register.town.value;
  var country = user_register.country.value;
  var state = user_register.state.value;
  var district = user_register.district.value;
  var pin = user_register.pin.value;
  var passcode = user_register.passcode.value;
  var mobile = user_register.mobile.value;
  var father_id = user_register.father_id.value;
  var sponser_office = user_register.sponser_office.value;
  var position = user_register.position.value;
  var date_of_birth = user_register.date_of_birth.value;
  var nominee = user_register.nominee.value;
  var relation = user_register.relation.value;
  var agree = user_register.agree.checked;
   
  if(password1 == "") {
  inlineMsg('password1','You must enter your password...',4);
  return false;
  }
  
  if(password1.length < 6 ) {
    inlineMsg('password1','Password length should be more than 6...',4);
    return false;
  }
  if(password2 == "") {
  inlineMsg('password2','You must enter your password again...',4);
  return false;
  }
  if(password1 != password2) {
    inlineMsg('password2','<strong>Error</strong><br />Password Mismatch',4);
    return false;
  }
   if(full_name == "") {
  inlineMsg('full_name','You must enter your name here...',4);
  return false;
  }
  if(address == "") {
  inlineMsg('address','You must enter your address here...',4);
  return false;
  }

  if(town == "") {
  inlineMsg('town','You must enter your town here...',4);
  return false;
  }
  if(country == "") {
  inlineMsg('country','You must Select your country...',4);
  return false;
  }
  if(country == "India"){
  if(state == "") {
  inlineMsg('state','You must select state...',4);
  return false;
  }
  if(district == "") {
  inlineMsg('district','You must select district...',4);
  return false;
  }
  }
  if(pin == "") {
  inlineMsg('pin','You must enter pincode...',4);
  return false;
  }
  if(pin.length < 6 ) {
    inlineMsg('pin','Pincode length not correct...',4);
    return false;
  }
  if(passcode == "") {
  inlineMsg('passcode','You must enter your passcode here...',4);
  return false;
  }
  if(mobile == "") {
  inlineMsg('mobile','You must your mobile no...',4);
  return false;
  }
  if(mobile.length < 10 ) {
    inlineMsg('mobile','Mobile no length should be 10...',4);
    return false;
  }
  if(father_id == "") {
  inlineMsg('father_id','You must enter your sponser code...',4);
  return false;
  }
if(sponser_office == "") {
  inlineMsg('sponser_office','You must enter your sponser name...',4);
  return false;
  }
  if(position == "") {
  inlineMsg('position','You must select your position...',4);
  return false;
  }
  if(date_of_birth == "") {
  inlineMsg('jscal_trigger_Month1','You must enter your date of birth...',4);
  return false;
  }
  if(nominee == "") {
  inlineMsg('nominee','You must enter your nominee name...',4);
  return false;
  }
  if(relation == "") {
  inlineMsg('relation','You must enter relationship with nominee...',4);
  return false;
  }
  if(agree == false) {
  inlineMsg('agree','You must accept terms and conditions ...',4);
  return false;
  }




  
    
   return true;
		
}
//for registrations..................



function validate_password_user(change_pass_user)
 {
 
  var user_id_pass = change_pass_user.user_id_pass.value;
  var new_pwd_user = change_pass_user.new_pwd_user.value;
  var confirm_pwd_user = change_pass_user.confirm_pwd_user.value;
  
   
  if(user_id_pass == "") {
  inlineMsg('user_id_pass','You must select user...',4);
  return false;
  }
  if(new_pwd_user == "") {
  inlineMsg('new_pwd_user','You must enter your new password...',4);
  return false;
  }
  if(new_pwd_user.length < 6 ) {
    inlineMsg('new_pwd_user','<strong>Error</strong><br />Password length should be more than 6...',4);
    return false;
  }
  if(confirm_pwd_user == "") {
  inlineMsg('confirm_pwd_user','You must enter your password again id...',4);
  return false;
  }
  if(confirm_pwd_user != new_pwd_user) {
    inlineMsg('confirm_pwd_user','<strong>Error</strong><br />Password Mismatch',4);
    return false;
  }

    
   return true;
		
}




function validate_add_pin(insert_pin)
 {
 
  var pin_count = insert_pin.pin_count.value;
    var numberRegex = /^[0-9]+/;
  
   
  if(pin_count == "") {
  inlineMsg('pin_count','You must enter no of pinnumbers to add...',4);
  return false;
  }
  if(!pin_count.match(numberRegex)) {
    inlineMsg('pin_count','You have entered an invalid  number.',2);
    return false;
  }

    
   return true;
		
}

function validate_search_pin(pin_search)
 {
 
  var keyword = pin_search.keyword.value;
  if(keyword == "") {
  inlineMsg('keyword','You must pin Enter numbers to search...',4);
  return false;
  }
    return true;
		
}

function validate_activate(activate)
 {
 
  var passcode = activate.passcode.value;
  if(passcode == "") {
  inlineMsg('passcode','You must Enter pin numbers ...',4);
  return false;
  }
    return true;
		
}

function validate_tax(tax)
 {
 
  var tax_rate = tax.tax_rate.value;
  var service_charge = tax.service_charge.value;
   var dpair = tax.dpair.value;
    var epair = tax.epair.value;
	 var lpair = tax.lpair.value;
	  var tpair = tax.tpair.value;
	   var hpair = tax.hpair.value;
  var dream_pair_price = tax.dream_pair_price.value;
  var dream_ceiling = tax.dream_ceiling.value;
   var excel_pair_price = tax.excel_pair_price.value;
  var excel_ceiling = tax.excel_ceiling.value;
  var lead_pair_price = tax.lead_pair_price.value;
   var lead_ceiling = tax.lead_ceiling.value;
  var train_pair_price = tax.train_pair_price.value;
  var train_ceiling = tax.train_ceiling.value;
   var holi_pair_price = tax.holi_pair_price.value;
    var holi_ceiling = tax.holi_ceiling.value;
	   //var numberRegex = /^[0-9]+/;
  
   
  if(tax_rate == "") {
  inlineMsg('tax_rate','You must enter TDS Rate...',4);
  return false;
  }
  if(service_charge == "") {
  inlineMsg('service_charge','You must enter service charge...',4);
  return false;
  }
   if(dpair == "") {
  inlineMsg('dpair','You must enter Dreamers Pair ceiling...',4);
  return false;
  }
   if(epair == "") {
  inlineMsg('epair','You must enter  Executives Pair ceiling...',4);
  return false;
  }
   if(lpair == "") {
  inlineMsg('lpair','You must enter Leaders Pair ceiling...',4);
  return false;
  }
   if(tpair == "") {
  inlineMsg('tpair','You must enter Trainers Pair ceiling...',4);
  return false;
  }
   if(hpair == "") {
  inlineMsg('hpair','You must enter Holiday Pair ceiling...',4);
  return false;
  }
   if(dream_pair_price == "") {
  inlineMsg('dream_pair_price','You must enter dream club pair price...',4);
  return false;
  }
   if(dream_ceiling == "") {
  inlineMsg('dream_ceiling','You must enter dream club ceiling price...',4);
  return false;
  }
   if(excel_pair_price == "") {
  inlineMsg('excel_pair_price','You must enter Excel club pair price...',4);
  return false;
  }
   if(excel_ceiling == "") {
  inlineMsg('excel_ceiling','You must enter Excel club ceiling price...',4);
  return false;
  }
   if(lead_pair_price == "") {
  inlineMsg('lead_pair_price','You must enter Lead club pair price...',4);
  return false;
  }
   if(lead_ceiling == "") {
  inlineMsg('lead_ceiling','You must enter Lead club ceiling price...',4);
  return false;
  }
   if(train_pair_price == "") {
  inlineMsg('train_pair_price','You must enter Trainer club pairg price...',4);
  return false;
  }
   if(train_ceiling == "") {
  inlineMsg('train_ceiling','You must enter Trainer club ceiling price...',4);
  return false;
  }
   if(holi_pair_price == "") {
  inlineMsg('holi_pair_price','You must enter Holiday club pair price...',4);
  return false;
  }
   if(holi_ceiling == "") {
  inlineMsg('holi_ceiling','You must enter Holiday club ceiling price...',4);
  return false;
  }

    
   return true;
		
}

function startUpload()
{
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}


function stopUpload(success)

{
      var result = '';

      if (success == 1)
{

		alert('Successfully uploaded Image ..');
		document.location.href='mlm_index.php';

 }
  else {
      alert('Image Upload Failed..');
         result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      //document.getElementById('f1_upload_form').innerHTML = result + '<label>File: <input name="myfile" type="file" size="30" /><\/label><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>';
      document.getElementById('f1_upload_form').style.visibility = 'visible';
      return true;
}


function validate_gallery_add(gallery_add)
 {
 
  var myfile = gallery_add.myfile.value;
  var img_title = gallery_add.img_title.value;
  
    
  if(myfile == "") {
  inlineMsg('myfile','You must select a image...',4);
  return false;
  }
   if(img_title == "") {
  inlineMsg('img_title','You must enter image Title...',4);
  return false;
  }
      
   return true;
   startUpload();
		
}



function validate_newsupload(upload_news)
 {
 
  //var myfile = upload_news.myfile.value;
  var news_title = upload_news.news_title.value;
  var news_desc = upload_news.news_desc.value;
    
 // if(myfile == "") {
  //inlineMsg('myfile','You must select a image...',4);
  //return false;
 // }
   if(news_title == "") {
  inlineMsg('news_title','You must enter news Title...',4);
  return false;
  }
  if(news_desc == "") {
  inlineMsg('news_desc','You must enter news...',4);
  return false;
  }
      
   return true;
   //startUpload();
		
}

function validate_eventsupload(upload_events)
 {
 
  
  var news_title = upload_events.news_title.value;
    var date = upload_events.date.value;
	  var venue = upload_events.venue.value;
       var time = upload_events.time.value;
    
 
   if(news_title == "") {
  inlineMsg('news_title','You must enter Events Title...',4);
  return false;
  }
 if(date == "") {
  inlineMsg('jscal_trigger_Month1','You must select date...',4);
  return false;
  }
   if(venue == "") {
  inlineMsg('venue','You must enter Events venue...',4);
  return false;
  }
   if(time == "") {
  inlineMsg('time','You must enter Events time...',4);
  return false;
  }
      
   return true;
 		
}



function validate_week_pay(weekly_pay)
 {
  var from_pay = weekly_pay.from_pay.value;
  var to_pay = weekly_pay.to_pay.value;
  
  
  if(from_pay == "") {
  inlineMsg('jscal_trigger_Month3','You must select from date...',4);
  return false;
  }
   if(to_pay == "") {
  inlineMsg('jscal_trigger_Month4','You must select to date...',4);
  return false;
  }
  
   if(from_pay > to_pay) {
    inlineMsg('jscal_trigger_Month4','You Must Select From & To Date Correctly',4);
    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"; 
}