mooflo_full = false;

si = 0;

var myScrollFx = false;
window.addEvent('domready', function() {
  myScrollFx = new Fx.Scroll(window);
});

function domyscroll(trgid) {
  if ($(trgid)) {
    myScrollFx.toElement($(trgid));
  }
}

var myMooFlowPage = {
	start: function(){
		var mf = new MooFlow($('MooFlow'), {
			startIndex: si,
			useSlider: true,
			useAutoPlay: false,
			useCaption: true,
			useResize: true,
			useMouseWheel: true,
			useKeyInput: true,
			useWindowResize: true,
			heightRatio: 0.5,
			factor:115,
			useViewer: true,
			'onResized': function(isFull){
			  mooflo_full = isFull;
			}
		});
		mf.attachViewer();
	}
};

function build_a_card() {
  if ($('this_url').value == "secure") {
    window.location = $('nonsecure_url').value+'?func=build_a_card()';
  }
  else {
    var rn = Math.floor(Math.random()*999999999);
    MOOdalBox_I.open(
      $('nonsecure_url').value+"CGUI.php?rn="+rn+"&recall=1",
      "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
      "905 505"
    );
  }
}

function new_card_session() {
  var rn = Math.floor(Math.random()*999999999);
  MOOdalBox_I.open(
      $('nonsecure_url').value+"CGUI.php?rn="+rn+"&new_session=1",
      "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
      "905 505"
  );
}


function load_card_template(id) {
  /*
  if ($('this_url').value == "secure") {
    window.location = $('nonsecure_url').value+'?func=load_card_template(\''+id+'\')';
  }
  else {
    var rn = Math.floor(Math.random()*999999999);
    MOOdalBox_I.open(
      $('nonsecure_url').value+"/ajax/load_template.php?rn="+rn+"&id="+id,
      "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
      "905 505"
    );
  }
  */
  if ($('this_url').value == "secure") {
    window.location = $('nonsecure_url').value+'?func=resend_card(\''+id+'\')';
  }
  else {
    var rn = Math.floor(Math.random()*999999999);
    MOOdalBox_I.open(
      $('nonsecure_url').value+"/ajax/resend_card.php?rn="+rn+"&id="+id,
      "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
      "905 505"
    );
  }
}

function load_card_contact(id) {
  if ($('this_url').value == "secure") {
    window.location = $('nonsecure_url').value+'?func=load_card_contact(\''+id+'\')';
  }
  else {
    var rn = Math.floor(Math.random()*999999999);
    MOOdalBox_I.open(
      $('nonsecure_url').value+"/ajax/load_CGUI_contact.php?rn="+rn+"&contact_id="+id,
      "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
      "905 505"
    );
  }
}

function resend_card(id) {
//  var rsc = confirm("This will rebuild this card's original session so you can edit (if you wish) and send again.\n\nDo you wish to proceed?");
  var rsc = true;
  if (rsc == true) {
    if ($('this_url').value == "secure") {
      window.location = $('nonsecure_url').value+'?func=resend_card(\''+id+'\')';
    }
    else {
      var rn = Math.floor(Math.random()*999999999);
      MOOdalBox_I.open(
        $('nonsecure_url').value+"/ajax/resend_card.php?rn="+rn+"&id="+id,
        "SFY CARD BUILDER - You can close this window anytime and your changes will be saved in your Cards-in-Progress!",
        "905 505"
      );
    }
  }
}

function clear_card(card_id) {
  var kk = confirm("Are you sure you want to delete your current card-in-progress? This operation cannot be undone.");
  if (kk == true) {
    window.location = $('nonsecure_url').value+"cards-in-progress.php?action=clearcard&card_id="+card_id;
  }
}

