// Netscape 3.0 compatibility test (for javascript image swapping)
compat = false;
if( parseInt( navigator.appVersion ) >= 3 ) { compat = true; }
// cache images for quick swapping
if( compat )
{

		mm_about_on = new Image;
		mm_about_on.src = ("/fc_images/mm_about_on.png");
		mm_about_off = new Image;
		mm_about_off.src = ("/fc_images/mm_about_off.png");

		mm_products_on = new Image;
		mm_products_on.src = ("/fc_images/mm_products_on.png");
		mm_products_off = new Image;
		mm_products_off.src = ("/fc_images/mm_products_off.png");

		mm_support_on = new Image;
		mm_support_on.src = ("/fc_images/mm_support_on.png");
		mm_support_off = new Image;
		mm_support_off.src = ("/fc_images/mm_support_off.png");

		mm_download_on = new Image;
		mm_download_on.src = ("/fc_images/mm_download_on.png");
		mm_download_off = new Image;
		mm_download_off.src = ("/fc_images/mm_download_off.png");

		mm_buynow_on = new Image;
		mm_buynow_on.src = ("/fc_images/mm_buynow_on.png");
		mm_buynow_off = new Image;
		mm_buynow_off.src = ("/fc_images/mm_buynow_off.png");

		mm_login_on = new Image;
		mm_login_on.src = ("/fc_images/mm_login_on.png");
		mm_login_off = new Image;
		mm_login_off.src = ("/fc_images/mm_login_off.png");

		mm_logout_on = new Image;
		mm_logout_on.src = ("/fc_images/mm_logout_on.png");
		mm_logout_off = new Image;
		mm_logout_off.src = ("/fc_images/mm_logout_off.png");
}

// generic image swap function
function doSwapGen(x, y)
{
   if( compat ) { 
    document.images[x].src=eval(y+'.src'); 
   }
}


var isNetscape;
if (navigator.appName == 'Netscape')
  isNetscape = true;
else
  isNetscape = false;


// validate the text input into the email field to see if it looks
// like a valid email address.

function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		return false;
	    exit;
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) {
	    return false;
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
			return false;
		    }
	    }
	    return true;
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
	    return false;
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		return false;
	}
//	if (document.images) {
//		if (len<2) {
//			return false;
//		}
//		return true;
//	}
}

function newImage(arg) {
//preload all the menu images
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		mm_about_off = newImage;
		mm_about_off = newImage("/fc_images/mm_about_off.png");
		mm_about_on = newImage;
		mm_about_on = newImage("/fc_images/mm_about_on.png");
		mm_products_on = newImage;
		mm_products_on = newImage("/fc_images/mm_products_on.png");
		mm_products_off = newImage;
		mm_products_off = newImage("/fc_images/mm_products_off.png");
		index_04_index_03_over = newImage("images/index_04-index_03_over.gif");
		index_04_index_05_over = newImage("images/index_04-index_05_over.gif");
		index_05_over = newImage("images/index_05-over.gif");
		index_06_index_05_over = newImage("images/index_06-index_05_over.gif");
		index_06_index_07_over = newImage("images/index_06-index_07_over.gif");
		index_07_over = newImage("images/index_07-over.gif");
		index_08_index_07_over = newImage("images/index_08-index_07_over.gif");
		index_08_index_09_over = newImage("images/index_08-index_09_over.gif");
		index_09_over = newImage("images/index_09-over.gif");
		index_10_index_09_over = newImage("images/index_10-index_09_over.gif");
		index_10_index_11_over = newImage("images/index_10-index_11_over.gif");
		index_11_over = newImage("images/index_11-over.gif");
		index_12_index_11_over = newImage("images/index_12-index_11_over.gif");
		index_12_index_13_over = newImage("images/index_12-index_13_over.gif");
		index_13_over = newImage("images/index_13-over.gif");
		index_14_index_13_over = newImage("images/index_14-index_13_over.gif");
		index_16_index_17_over = newImage("images/index_16-index_17_over.gif");
		index_16_index_17b_over = newImage("images/index_16-index_17b_over.gif");
		index_17_over = newImage("images/index_17-over.gif");
		index_17b_over = newImage("images/index_17b-over.gif");
		preloadFlag = true;
	}
}

