function setItemNumber(tabindex){
  document.purchase.item_name_1.value += ": "+(ParseInt(tabindex) * 10)+" users";
}
function Is_Valid_picture(fldHum,fldNum){
	var sendOBJ = new ajaxCall();
	sendOBJ.data = encodeURI("checkhuman="+fldHum.value+" & addquest="+fldNum.value);
	sendOBJ.url = "/4DAction/check_robot_picture";
	sendOBJ.method = 'POST';
	sendOBJ.responseArguments[0] = fldHum;
	sendOBJ.onResponse = ckpictcallback;
	sendOBJ.send();
}
function ckpictcallback(response,args){
	if(response != "OK"){
		var fldHum = args[0];
		fldHum.value = "";
		alert("Sorry. Please enter the correct number!");
	}
}
function validate_RPM_signup(frm){
	if(validate(frm,'user_FName','user_LName','user_addr','user_city','user_state','user_zip','user_email','ck_email')){
	  data = "divHolder=&prodname=debtReduction&pgname="+document.frmEditUser.pgname.value;
  	  url = "/4DAction/Web_NavProd";
	  window.location = url+"?"+data;
	  return true;
	  }
	else{
	  return false;
	}
	
}

function validate_RPM_login(frm){
	if(validate(frm,'LoginName','PWD')){
	  data = "divHolder=&prodname=debtReduction&pgname="+document.frmLogin.pgname.value;
  	  url = "/4DAction/Web_NavProd";
	  window.location = url+"?"+data;
	  return true;
	  }
	else{
	  return false;
	}
	
}

function validate_newAgent_RPM(frm){
	if(validate(frm,'user_FName','user_LName','user_addr','user_city','user_state','user_zip','user_email','ck_email')){
	  data = "taskname=RPM&amp;pgname="+frm.pgname.value;
  	  url = "/4DAction/Web_NavAgentTask";
	  window.location = url+"?"+data;
	  return true;
	  }
	else{
	  return false;
	}
	
}

function Validate_Uploadebook(frm){
  if(Is_Blank(frm.ct_name, 'Name', 'Please enter your name.')) return false;

  if(Is_Blank(frm.ct_email, 'Email Address', 'Please enter your email address.')) return false;
  else if(!Is_Email(frm.ct_email, 'Please enter valid email address.')) return false;

  if(Is_Blank(frm.ct_phone, 'Phone', 'Please enter your phone.')) return false;
  return true;
}

function validate_blast(frm){
  if(Is_Blank(frm.emailSubject, 'Subject', 'Please enter an Email Subject.')) return false;

  if(Is_Blank(frm.emailMsg, 'Message', 'Please enter your message.')) return false;
  return true;
}

function Is_Email(obj, msg){
  email = obj.value;
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!(!reg1.test(email) && reg2.test(email))){ alert(msg); obj.focus(); return false; }
  else return true;
}