function update_card_in_progress() {
  new Request({
    url: '/ajax/current_card_in_progress.php?rn='+Math.floor(Math.random()*999999999),
    onSuccess: 	function(txt) {
	  $('current_card_in_progress').set('html',txt);
    }
  }).send();
  setTimeout("update_card_in_progress()",8000); // every 8 seconds
}
function init_top_nav() {
  $$('#top_nav li.link').each(function(item){
	item.addEvent('mouseover', function(e) {
	  item.setProperty('class','link_over');
	});
	item.addEvent('mouseout', function(e) {
	  item.setProperty('class','link');
	});
  });
}

function init_left_col_cats() {
  $$('#left_col div.cat').each(function(item){
	gc = $(item.id+'_ul').getCoordinates();
	hh = (gc['height']+4);
	$(item.id+'_hh').value = hh;
	$(item.id+'_ul').setStyles({'overflow':'hidden', 'height':'0'});
	item.addEvent('click', function(e) {
	  toggle_category_nav(item.id);
	});
  });
  $$('#left_col li.cc_drop').each(function(item){
	item.addEvent('click', function(e) {
	  load_category(item.id);
	});
	item.addEvent('mouseover', function(e) {
	  item.setProperty('class','over');
	});
	item.addEvent('mouseout', function(e) {
	  item.setProperty('class','');
	});
  });
  if ($('expand_root')) { // expand root
    toggle_category_nav($('expand_root').value);
  }
}

function load_category(liid) {
  str = liid.split("_");
  catid = str[1];
  rootid = str[2];
  if (!isNaN(catid)) {
    window.location = "/?catid="+catid+"&rootid="+rootid;
  }
}

function toggle_category_nav(itemid) {
  if ($(itemid)) {
    ugc = $(itemid+'_ul').getCoordinates();
    ihh = ugc['height'];
    if (ihh == 0) {
      $(itemid+'_ul').tween('height', $(itemid+'_hh').value);
      $(itemid+'_icon').setProperty('class','cat_arrow_down');
    }
    else {
      $(itemid+'_ul').tween('height', 0);
      $(itemid+'_icon').setProperty('class','cat_arrow');
    }
  }
}

function toggleAgreement() {
  i = $('agreechk');
  if (i.checked == true) {
    i.checked = false;
  }
  else {
    i.checked = true;
  }
}


// username illegal characters
var illegalChars = /\W/; // alpha-numeric & underscores

user_alert = 'Username Protocol:\n\n7 minimum characters\n20 maximum characters\nA-Z, a-z, 0-9 and Underscores only. All other characters are prohibited.';

function username_alert() {
  alert(user_alert);
}