function preloadImages2() {
	if (document.images) {
		mm_about_off = newImage;
		mm_about_off.src = newImage("/fc_images/mm_about_off.png");
		mm_about_on = newImage;
		mm_about_on.src = newImage("/fc_images/mm_about_on.png");
		mm_products_on = newImage;
		mm_products_on.src = ("/fc_images/mm_products_on.png");
		mm_products_off = newImage;
		mm_products_off = newImage("/fc_images/mm_products_off.png");
		index_03_over = newImage("images/index_03-over.gif");
		index_04_index_03_over = newImage("images/index_04-index_03_over.gif");
		index_04_index_05_over = newImage("images/index_04-index_05_over.gif");
		index_05_over = newImage("images/index_05-over.gif");
		index_06_index_05_over = newImage("images/index_06-index_05_over.gif");
		index_06_index_07_over = newImage("images/index_06-index_07_over.gif");
		index_07_over = newImage("images/index_07-over.gif");
		index_08_index_07_over = newImage("images/index_08-index_07_over.gif");
		index_08_index_09_over = newImage("images/index_08-index_09_over.gif");
		index_09_over = newImage("images/index_09-over.gif");
		index_10_index_09_over = newImage("images/index_10-index_09_over.gif");
		index_10_index_11_over = newImage("images/index_10-index_11_over.gif");
		index_11_over = newImage("images/index_11-over.gif");
		index_12_index_11_over = newImage("images/index_12-index_11_over.gif");
		index_12_index_13_over = newImage("images/index_12-index_13_over.gif");
		index_13_over = newImage("images/index_13-over.gif");
		index_14_index_13_over = newImage("images/index_14-index_13_over.gif");
		index_16_index_17_over = newImage("images/index_16-index_17_over.gif");
		index_16_index_17b_over = newImage("images/index_16-index_17b_over.gif");
		index_17_over = newImage("images/index_17-over.gif");
		index_17b_over = newImage("images/index_17b-over.gif");
		preloadFlag = true;
	}
	auto_swap_main_img();
}

function validate_contact(){
	if(document.contact.first_name.value == ""){
		alert("Please enter your First Name.");
		document.contact.first_name.focus();
		document.contact.first_name.select();
		return false;
   	}
	if(document.contact.last_name.value == ""){
		alert("Please enter your Last Name.");
		document.contact.last_name.focus();
		document.contact.last_name.select();
		return false;
   	}
	var email_Str = document.contact.email.value; 
    if (emailCheck(email_Str) == 0) {
		alert("Please enter a valid Email Address.");
		document.contact.email.focus();
		document.contact.email.select();
		return false;
   	}
}

function validate_invite(){
	if(document.invite.friend_name.value == ""){
		alert("Please enter your friends name.");
		document.invite.friend_name.focus();
		document.invite.friend_name.select();
		return false;
   	}
	var email_Str = document.invite.friend_email.value; 
    if (emailCheck(email_Str) == 0) {
		alert("Please enter a valid email address for your friend.");
		document.invite.friend_email.focus();
		document.invite.friend_email.select();
		return false;
   	}
}


function editMask(eBox, evt, mask){
	var i,j=0;
	var ch;
	var oldValue=eBox.value;
	var key;
	if (isNetscape){
		key = evt.which;
	} else {
		key = evt.keyCode;
	}
	// Check for the Delete (BKSP) Key.  The "key" variable will have a value of 8.
	if (key != 8){
		oldValue += String.fromCharCode(key);
	} else {
    // For Netscape, when the BKSP is hit we should just set key to 0.
	    key = 0;
	}
	eBox.value = applyEditMask(oldValue, mask);
    // Need to return TRUE if a key like TAB was hit.
	return ((isNetscape) && (key == 0));
}

function setValueWithMask(targetField, srcValue, mask){
	targetField.value = applyEditMask(srcValue, mask);
}

