function focus_next(thisfield, nextfield) {
  if (document.getElementById(thisfield).value.length == 3) {
    document.getElementById(nextfield).value = "";
    document.getElementById(nextfield).focus();
  }
}

function required() {
  
  
  var form_names = new Array("state", "fname", "lname", "num_lines", "ac_prefix", "ac_first", "ac_last", "address", "city", "state", "email", "billing_preference");
  
  for (i = 0; i < form_names.length; i++) {
    if (curr = document.getElementById(form_names[i])) {
      if (!curr.value) {
        curr.focus();
        alert ("Required field is missing!");
        return false;
      }
      
    }
  }
  
  
  if (document.getElementById("billing_preference").value == "bill_credit") {
  
    var bill_credit_elems = new Array ("card_name", "card_billing_address", "card_type", "card_number", "card_month", "card_year", "card_verification", "drivers_license");
    for (i = 0; i < bill_credit_elems.length; i++) {
      if (curr = document.getElementById(bill_credit_elems[i])) {
        if (!curr.value) {
          curr.focus();
          alert ("Required field is missing!");
          return false;
        }
      }
    }
  }

  if (document.getElementById("billing_preference").value == "bill_mail") {
  
    var bill_mail_elems = new Array ("mail_name", "mail_ac_prefix", "mail_ac_first", "mail_ac_last", "mail_address", "mail_city", "mail_state", "mail_email");
    for (i = 0; i < bill_mail_elems.length; i++) {
      if (curr = document.getElementById(bill_mail_elems[i])) {
        if (!curr.value) {
          curr.focus();
          alert ("Required field is missing!");
          return false;
        }
      }
    }
  }
}


function valid_email(email, elem) {
  if (email) {
    //alert (email);
    curr = document.getElementById(elem);
    if (!email.match(/^\S+\@\S+\.\S+$/)) {
      alert("Invalid Email Address: " + email);
      curr.value = "";
      curr.focus();
    }
  }
}

function popup() {
popup = window.open("/chat/request.php?l=setup&x=1&deptid=0", "_blank", 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=350');
}



var buttons = new Array();


//ADD THE NAME_OF_BUTTON TO THIS ARRAY
var ids = new Array("about", "rates", "services", "ugiveback",
		"business_services", "residential_services",
		"long_distance_services", "toll_free_services",
		"conferencing_services", "calling_card_services",
		"charity_list", "ugiveback_faq",
		"voip_services", "order_management", 
		"email_management", "user_management","rates_management", 
		"logout");
//ADD THE NAME_OF_BUTTON TO THIS ARRAY





for (i = 0; i < ids.length; ++i) {
	buttons[ids[i]] = new Button(ids[i]);
}

function Button(id) {
	
	this.id = id;
	this.on = false;
	this.duration = .25;
	
	eval (this.id + '_off = new Image();');
	eval (this.id + '_off.src = "./images/' + this.id + '.jpg";');
	eval (this.id + '_on = new Image();');
	eval (this.id + '_on.src = "./images/' + this.id + '_on.jpg";');
	
	this.over = fadeOver;
	this.out = fadeOut;


}

function fadeOver() {
	if (! this.on) {
		eval ('document.getElementById("' + this.id + '").filters.blendTrans.apply ()');
		if (document.images) document.images[this.id].src = eval (this.id + '_on.src');
		eval ('document.getElementById("' + this.id + '").filters.blendTrans.play (this.duration)');
		this.on = true;
	}
}

function fadeOut() {
	
	eval ('document.getElementById("' + this.id + '").filters.blendTrans.apply ()');
	if (document.images) document.images[this.id].src = eval (this.id + '_off.src');
	eval ('document.getElementById("' + this.id + '").filters.blendTrans.play (this.duration)');
	this.on = false;
}





field_types_state = Array('2','3','4','5','btns');
field_replace_state = Array('<input type="text" size="3" name="domestic[]" value="{val}" maxlength="6">','<input type="text" size="3" name="domestic[]" value="{val}" maxlength="6">','<input type="text" size="3" name="tollfree[]" value="{val}" maxlength="6">','<input type="text" size="4" name="tollfree[]" value="{val}" maxlength="6">','<input type="submit" name="go" value="Update"> <input type="button" name="cancel" value="Cancel" onclick="swap_edit_state(\'{state}\');">');

field_types_country = Array('rate','btns');
field_replace_country = Array('<input type="text" size="3" name="rate" value="{val}" maxlength="4">','<input type="submit" name="go" value="Update"> <input type="button" name="cancel" value="Cancel" onclick="swap_edit_country(\'{country}\');">');

function swap_edit_state(st){
	for(i=0; i < field_types_state.length; i++){
		field = document.getElementById(st+'_'+field_types_state[i]);
		field2 = document.getElementById(st+'_'+field_types_state[i]+'_form');
		if(field.style.display == 'none'){
			field.style.display = 'inline';
			field2.innerHTML = '';
		}else{
			old_val = field.innerHTML;
			new_val = field_replace_state[i].replace('{val}', old_val);
			new_val = new_val.replace('{state}', st);
			field.style.display = 'none';
			do_replace = field2.innerHTML = new_val;
		}
	}
}

function verify_update_state(f,type){
	val = document.forms[f].val.value;
	if(val == ''){
		alert('You must enter a value (e.g. 0.0649)');
	}else{
		if(confirm('Are you sure you want to update all '+ type +' rates?')){
			document.forms[f].submit();
		}
	}
}

function swap_edit_country(c){
	for(i=0; i < field_types_country.length; i++){
		field = document.getElementById(c+'_'+field_types_country[i]);
		field2 = document.getElementById(c+'_'+field_types_country[i]+'_form');
		if(field.style.display == 'none'){
			field.style.display = 'inline';
			field2.innerHTML = '';
		}else{
			old_val = field.innerHTML;
			new_val = field_replace_country[i].replace('{val}', old_val);
			new_val = new_val.replace('{country}', c);
			field.style.display = 'none';
			do_replace = field2.innerHTML = new_val;
		}
	}
}