function chkRegForm() {
  ff = eval("document.regform");
  
  ichk_cc = false;
  if (ff.chk_cc.value == "1") { // verifies billing information is complete
    ichk_cc = true;
  }
  
  if (ff.contact_fname.value == "") {
    alert("Please enter your first name.");
    ff.contact_fname.focus();
    return false;
  }
  else if (ff.contact_lname.value == "") {
    alert("Please enter your last name.");
    ff.contact_lname.focus();
    return false;
  }
  else if (ff.contact_address1.value == "") {
    alert("Please enter your address.");
    ff.contact_address1.focus();
    return false;
  }
  else if (ff.contact_city.value == "") {
    alert("Please enter your city.");
    ff.contact_city.focus();
    return false;
  }
  else if (ff.contact_state.value == "") {
    alert("Please enter your state.");
    ff.contact_state.focus();
    return false;
  }
  else if (ff.contact_zip.value == "") {
    alert("Please enter your zip.");
    ff.contact_zip.focus();
    return false;
  }
  else if (ff.phone.value == "") {
    alert("Please enter your phone number.");
    ff.phone.focus();
    return false;
  }
  else if (ff.email.value.indexOf('@') <= 0) {
    alert("Please enter a valid email address.");
    ff.email.focus();
    ff.email.select();
    return false;
  }



  else if ((ichk_cc) && (ff.billing_fname.value == "")) {
    alert("Please enter the first name as it appears on your card.");
    ff.billing_fname.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.billing_lname.value == "")) {
    alert("Please enter the last name as it appears on your card.");
    ff.billing_lname.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.billing_address1.value == "")) {
    alert("Please enter the address associated with your billing.");
    ff.billing_address1.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.billing_city.value == "")) {
    alert("Please enter the city associated with your billing.");
    ff.billing_city.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.billing_state.value == "")) {
    alert("Please select the state associated with your billing.");
    ff.billing_state.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.billing_zip.value == "")) {
    alert("Please enter the zip associated with your billing.");
    ff.billing_zip.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.cn.value == "")) {
    alert("Please enter your card number with no spaces or dashes.");
    ff.cn.focus();
    return false;
  }
  else if ((ichk_cc) && (ff.cvv.value == "")) {
    alert("Please enter your 3 digit CVV number on the back of your card.");
    ff.cvv.focus();
    return false;
  }
  
  
  
  else if (ff.user.value == "") {
    alert("Please enter a user name.");
    ff.user.focus();
    return false;
  }
  else if (illegalChars.test(ff.user.value)) {
    username_alert();
    ff.user.focus();
    ff.user.select();
    return false;
  }
  else if (ff.user.value.length < 7) {
    alert("Your username must be at least 7 characters in length. Please re-enter.");
    ff.user.focus();
    ff.user.select();
    return false;
  }
  else if (ff.pass.value == "") {
    alert("Please enter a password.");
    ff.pass.focus();
    return false;
  }
  else if (ff.pass.value.length < 7) {
    alert("Your password must be at least 7 characters in length. Please re-enter.");
    ff.pass.focus();
    ff.pass.select();
    return false;
  }
  else if (ff.pass_check.value == "") {
    alert("Please verify (repeat) your password.");
    ff.pass_check.focus();
    return false;
  }
  else if (ff.pass.value != ff.pass_check.value) {
    alert("Your passwords did not match. Please re-enter.");
    ff.pass_check.value = "";
    ff.pass.focus();
    ff.pass.select();
    return false;
  }
  else if (!ff.agree.checked) {
    alert("Please agree to the terms of use.");
    ff.agree.focus();
    return false;
  }
  else {
    ff.subtn.value = "please wait...";
    ff.subtn.disabled = true;
    return true;
  }
}

function same_as_billing() {
  ff = eval("document.regform");
  ff.billing_fname.value = ff.contact_fname.value;
  ff.billing_lname.value = ff.contact_lname.value;
  ff.billing_address1.value = ff.contact_address1.value;
  ff.billing_address2.value = ff.contact_address2.value;
  ff.billing_city.value = ff.contact_city.value;
  ff.billing_state.value = ff.contact_state.value;
  ff.billing_zip.value = ff.contact_zip.value;
  ff.billing_country.value = ff.contact_country.value;
  ff.ct.focus();
}

function chk_credit_purchase() {
  ff = eval("document.credit_form");
  if (ff.credit_package.value == "") {
    alert("Please select a credit package.");
    ff.credit_package.focus();
    return false;
  }
  else if (!ff.agree.checked) {
    alert("Please agree to the terms.");
    ff.agree.focus();
    return false;
  }
  else {
    ff.subtn.value = "Purchasing Credits...";
    ff.subtn.disabled = true;
    return true;
  }
}

function init_boxes() {
  $$('div.box_wide').each(function(item) {
    xcontent = item.get('html');
    item.set('html','');
    new Element('div').set({
    	'class':	'boxbar',
    	'html':		item.title
      }).inject(item);    
    new Element('div').setStyles({
    	'padding':		'5px',
    	'border':		'1px solid #D5D5D5',
    	'border-top':	'0'
      }).set({
    	'html':	xcontent
      }).inject(item);
  });
}

function chkForgotPass() {
  if (document.passform.email.value.indexOf('@') <= 0) {
    alert('Please enter a valid email address.');
    document.passform.email.focus();
    document.passform.email.select();
    return false;
  }
  else {
    return true;
  }
}