function applyEditMask(inString, mask){
  var outString = '';
  var i,j=0;
  var ch;
  for (i=0; i < mask.length; i++){
    var mch = mask.charAt(i);
    if (j < inString.length){
      ch = inString.charAt(j);
      switch (mch){
        case "A":
          if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
          {
            outString += ch;
          }
          j++;
          break;
        case "N":
          if (ch >= '0' && ch <= '9')
          {
            outString += ch;
          }
          j++;
          break;
        case "X":
          outString += ch;
          j++;
          break;
        case "!":
          if (ch >= 'A' && ch <= 'Z')
          {
            outString += ch;
          }
          else if (ch >= 'a' && ch <= 'z')
          {
            outString += (ch + 'A' - 'a');
          }
          j++;
          break;
        case "#":
          if ((ch >= '0' && ch <= '9') || ch == '$' || ch == '+' || ch == '-' || ch == '.')
          {
            outString += ch;
          }
          j++;
          break;
        default:
          // The current mask character is a literal that MUST be present in the
          // current location.
          if (mch == ch)
          {
            // Skip the current character in the input string if it matches
            // the mask literal.
            j++;
          }
          outString += mch;
      }
    }
  }
  return outString;
}

//Swaps the main homepage image.
function swap_main_img(targeted){
	var the_targeted = targeted;
	if (targeted == null){
		the_targeted = "";
	}
	img1 = newImage("images/main_image1.jpg");
	img2 = newImage("images/main_image2.jpg");
	img3 = newImage("images/main_image3.jpg");
	document.getElementById("flash_container").style.backgroundImage = 'url("' + the_targeted + '")';
}

//Swaps the hompeage image of the bottom part of the phone to match with the main homepage image.
function swap_main_img_bottom(targeted){
	var the_targeted = targeted;
	if (targeted == null){
		the_targeted = "";
	}
	img1 = newImage("images/index_21_1.gif");
	img2 = newImage("images/index_21_2.gif");
	img3 = newImage("images/index_21_3.gif");
	document.getElementById("home_content").style.backgroundImage = 'url("' + the_targeted + '")';
}

function auto_swap_main_img(){
	var the_seeder = Math.random();
	var the_bigger_seed = the_seeder*3+.5;
	var the_number = Math.round(the_bigger_seed,0);
	if (the_number == 1) {
		swap_main_img('/images/main_image1.jpg');
		swap_main_img_bottom('/images/index_21_1.gif');
	}
	else if (the_number == 2) {
		swap_main_img('/images/main_image2.jpg');
		swap_main_img_bottom('/images/index_21_2.gif');
	}
	else {
		swap_main_img('/images/main_image3.jpg');
		swap_main_img_bottom('/images/index_21_3.gif');
	}
}


//function hide_submenus() {
//	document.getElementById("sub_menu_support_container").style.visibility= 'hidden';
//	document.getElementById("sub_menu_about_container").style.visibility= 'hidden';
//	document.getElementById("sub_menu_product_container").style.visibility= 'hidden';
//}

//Hides all of the submenus. Should be called onLoad
function hide_submenus(){
	document.getElementById("sub_menu_main_support_container").style.visibility= 'hidden';
	document.getElementById("sub_menu_main_buynow_container").style.visibility= 'hidden';
	document.getElementById("sub_menu_main_about_container").style.visibility= 'hidden';
	document.getElementById("sub_menu_main_products_container").style.visibility= 'hidden';
	document.getElementById("sub_menu_main_download_container").style.visibility= 'hidden';
	document.getElementById("html_nav").style.visibility= 'hidden';
}

var still_menuing = 'nothing';

function delayed_hide_submenus (truth) {
	still_menuing = truth;
//	alert(truth);
	//set timer for about half second
	  setTimeout ( "should_i_hide_submenus()", 500 );
}

function should_i_hide_submenus() {
	//if menu rollover is true, do nothing
	if (still_menuing == 'untrue') {	//if rollover is false, hide_submenus()
		hide_submenus();
	}
}

function make_it_true() {
	still_menuing = "sorta_true";
}


function show_submenu(crosshair) {
	hide_submenus();
	var fire;
	fire="sub_menu_"+crosshair+"_container";
	document.getElementById(fire).style.visibility= 'visible';
}