function Is_Blank(obj, chk_val, msg){
  if(trim(obj.value) == chk_val){
    alert(msg);
    obj.focus();
    return true;
  } else if(obj.value.indexOf(chk_val)>-1){
    alert(msg);
    obj.focus();
	return true;
  }
  else return false;
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function validate(){
  //This function takes any number of args. The first is a form object
  //That contains the fields named in the other args.
  var form = arguments[0];
  var popup = false;
  var ret_val = false;
  for(i = 1;i < arguments.length;i++){
    var type = eval("form."+arguments[i]+".type");
    temp = eval("form."+arguments[i]+".style.backgroundColor='#FFFFFF';");
    if(type == "select" || type=="select-one"){
      var select = eval("form."+arguments[i]);
      var empty = select.options[select.selectedIndex].value=="";

    } else {
      var empty = eval("form."+arguments[i]+".value=='' || form."+arguments[i]+".value=='00/00/00' || form."+arguments[i]+".value=='0.00' || form."+arguments[i]+".value=='0.00%' || form."+arguments[i]+".value=='$0.00' || form."+arguments[i]+".value=='0'");
    }
    if(empty==true){
      temp = eval("form."+arguments[i]+".style.backgroundColor='#FFDD77';");
      popup = true;
    }
  }
  if(popup == true){
    alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
  } else {
    ret_val= true;
  }
  return ret_val;
}

function send_showhide_value(refno,clicked){
  data = "Refno="+escape(refno)+" & clicked="+escape(clicked.checked);
  url = "/4DAction/submitlist_On_Off";
  supported = send_ajax_post(url,data,true);
}

function send_HRshowhide_value(refno,clicked){
  data = "Refno="+escape(refno)+" & clicked="+escape(clicked.checked);
  url = "/4DAction/submitHR_On_Off";
  supported = send_ajax_post(url,data,true);
}

function print_submissionfaxcover(SubmitID){
  var win = window.open ("/4DAction/WEB_PrintSubmitCover?SubmitID="+SubmitID,'');
}

function print_debtfaxcover(SubmitID){
  var win = window.open ("/4DAction/WEB_PrintdebtCover?SubmitID="+SubmitID,'');
}

function review_debtResSubmit(SubmitID){
  var win = window.open ("/4DAction/WEB_ReviewDebtResEmail?SubmitID="+SubmitID,'');
}
function review_credsSubmit(RefNo){
  var win = window.open ("/4DAction/WEB_ReviewCredEmail?SubmitID="+RefNo,'');
}

function user_credsSubmit(PgNm){
  var win = window.open ("/4DAction/WEB_UserToCredForm?pagename="+PgNm,'');
}

function user_eBookDwnload(frm,PgNm){
  if(Validate_Uploadebook(frm)){
  var win = window.open ("/4DAction/WEB_eBookDnload?pagename="+PgNm+"&name="+frm.ct_name.value+"&email="+frm.ct_email.value+"&phone="+frm.ct_phone.value,'');
  }
}

function validate_pdf_up(){
  //This function makes sure they are uploading a PDF file
  var form = arguments[0];
  var popup = false;
  var ret_val = false;
  var myfilename = form.myFile;
    for(i = 1;i < arguments.length;i++){
    var type = eval("form."+arguments[i]+".type");
    temp = eval("form."+arguments[i]+".style.backgroundColor='#FFFFFF';");
    if(type == "select" || type=="select-one"){
      var select = eval("form."+arguments[i]);
      var empty = select.options[select.selectedIndex].value=="";

    } else {
      var empty = eval("form."+arguments[i]+".value=='' || form."+arguments[i]+".value=='00/00/00' || form."+arguments[i]+".value=='0.00' || form."+arguments[i]+".value=='0.00%' || form."+arguments[i]+".value=='$0.00' || form."+arguments[i]+".value=='0'");
    }
    if(empty==true){
      temp = eval("form."+arguments[i]+".style.backgroundColor='#FFDD77';");
      popup = true;
    }
  }
  if(popup == true){
    alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
  } else {
    if(myfilename.value.indexOf(".pdf") < 1){
      alert('Only PDF format accepted! Please scan your documents to a PDF file.');
      myfilename.value = "";
      ret_val = false;
    } else {
    ret_val= true;
    }
  }
  return ret_val;
}

function validate_deal_up(){
  var form = arguments[0];
  var popup = false;
  var ret_val = false;
  var myfilename = form.myFile;
    for(i = 1;i < arguments.length;i++){
    var type = eval("form."+arguments[i]+".type");
    temp = eval("form."+arguments[i]+".style.backgroundColor='#FFFFFF';");
    if(type == "select" || type=="select-one"){
      var select = eval("form."+arguments[i]);
      var empty = select.options[select.selectedIndex].value=="";

    } else {
      var empty = eval("form."+arguments[i]+".value=='' || form."+arguments[i]+".value=='00/00/00' || form."+arguments[i]+".value=='0.00' || form."+arguments[i]+".value=='0.00%' || form."+arguments[i]+".value=='$0.00' || form."+arguments[i]+".value=='0'");
    }
    if(empty==true){
      temp = eval("form."+arguments[i]+".style.backgroundColor='#FFDD77';");
      popup = true;
    }
  }

  if(popup == true){
    alert('One or more required fields were not filled in. Please check the highlighted field(s) for details.');
  } else {
    if(myfilename.value.indexOf(".pdf") < 1){
      alert('Only PDF format accepted! Please scan your document to a PDF file.');
      myfilename.value = "";
      ret_val = false;
    }else
    {ret_val= true;}

  }

  if(ret_val == true){
  var pymnt2 = document.getElementById('pymnt2');
  var pymntdue = document.getElementById('pymnt2Due');
    if((pymnt2.value > 0) & (pymntdue.value =='' || pymntdue.value =='00/00/00' || pymntdue.value =='0.00' || pymntdue.value =='0.00%' || pymntdue.value =='$0.00' || pymntdue.value =='0')){
    alert('You need to enter the due date for payment #2.');
    pymntdue.style.backgroundColor='#FFDD77';
    ret_val = false;
    }
    else{
      var pymnt3 = document.getElementById('pymnt3');
      var pymntdue = document.getElementById('pymnt3Due');
      if((pymnt3.value > 0) & (pymntdue.value =='' || pymntdue.value =='00/00/00' || pymntdue.value =='0.00' || pymntdue.value =='0.00%' || pymntdue.value =='$0.00' || pymntdue.value =='0')){
        alert('You need to enter the due date for payment #3.');
        pymntdue.style.backgroundColor='#FFDD77';
        ret_val = false;
        }
      }
    }

  if(document.getElementById('AppOK').checked & document.getElementById('LSOK').checked & document.getElementById('PymntOK').checked){
    //do nothing
  }
  else{
    alert('You need to explicity check off the CONFIRM! task list check boxes.');
    ret_val = false;
    }

  return ret_val;
}

function printTextArea(text){
  var div = document.getElementById('printDiv');
  div.innerHTML=text.replace(/\r\n/g,/<br \/>/);
  window.print();
}

function expand_div(div){
  document.getElementById(div).style.display='';
}

function collapse_div(div){
  document.getElementById(div).style.display='none';
}

function enablesecondfld(div) {
  if (document.frmSubmitQuery.searchCrit.value == "is between") {
    document.getElementById(div).style.display='';
  }
  else {
    document.getElementById(div).style.display='none';
    document.frmSubmitQuery.fieldVal2.value = '';
  }
}

function show_div_tab(div){
  var tabs = document.getElementById('topNavbar');
  var real_tabs = tabs.getElementsByTagName('a');
  var num_children = real_tabs.length;
  var related = "";
  for(i=0;i<num_children;i++){
    related = real_tabs[i].getAttribute('rel');
    if(related != div){
      real_tabs[i].className='';
      document.getElementById(related).style.display = 'none';

      if(document.getElementById('sub'+related)){
        document.getElementById('sub'+related).style.display = 'none';
      }
    }else if(related == div){
      real_tabs[i].className='active_link';
      document.getElementById(div).style.display ='';
      if(document.getElementById('sub'+related)){
        document.getElementById('sub'+related).style.display = '';
      }
    }
  }

}

function calcloanmod(){
  var modAmt = document.getElementById('modAmt');
  var analAmt = document.getElementById('analyzeAmt');
  var depAmt = document.getElementById('depAmt');
  var pymnt2 = document.getElementById('pymnt2');
  var pymnt3 = document.getElementById('pymnt3');
  var depAnalAmt = 0
  var depModAmt = 0
    if(document.getElementById('cbMod').checked){
    modAmt.value = "2750.00";
    depModAmt = 2750;
    }
    else{
    modAmt.value = "0.00";
    depModAmt = 0;
    pymnt2.value = 0;
    pymnt3.value = 0;
    }
    if(document.getElementById('cbAnal').checked){
    analAmt.value = "750.00";
    depAnalAmt = 750;
    }
    else{
    analAmt.value = "0.00";
    depAnalAmt = 0;
    pymnt2.value = 0;
    pymnt3.value = 0;
    }
  var modamount = parseFloat(modAmt.value);
  var analamount = parseFloat(analAmt.value);
    depAmt.value = depModAmt + depAnalAmt;
    pymnt2.value= (modamount + analamount) - (depModAmt + depAnalAmt);
    pymnt3.value = 0;

}

function calcshopcart(checkbox){
    switch (checkbox.name)
  {
    case "item1cb":
    if(checkbox.checked){
        document.frmShopcart.sc_item1qty.value = parseInt(document.frmShopcart.sc_item1qty.value) + 1;
      }else{
      document.frmShopcart.sc_item1qty.value = parseInt(document.frmShopcart.sc_item1qty.value) - 1;
    }
      break
    case "item2cb":
    if(checkbox.checked){
        document.frmShopcart.sc_item2qty.value = parseInt(document.frmShopcart.sc_item2qty.value) + 1;
      }else{
      document.frmShopcart.sc_item2qty.value = parseInt(document.frmShopcart.sc_item2qty.value) - 1;
    }
      break
    case "item3cb":
    if(checkbox.checked){
        document.frmShopcart.sc_item3qty.value = parseInt(document.frmShopcart.sc_item3qty.value) + 1;
      }else{
      document.frmShopcart.sc_item3qty.value = parseInt(document.frmShopcart.sc_item3qty.value) - 1;
    }
      break
    case "item4cb":
    if(checkbox.checked){
        document.frmShopcart.sc_item4qty.value = parseInt(document.frmShopcart.sc_item4qty.value) + 1;
      }else{
      document.frmShopcart.sc_item4qty.value = parseInt(document.frmShopcart.sc_item4qty.value) - 1;
    }
    break
    case "item5cb":
    if(checkbox.checked){
        document.frmShopcart.sc_item5qty.value = parseInt(document.frmShopcart.sc_item5qty.value) + 1;
      }else{
      document.frmShopcart.sc_item5qty.value = parseInt(document.frmShopcart.sc_item5qty.value) - 1;
    }
    break
  }
    getcarttotal()
}

function getcarttotal(){
  var item1amt = Math.round((document.frmShopcart.sc_item1qty.value * 15.99)*100)/100;
  var item2amt = Math.round((document.frmShopcart.sc_item2qty.value * 15.99)*100)/100;
  var item3amt = Math.round((document.frmShopcart.sc_item3qty.value * 15.99)*100)/100;
  var item4amt = Math.round((document.frmShopcart.sc_item4qty.value * 579)*100)/100;
  var item5amt = Math.round((document.frmShopcart.sc_item5qty.value * 1999)*100)/100;
  var totamt = Math.round((item1amt+item2amt+item3amt+item4amt+item5amt)*100)/100;

  document.frmShopcart.totalcartamt.value = totamt;

  var lineitems = "Item(s): "
  if(document.frmShopcart.sc_item1qty.value>0){
    lineitems += 'Guaranteed Millionaire@$15.99: ';
  }
  if(document.frmShopcart.sc_item2qty.value>0){
    lineitems += '1031 Exchange CD@$15.99: ';
  }
  if(document.frmShopcart.sc_item3qty.value>0){
    lineitems += 'Insurance Eval CD@$15.99: ';
  }
  if(document.frmShopcart.sc_item4qty.value>0){
    lineitems += 'Benefit and Savings Plans@$579.00: ';
  }
  if(document.frmShopcart.sc_item5qty.value>0){
    lineitems += 'Complete APW System@$1999.00';
  }

  document.frmEstateSubmit.amount.value = totamt;
  document.frmEstateSubmit.item_name.value = lineitems;
}

function zero_estate_cart(){
  document.frmShopcart.sc_item1qty.value = 0
  document.frmShopcart.sc_item2qty.value = 0
  document.frmShopcart.sc_item3qty.value = 0
  document.frmShopcart.sc_item4qty.value = 0
  document.frmShopcart.sc_item5qty.value = 0
  document.getElementById("item1cb").checked = false
  document.getElementById("item2cb").checked = false
  document.getElementById("item3cb").checked = false
  document.getElementById("item4cb").checked = false
  document.getElementById("item5cb").checked = false
}

function calcloandepamt(){
  var modAmt = document.getElementById('modAmt');
  var analAmt = document.getElementById('analyzeAmt');
  var depAmt = document.getElementById('depAmt');
  var pymnt2 = document.getElementById('pymnt2');
  var pymnt3 = document.getElementById('pymnt3');
  var modamount = parseFloat(modAmt.value);
  var analamount = parseFloat(analAmt.value);
  var depamount = parseFloat(depAmt.value);
    if((modamount + analamount) == 0){
    pymnt2.value = 0;
    depAmt.value = 0;
    pymnt3.value = 0;
    }
    else{
      if(depAmt.value == 0){
      depAmt.value = modamount + analamount;
      pymnt2.value = 0;
      pymnt3.value = 0;
      }
      else{
      pymnt2.value = (modamount + analamount) - depamount;
      pymnt3.value = 0;
      }
    }
  var pymntamount = parseFloat(pymnt2.value)
    if(pymntamount < 0){
    pymnt2.value = 0;
    depAmt.value = 0;
    pymnt3.value = 0;
    }
}

function calcloanpymnt2(){
  var modAmt = document.getElementById('modAmt');
  var analAmt = document.getElementById('analyzeAmt');
  var depAmt = document.getElementById('depAmt');
  var pymnt2 = document.getElementById('pymnt2');
  var pymnt3 = document.getElementById('pymnt3');
  var modamount = parseFloat(modAmt.value);
  var analamount = parseFloat(analAmt.value);
  var depamount = parseFloat(depAmt.value);
  var pymnt2amount = parseFloat(pymnt2.value);
    if(pymnt2.value == ''){
      pymnt2.value = 0;
      pymnt3.value = 0;
      depAmt = modamount + analamount;
    }
    if((modamount + analamount + pymnt2amount) == 0){
    pymnt2.value = 0;
    depAmt.value = 0;
    pymnt3.value = 0;
    }
    else{
      if(pymnt2amount == 0){
      pymnt3.value = 0;
      depAmt.value = modamount + analamount;
      }
      else{
      pymnt3.value = (modamount + analamount - depamount - pymnt2amount);
      }
    }

  var pymntamount = parseFloat(pymnt3.value)
    if(pymntamount < 0){
    pymnt2.value = 0;
    depAmt.value = 0;
    pymnt3.value = 0;
    }
}

function calcloanpymnt3(){
  var modAmt = document.getElementById('modAmt');
  var analAmt = document.getElementById('analyzeAmt');
  var depAmt = document.getElementById('depAmt');
  var pymnt2 = document.getElementById('pymnt2');
  var pymnt3 = document.getElementById('pymnt3');
  var modamount = parseFloat(modAmt.value);
  var analamount = parseFloat(analAmt.value);
  var depamount = parseFloat(depAmt.value);
  var pymnt2amount = parseFloat(pymnt2.value);
  var pymnt3amount = parseFloat(pymnt3.value);
    if(pymnt3amount == 0){
    pymnt3.value = 0;
    pymnt2.value = (modamount + analamount) - depamount;
    }
    else{
      if((modamount + analamount) != (depamount + pymnt2amount + pymnt3amount)){
      pymnt3.value = (modamount + analamount - depamount - pymnt2amount);
      }
    }
  var pymntamount = parseFloat(pymnt3.value)
    if(pymntamount < 0){
    pymnt2.value = 0;
    depAmt.value = 0;
    pymnt3.value = 0;
    }
}

function setEnabledOnLoad(){
  //this method will set disabled to true on the relevant fields
  // if the field is inactive
  var form = document.frmAgentEditUser;
  var elements = form.elements;
  var type="";
  for(i=0;i<elements.length;i++){
    type = elements[i].type;
    if(type != "hidden" && type != "radio" && type !="button"){
      elements[i].disabled = true;
    }
  }
}

function destroy_session(location){
      var today = new Date();
      var cookieExpires = today.toGMTString();
     document.cookie = "CS_cookie=~CS_cookieEND;path=/;expires="+cookieExpires+";;";
     window.location=location;
}

function SetClickNum(variable, value, formname){
  var form = document.getElementById(formname)
  eval('form.'+variable+'.value = '+value);
}

function writeYear(){
  var today = new Date();
  document.write(today.getFullYear().toString());
}

function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.tabindex) newObject.size = oldObject.tabindex;
  if(oldObject.maxlength) newObject.size = oldObject.maxlength;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}

Object.prototype.clone = function() {
  var newObj = (this instanceof Array) ? [] : {};
  for (i in this) {
    if (i == 'clone') continue;
    if (this[i] && typeof this[i] == "object") {
      newObj[i] = this[i].clone();
    } else newObj[i] = this[i]
  } return newObj;
};