function add_new_favorite_category() {
  $('new_fav_cat_form').setStyles({'display':''});
  $('new_fav_cat_add').tween('height', 0);
  $('new_fav_cat_name').value = "[enter a name]";
  $('new_fav_cat_name').focus();
  $('new_fav_cat_name').select();
}

function close_new_favorite_category() {
  $('new_fav_cat_add').tween('height', 23);
  $('new_fav_cat_name').value = "";
  $('new_fav_cat_form').setStyles({'display':'none'});
}

function save_new_favorite_category() {
  fi = $('new_fav_cat_name');
  if ((fi.value == "[enter a name]") || (fi.value == "")) {
    alert("Please enter a name for the favorite category you are creating.");
    fi.value = "[enter a name]";
    fi.focus();
    fi.select();
  }
  else {
    window.location = "?action=add_fav_cat&name="+fi.value;
  }
}

function delete_favorite_category(id) {
  var kk = confirm("Are you sure you want to delete this Favorite Category?");
  if (kk == true) {
    window.location = "?action=del_fav_cat&id="+id;
  }
}

function edit_favorite_category(id,oldname,thrulink) {
  var nnm = prompt("Please enter the new name for this category:",oldname);
  if (nnm) {
    window.location = "?"+thrulink+"&action=rename_fav&id="+id+"&name="+URLEncode(nnm);
  }
}

function chk_save_to_favs() {
  ff = eval("document.stf");
  if (ff.favorite_category_id.value == "") {
    alert("Please select a category.");
    ff.favorite_category_id.focus();
    return false;
  }
  else if ((ff.favorite_category_id.value == "add") && ((ff.newname.value == "") || (ff.newname.value == "[Enter a name]"))) {
    alert("Please enter a name for your new category.");
    ff.newname.focus();
    return false;
  }
  else {
    ff.subtn.value = "saving...";
    ff.subtn.disabled = true;
    return true;
  }
}

function chk_save_to_favs_type() {
  ff = eval("document.stf");
  if (ff.favorite_category_id.value == "add") {
    $('addnew').setStyle('display','');
    ff.newname.value = "[Enter a name]";
    ff.newname.focus();
    ff.newname.select();
  }
  else {
    $('addnew').setStyle('display','none');
    ff.newname.value = "";
  }
}

function URLEncode(str) {
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";	// x-www-urlencoded, rather than 
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert("Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted.");
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
}

function chkLogin() {
  ff = eval("document.plogin");
  if (ff.user.value == "") {
    alert("Please enter your username.");
    ff.user.focus();
    return false;
  }
  else if (ff.pass.value == "") {
    alert("Please enter your password.");
    ff.pass.focus();
    return false;
  }
  else {
    ff.subtn.value = "logging in...";
    ff.subtn.disabled = true;
    return true;
  }
}

// CALENDAR

function toggle_resource(rid) {
  if ($(rid).checked) {
    $(rid).checked = false;
  }
  else {
	$(rid).checked = true;
  }
  calendar_filters();
}

function calendar_filter_config() {
  ii = "";
  $$('input.cal_filter').each(function(item){
    vv = 'n'
    if (item.checked) { vv = 'y'; }
	ii += "&"+item.get('id')+"="+vv;
  });
  return ii;
}

function calendar_filters() {
  $$('input.cal_filter').each(function(item){
    dis = 'none'
    if (item.checked) { dis = ''; }
    $$('div.cal_event').each(function(el){
      cls = $(el.get('id')+'_C').get('class');
      if (cls == item.get('id')) {
        el.setStyle('display',dis);
      }
    });
  });
}
function cal_view_ab(id) {
  window.location = "/address_book.php?contact_id="+id;
}