//Loads up the hidden submenus when called by the main menu button
function show_submenu_main(crosshair) {
	hide_submenus();
	var fire;
	still_menuing = "something";
//	alert(still_menuing);
	fire="sub_menu_main_"+crosshair+"_container";
	document.getElementById(fire).style.visibility= 'visible';
	document.getElementById(fire).style.position= 'relative';
	document.getElementById("html_nav").style.visibility= 'visible';
//	document.getElementById(fire).style.position= 'absolute';
}

//Checks to see if the user is inside our frames for displaying our 
//app and settings. If they are not, then they need to be logged out.
function where_am_i() {
//alert(window.name);
	if (window.name == "losframos") 
	{
		return false;
	}
	else if (window.name == "elframo") 
	{
		return false;
	}
	else {
		_top.window.location = "/logout.php";
	}
}

function do_loadup(){
	where_am_i();
	preloadImages();
	//alert("it's getting this far");
}

function disableer(){
	var disable_border_color;
	disable_border_color="CDDEF3";
	var disable_background_color;
	disable_background_color="EAF0F7";
	var enable_border_color;
	enable_border_color="2969BB";
	var enable_background_color;
	enable_background_color="FFFFFF";
	//alert("fc_main.js" + document.selectplan.device[3].value);

    function disableControl(control, d) {
        if( d == true ) {
		    control.style.borderColor= disable_border_color;
		    control.style.backgroundColor= disable_background_color;
        } else {
		    control.style.borderColor= enable_border_color;
		    control.style.backgroundColor= enable_background_color;
		}
       control.disabled=d;
    }
    function disableEditBox(control, d){
        if( d == true ) {
            control.value="";
        }
        disableControl(control, d);
    }
    function disableCheckBoxControl(control, d){
        if( d == true ) {
		    control.checked=false;
		}
        disableControl(control, d);
    }
	// None is selected
	if(document.selectplan.device[1].checked) {
        disableEditBox(document.selectplan.cellnumberWM, false);
        disableEditBox(document.selectplan.carrierWM, false);
	}else{
        disableEditBox(document.selectplan.cellnumberWM, true);
        disableEditBox(document.selectplan.carrierWM, true);
	}
	if(document.selectplan.device[2].checked) {
        disableEditBox(document.selectplan.custom_sms_email, false);
	} else {
        disableEditBox(document.selectplan.custom_sms_email, true);
	}
	if(document.selectplan.device[3].checked) {
        disableEditBox(document.selectplan.cellnumberFP, false);
        disableEditBox(document.selectplan.carrierFP, false);
        disableCheckBoxControl(document.selectplan.new_post_sms, false);
        disableCheckBoxControl(document.selectplan.update_post_sms, false);
        disableCheckBoxControl(document.selectplan.new_task_sms, false);
        disableCheckBoxControl(document.selectplan.update_task_sms, false);
        disableCheckBoxControl(document.selectplan.new_schedule_sms, false);
	    disableCheckBoxControl(document.selectplan.update_schedule_sms, false);
	} else {
        disableEditBox(document.selectplan.cellnumberFP, true);
        disableEditBox(document.selectplan.carrierFP, true);
        disableCheckBoxControl(document.selectplan.new_post_sms, true);
        disableCheckBoxControl(document.selectplan.update_post_sms, true);
        disableCheckBoxControl(document.selectplan.new_task_sms, true);
        disableCheckBoxControl(document.selectplan.update_task_sms, true);
        disableCheckBoxControl(document.selectplan.new_schedule_sms, true);
	    disableCheckBoxControl(document.selectplan.update_schedule_sms, true);
	}
}

function showWH(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return(myHeight);
}

function breakout_of_frame(){
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}

	function processing_message() {
//	alert("it's getting this far");
	document.getElementById("processing_message_box").style.visibility= 'visible';
	document.getElementById("processing_message_hider").style.visibility= 'hidden';
}

function popup(mylink, windowname) {
    if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    window.open(href, windowname, 'width=700,height=300,scrollbars=yes');
    return false;
}