function calendar_init() {
  $$('div.cal_event').each(function(item) {
    item.addEvent('mouseenter', function() {
      $(item.get('id')+'_I').setStyle('display','');
    });
    item.addEvent('mouseleave', function() {
      $(item.get('id')+'_I').setStyle('display','none');
    });
  });
  
  // SET DATE SELECTION ELEMENTS
  gt = $('mark_top').getCoordinates();
  gc = $('mark_month').getCoordinates();
  $('cal_month').setStyles({
  	'top':	(gc['top'] - gt['top']),
  	'left':	(gc['left'] - gt['left'])
  });
  gc = $('mark_year').getCoordinates();
  $('cal_year').setStyles({
  	'top':	(gc['top'] - gt['top']),
  	'left':	(gc['left'] - gt['left'])
  });
  
  // document onClick
  document.addEvent('click', function(event){
    if (event.target) {
      this_cls = $(event.target).get('class');
      this_id  = $(event.target).get('id');
      if ((this_id != 'mark_month') &&
          (this_id != 'mark_year') &&
          (this_id != 'cal_month') && 
          (this_id != 'cal_year')) {
	    $('cal_month').setStyle('display','none');
	    $('cal_year').setStyle('display','none');
      }
    }
  });
  
}
function calendar_add_item(vv) {
  var rn = Math.floor(Math.random()*999999999);
  MOOdalBox_I.open(
    "/ajax/calendar_form.php?vv="+vv+calendar_filter_config()+"&rn="+rn,
    "ADD CUSTOM EVENT",
    "400 300"
  );
}
function cal_edit_event(id) {
  var rn = Math.floor(Math.random()*999999999);
  MOOdalBox_I.open(
    "/ajax/calendar_form.php?action=edit&id="+id+calendar_filter_config()+"&rn="+rn,
    "EDIT CUSTOM EVENT",
    "400 300"
  );
}
function calendar_send_card(id) {
  load_card_contact(id);
}
function calendar_form() {
  ff = eval("document.cform");
  if (ff.event.value == "") {
    alert("Please enter a description for this event.");
    ff.event.focus();
    return false;
  }
  else if ((ff.irepeat[1].checked) && (ff.repeat_type.value == '0')) {
    alert("Please select a repeat type.");
    ff.repeat_type.focus();
    return false;
  }
  else {
    ff.subtn.value = "saving...";
    ff.subtn.disabled = true;
    return true;
  }
}
function calendar_repeat_options() {
  ff = eval("document.cform");
  if (ff.irepeat[1].checked) {
    $('repeat_options').setStyle('display','');
  }
  else {
    $('repeat_options').setStyle('display','none');
    ff.repeat_type.value = '0';
  }
}
function cal_delete_event(id,rpt,calid) {
  if (rpt > 0) {
    var kk = confirm("This event is repeating. Deleting will remove all recurring items. Do you wish to proceed?");
  }
  else {
    var kk = confirm("Are you sure you want to delete this event?");
  }
  if (kk == true) {
    new Request({
      url: '/ajax/calendar_form.php?action=delete&id='+id+'&rn='+Math.floor(Math.random()*999999999),
      onSuccess: 	function(txt) {
		$$('input.E'+id).each(function(item) {
		  $(item.value).dispose();
		});
      }
    }).send();
  }
}

function calendar_reload(icmd,mm,yy) {
  window.location = "?command="+icmd+"&month="+mm+"&year="+yy+calendar_filter_config();
}

function cal_pop_month() {
  $('cal_year').setStyle('display','none');
  $('cal_month').setStyle('display','');
}

function cal_pop_year() {
  $('cal_month').setStyle('display','none');
  $('cal_year').setStyle('display','');
}

function clear_myfonts_select() {
  $$('#ab_groups li').each(function(item){
    item.setStyles({
      'background-color':'#FFF',
      'color':'#000'
    });
  });
}

function init_fonts() {
  $$('#ab_groups li').each(function(item){
	item.addEvent('click', function() {
	  clear_myfonts_select();
	  cls = item.get('class');
	  if (cls == "li_font") {
	    trg = "font_details.php";
	  }
	  if (cls == "li_sign") {
	    trg = "sign_details.php";
	  }
      item.setStyles({
        'background-color':'#0F77E4',
        'color':'#FFF'
      });
	  new Request({
	    url: '/ajax/'+trg+'?id='+item.get('id')+'&rn='+Math.floor(Math.random()*999999999),
	    onSuccess: 	function(txt) {
		  $('ab_details').set('html',txt);
	    }
	  }).send();
	});
  });
}

function myphotos_select_cat() {
  vv = $('cat_id').value;
  if (vv != "") {
    window.location = "/myphotos.php?cat_id="+vv;
  }
}

function myphotos_edit_cat(id,txt) {
  var rnm = prompt("Edit Category Name:",txt);
  if (rnm) {
    window.location = "?cat_id="+id+"&action=savecat&id="+id+"&name="+URLEncode(rnm);
  }
}

function myphotos_delete_cat(id) {
  var kk = confirm("Deleting this category will also delete ALL photos within. Are you sure you wish to proceed?");
  if (kk == true) {
    window.location = "?action=deletecat&id="+id;
  }
}

function init_dim_screen() {
  $('screendim').setStyles({
  	'opacity':'0',
  	'display':'none'
  });
}

function dim_screen(txt) {
  if (!txt) {
    txt = "Loading...";
  }
  $('dimstat').set('html',txt);
  $('screendim').setStyles({
    'display':	'',
    'opacity':	'0.8',
  	'width':	window.getWidth(),
  	'height':	window.getHeight()
  });
  $('dimstat').setStyles({
  	'width':	window.getWidth(),
  	'top':	((window.getHeight() / 2).toInt(0) + 30)
  });
//  new Fx.Morph($('screendim')).start({'opacity':[0,0.8]});
}

function undim_screen(txt,jsexec) {
  if (!txt) {
    txt = "Complete!";
  }
  $('dimstat').set('html',txt);
  //  $('screendim').setStyles({'display':'none', 'opacity':'0'});
  new Fx.Morph($('screendim'), {
    duration:	100,
  	onComplete: function() {
  	  $('screendim').setStyle('display','none');
      if (jsexec) {
        eval(jsexec);
      }
  	}
  }).start({'opacity':[0.8,0]});
}

function chk_new_pcat() {
  document.cf.subtn.disabled = false;
  if ($('cat_id').value.indexOf('new') >= 0) {
    $('new_cat').setStyle('display','');
    $('new_cat_name').value = "Untitled";
    $('new_cat_name').focus();
    $('new_cat_name').select();
    if ($('cat_icons')) {
      $('cat_icons').setStyle('display','none');
    }
  }
  else if ($('cat_id').value == "") {
    $('new_cat').setStyle('display','none'); 
    if ($('cat_icons')) {
      $('cat_icons').setStyle('display','none');
    }
  }
  else {
    $('new_cat').setStyle('display','none'); 
    if ($('cat_icons')) {
      $('cat_icons').setStyle('display','');
    }
  }
}
function chk_photo_cat_form() {
  ff = eval("document.cf");
  if (ff.cat_id.value == "") {
    alert("Please select an album/category or create a new one to upload your photos/files to.");
    ff.cat_id.focus();
    return false;
  }
  else if ((ff.cat_id.value.indexOf('new') >= 0) && ((ff.new_cat_name.value == "") || (ff.new_cat_name.value == "Untitled")) ) {
    alert("Please select a name for your new album/category.");
    ff.new_cat_name.focus();
    ff.new_cat_name.select();
    return false;
  }
  else {
    ff.subtn.value = "please wait...";
    ff.subtn.disabled = true;
    return true;
  }
}

function cms_template_cat_delete() {
  var kk = confirm("Are you sure you want to delete this category?");
  if (kk == true) {
    window.location = "?action=delete_cat&id="+$('cat_id').value;
  }
}

function cms_template_cat_edit() {
  vv = $('cat_id').value;
  if ((vv != "") && (vv != "new")) {
    var kk = prompt("Edit Category Name:", $('cat'+vv).value);
    if (kk) {
      window.location = "?action=save_cat&id="+$('cat_id').value+"&name="+URLEncode(kk);
    }
  }
}

function chkContactForm() {
    if (document.cform.name.value == "") {
      alert("Please enter your name.");
      document.cform.name.focus();
      return false;
    }
    else if (document.cform.email.value.indexOf('@') <= 0) {
      alert("Please enter a valid email address.");
      document.cform.email.focus();
      document.cform.email.select();
      return false;
    }
    else if (document.cform.subject.value == "") {
      alert("Please enter a subject.");
      document.cform.subject.focus();
      return false;
    }
    else if (document.cform.message.value == "") {
      alert("Please enter a message.");
      document.cform.message.focus();
      return false;
    }
    else if (document.cform.code.value == "") {
      alert("Please enter the validation code you see displayed.");
      document.cform.code.focus();
      return false;
    }
    else {
      document.cform.subtn.value = "please wait...";
      document.cform.subtn.disabled = true;
      return true;
    }
}

function chkCloseAcct() {
  var ca = confirm("Are you SURE you want to close your account? Last chance!");
  if (ca == true) {
    alert("Good knowing you!");
    return true;
  }
  else {
    return false;
  }
}

function delete_template(id,pn) {
  var kk = confirm("Are you sure you want to delete this template?");
  if (kk == true) {
    window.location = "?action=delete&id="+id+"&pagenum="+pn;
  }
}
function edit_template(id,pn) {
  var rn = Math.floor(Math.random()*999999999);
  MOOdalBox_I.open(
    "/ajax/edit_template.php?rn="+rn+"&id="+id+"&pagenum="+pn,
    "EDIT TEMPLATE",
    "550 400"
  );
}

card_session_out_timer = 0;

function card_sessions_over() {
  card_session_out_timer = 0;
  if ($('card_sessions')) {
    $('card_sessions').setStyle('display','');
  }
}

function card_sessions_out() {
  card_session_out_timer = 1;
  card_session_out_timer_start();
}

function card_session_out_timer_start() {
  if (card_session_out_timer > 0) {
    card_session_out_timer++;
    if (card_session_out_timer >= 5) {
      card_sessions_hide();
    }
    else {
      setTimeout("card_session_out_timer_start()",1000);
    }
  }
}

function card_sessions_hide() {
  card_session_out_timer = 0;
  if ($('card_sessions')) {
    $('card_sessions').setStyle('display','none');
  }
}

function reload_card_session(card_id) {
  window.location = $('nonsecure_url').value+'cards-in-progress.php?action=reload_card_session&id='+card_id+'&func=build_a_card()';
}

function check_referral_code() {
  if ($('referral_code').value != '') {
    var myAjax = new Request.JSON({
    	url:		'/ajax/check_referral_code.php',
    	data:		'&ref_id='+$('referral_code').value,
    	onSuccess:	function(databack, html) {
    	  if (databack.status == "error") {
    	    $('referral_name').set('html','<span style="color:red">&rarr; The referral code you entered was invalid.</span>');
    	    $('referral_code').value = "";
    	  }
    	  else {
    	    $('referral_code').value = databack.ref_id;
    	    if (databack.user_name == "NOSHOW") {
    	      $('referral_name').set('html','&rarr; Code Accepted!');
    	    }
    	    else {
    	      $('referral_name').set('html','&rarr; Thank you for giving '+databack.user_name+' credit!');
    	    }
    	  }
    	}
    }).post();
  }
}

function delete_card_order(card_id) {
  var kk = confirm("Are a system administrator, you can delete this card and all it's corresponding orders. This is non-recoverable and removes the card and all resources from the system permanently.\n\nDo you wish to proceed?");
  if (kk == true) {
    pn = "";
    if ($('pagenum')) {
      pn = "&pagenum="+$('pagenum').value;
    }
    window.location = "?action=delete_card_order&card_id="+card_id+pn;
  }
}
