// JavaScript Document
$(document).ready(function() {
	$('#codeLoading').hide();
	$('#newcode').blur(function(){
	  $('#codeLoading').show();
      $.post("/codecheck.cfm", {
        code: $('#newcode').val()
      }, function(response){
	  
        $('#codeResult').fadeOut();
        setTimeout("finishAjax('codeResult', '"+escape(response)+"')", 400);
		
      });
    	return false;
	});
});

function finishAjax(id, response) {
  $('#codeLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax


$(document).ready(function() {
	$('#keywordLoading').hide();
	$('#keyword').blur(function(){
	  $('#keywordLoading').show();
      $.post("/keywordcheck.cfm", {
        code: $('#keyword').val()
      }, function(response){
	  
        $('#keywordResult').fadeOut();
        setTimeout("finishAjax('keywordResult', '"+escape(response)+"')", 400);
		
      });
    	return false;
	});
});

function finishAjax(id, response) {
  $('#keywordLoading').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
} //finishAjax






 $(document).ready(function() {
     // We use the jQuery validator plugin to do input validation
     // http://docs.jquery.com/Plugins/Validation
     // call the validate method on our form, and pass in our explicit options


 $("#theForm").validate({onkeyup:true,
					groups: {
					    localPhone: "phone1 phone2 phone3"
						  },
					errorPlacement: function(error, element) {
						 if (element.attr("name") == "phone1" 
									 || element.attr("name") == "phone2"
									 || element.attr("name") == "phone3")
						   error.insertAfter("#phone4");
						 else
						   error.insertAfter(element);
					   },
					 messages: {
						 phone3: "Please Enter a full 10 digit phone number",	
						 phone2: "Please Enter a full 10 digit phone number",	
						 phone1: "Please Enter a full 10 digit phone number"	
						 	}
					   
		});	
 
  $("#uploadForm").validate({onkeyup:true,
					rules: {
					    file: {
							required: true,
							accept: "jpg|jpeg|gif|png"
						}
					   },
					 messages: {
						 file: "Only .jpg .jpeg .gif & .png files accepted"
					 	}
					   
		});	

  $("#uploadBannerForm").validate({onkeyup:true,
					rules: {
					    file: {
							required: true,
							accept: "jpg|jpeg|gif"
						}
					   },
					 messages: {
						 file: "Only .jpg .jpeg & .gif files accepted"
					 	}
					   
		});	
 

        $("#frmRegister").validate({
             onkeyup:false,
             rules: {
               username: {
                  required:true,
                  minlength:5,
	              maxlength:45,
                  validChars:true,
				  remote: "/check2.cfm",
                  usernameCheck:true    // remote check for duplicate username
              },

              email_first: {
                 required:true,
                 email:true,
                 maxlength:255,
                 emailCheck:true    // remote check for duplicate email address
             },

              email_second: {
                  required:true,
                  equalTo: "#email_first"
             },

              password_first: {
                  required:true,
                  minlength:6,
                  maxlength:128
              },

              password_second: {
                 required:true,
                 equalTo: "#password_first"
              },
			  zipcode: {
                  required:true,
                  minlength:5,
	              maxlength:5
              },
		 
          },

          messages: {
              username: {
                  required: "username is required.",
                  minlength: jQuery.format("username must be at least {0} characters in length."),
                  maxlength: jQuery.format("username can not exceed {0} characters in length."),
				  remote: jQuery.format("{0} is already in use"),
                  validChars: "please supply valid characters only."
              },

              email_first: {
                  required: "Email address is required.",
                  email: "Email address must be valid.",
                  maxlength: jQuery.format("Email address can not exceed {0} characters in length.")
              },

             email_second: {
                 required: "Confirmed email address is required.",
                 equalTo: "Confirmed email address does not match."
              },

              password_first: {
                  required: "Password is required.",
                  minlength: jQuery.format("password must be at least {0} characters in length."),
                  maxlength: jQuery.format("password can not exceed {0} characters in length.")
              },

              password_second: {
                  required: "Confirmed password is required.",
                  equalTo: "Confirmed password does not match."
              },
			  zipcode: {
                  required: "Zip Code is required.",
                  minlength: jQuery.format("Zip Code must be at least {0} characters in length."),
                  maxlength: jQuery.format("Zip Code can not exceed {0} characters in length.")
              },

          }
      });


   $("#frmEditMember").validate({
             onkeyup:true,
             rules: {

			email_first: {
                 required:true,
                 email:true,
                 maxlength:255,
             },

              email_second: {
                  required:true,
                  equalTo: "#email_first"
             },

              password_first: {
                  required:true,
                  minlength:6,
                  maxlength:128
              },

              password_second: {
                 required:true,
                 equalTo: "#password_first"
              },

		 
          },

          messages: {
              email_first: {
                  required: "email address is required.",
                  email: "email address must be valid.",
                  maxlength: jQuery.format("email address can not exceed {0} characters in length.")
              },

             email_second: {
                 required: "confirmed email address is required.",
                 equalTo: "confirmed email address does not match."
              },

              password_first: {
                  required: "password is required.",
                  minlength: jQuery.format("password must be at least {0} characters in length."),
                  maxlength: jQuery.format("password can not exceed {0} characters in length.")
              },

              password_second: {
                  required: "confirmed password is required.",
                  equalTo: "confirmed password does not match."
              }

          }
      });


  });

  // extend the validation plugin to do remote username and email dupe checking

 

   
 // check for unwanted characters

  $.validator.addMethod('validChars', function (value) {
     var result = true;
     // unwanted characters
     var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
     for (var i = 0; i < value.length; i++) {
         if (iChars.indexOf(value.charAt(i)) != -1) {
             return false;
         }
     }
     return result;
}, '');




(function($){
/*
 * Editable 1.3.3
 *
 * Copyright (c) 2009 Arash Karimzadeh (arashkarimzadeh.com)
 * Licensed under the MIT (MIT-LICENSE.txt)
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Date: Mar 02 2009
 */
$.fn.editable = function(options){
	var defaults = {
		onEdit: null,
		onSubmit: null,
		onCancel: null,
		editClass: null,
		submit: null,
		cancel: null,
		type: 'text', //text, textarea or select
		submitBy: 'blur', //blur,change,dblclick,click
		editBy: 'click',
		options: null
	}
	if(options=='disable')
		return this.unbind(this.data('editable.options').editBy,this.data('editable.options').toEditable);
	if(options=='enable')
		return this.bind(this.data('editable.options').editBy,this.data('editable.options').toEditable);
	if(options=='destroy')
		return  this.unbind(this.data('editable.options').editBy,this.data('editable.options').toEditable)
					.data('editable.previous',null)
					.data('editable.current',null)
					.data('editable.options',null);
	
	var options = $.extend(defaults, options);
	
	options.toEditable = function(){
		$this = $(this);
		$this.data('editable.current',$this.html());
		opts = $this.data('editable.options');
		$.editableFactory[opts.type].toEditable($this.empty(),opts);
		// Configure events,styles for changed content
		$this.data('editable.previous',$this.data('editable.current'))
			 .children()
				 .focus()
				 .addClass(opts.editClass);
		// Submit Event
		if(opts.submit){
			$('<button/>').appendTo($this)
						.html(opts.submit)
						.one('mouseup',function(){opts.toNonEditable($(this).parent(),true)});
		}else
			$this.one(opts.submitBy,function(){opts.toNonEditable($(this),true)})
				 .children()
				 	.one(opts.submitBy,function(){opts.toNonEditable($(this).parent(),true)});
		// Cancel Event
		if(opts.cancel)
			$('<button/>').appendTo($this)
						.html(opts.cancel)
						.one('mouseup',function(){opts.toNonEditable($(this).parent(),false)});
		// Call User Function
		if($.isFunction(opts.onEdit))
			opts.onEdit.apply(	$this,
									[{
										current:$this.data('editable.current'),
										previous:$this.data('editable.previous')
									}]
								);
	}
	options.toNonEditable = function($this,change){
		opts = $this.data('editable.options');
		// Configure events,styles for changed content
		$this.one(opts.editBy,opts.toEditable)
			 .data( 'editable.current',
				    change 
						?$.editableFactory[opts.type].getValue($this,opts)
						:$this.data('editable.current')
					)
			 .html(
				    opts.type=='password'
				   		?'*****'
						:$this.data('editable.current')
					);
		// Call User Function
		var func = null;
		if($.isFunction(opts.onSubmit)&&change==true)
			func = opts.onSubmit;
		else if($.isFunction(opts.onCancel)&&change==false)
			func = opts.onCancel;
		if(func!=null)
			func.apply($this,
						[{
							current:$this.data('editable.current'),
							previous:$this.data('editable.previous')
						}]
					);
	}
	this.data('editable.options',options);
	return  this.one(options.editBy,options.toEditable);
}
$.editableFactory = {
	'text': {
		toEditable: function($this,options){
			$('<input/>').appendTo($this)
						 .val($this.data('editable.current'));
		},
		getValue: function($this,options){
			return $this.children().val();
		}
	},
	'password': {
		toEditable: function($this,options){
			$this.data('editable.current',$this.data('editable.password'));
			$this.data('editable.previous',$this.data('editable.password'));
			$('<input type="password"/>').appendTo($this)
										 .val($this.data('editable.current'));
		},
		getValue: function($this,options){
			$this.data('editable.password',$this.children().val());
			return $this.children().val();
		}
	},
	'textarea': {
		toEditable: function($this,options){
			$('<textarea/>').appendTo($this)
							.val($this.data('editable.current'));
		},
		getValue: function($this,options){
			return $this.children().val();
		}
	},
	'select': {
		toEditable: function($this,options){
			$select = $('<select/>').appendTo($this);
			$.each( options.options,
					function(key,value){
						$('<option/>').appendTo($select)
									.html(value)
									.attr('value',key);
					}
				   )
			$select.children().each(
				function(){
					var opt = $(this);
					if(opt.text()==$this.data('editable.current'))
						return opt.attr('selected', 'selected').text();
				}
			)
		},
		getValue: function($this,options){
			var item = null;
			$('select', $this).children().each(
				function(){
					if($(this).attr('selected'))
						return item = $(this).text();
				}
			)
			return item;
		}
	}
}
})(jQuery);

$(function(){
function begin(){
this.append('<br>Click somewhere else to save changes')
}
function end(content){
alert(content.current+':'+content.previous)
}
//#
$('.editable1').editable({type:'textarea',editClass:'editsomething',onSubmit:submitData,submit:'SAVE CHANGES',options:'extra'});

function submitData(content){
     $.ajax({
         type: 'POST',
         url:  '/editablesave.cfm',
         data: 'where='+location+'&current='+content.current+'&prev='+content.previous,
         success: function(msg){
             alert( 'Data Saved: ' + msg );
         }
     });
 }

});
		
	var fromBoxArray = new Array();
	var toBoxArray = new Array();
	var selectBoxIndex = 0;
	var arrayOfItemsToSelect = new Array();
	
	
	function moveSingleElement()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;
		if(this.tagName.toLowerCase()=='select'){			
			tmpFromBox = this;
			if(tmpFromBox==fromBoxArray[selectBoxIndex])tmpToBox = toBoxArray[selectBoxIndex]; else tmpToBox = fromBoxArray[selectBoxIndex];
		}else{
		
			if(this.value.indexOf('>')>=0){
				tmpFromBox = fromBoxArray[selectBoxIndex];
				tmpToBox = toBoxArray[selectBoxIndex];			
			}else{
				tmpFromBox = toBoxArray[selectBoxIndex];
				tmpToBox = fromBoxArray[selectBoxIndex];	
			}
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			if(tmpFromBox.options[no].selected){
				tmpFromBox.options[no].selected = false;
				tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);
				
				for(var no2=no;no2<(tmpFromBox.options.length-1);no2++){
					tmpFromBox.options[no2].value = tmpFromBox.options[no2+1].value;
					tmpFromBox.options[no2].text = tmpFromBox.options[no2+1].text;
					tmpFromBox.options[no2].selected = tmpFromBox.options[no2+1].selected;
				}
				no = no -1;
				tmpFromBox.options.length = tmpFromBox.options.length-1;
											
			}			
		}
		
		
		var tmpTextArray = new Array();
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpTextArray.push(tmpFromBox.options[no].text + '___' + tmpFromBox.options[no].value);			
		}
		tmpTextArray.sort();
		var tmpTextArray2 = new Array();
		for(var no=0;no<tmpToBox.options.length;no++){
			tmpTextArray2.push(tmpToBox.options[no].text + '___' + tmpToBox.options[no].value);			
		}		
		tmpTextArray2.sort();
		
		for(var no=0;no<tmpTextArray.length;no++){
			var items = tmpTextArray[no].split('___');
			tmpFromBox.options[no] = new Option(items[0],items[1]);
			
		}		
		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			tmpToBox.options[no] = new Option(items[0],items[1]);			
		}
	}
	
	function sortAllElement(boxRef)
	{
		var tmpTextArray2 = new Array();
		for(var no=0;no<boxRef.options.length;no++){
			tmpTextArray2.push(boxRef.options[no].text + '___' + boxRef.options[no].value);			
		}		
		tmpTextArray2.sort();		
		for(var no=0;no<tmpTextArray2.length;no++){
			var items = tmpTextArray2[no].split('___');
			boxRef.options[no] = new Option(items[0],items[1]);			
		}		
		
	}
	function moveAllElements()
	{
		var selectBoxIndex = this.parentNode.parentNode.id.replace(/[^\d]/g,'');
		var tmpFromBox;
		var tmpToBox;		
		if(this.value.indexOf('>')>=0){
			tmpFromBox = fromBoxArray[selectBoxIndex];
			tmpToBox = toBoxArray[selectBoxIndex];			
		}else{
			tmpFromBox = toBoxArray[selectBoxIndex];
			tmpToBox = fromBoxArray[selectBoxIndex];	
		}
		
		for(var no=0;no<tmpFromBox.options.length;no++){
			tmpToBox.options[tmpToBox.options.length] = new Option(tmpFromBox.options[no].text,tmpFromBox.options[no].value);			
		}	
		
		tmpFromBox.options.length=0;
		sortAllElement(tmpToBox);
		
	}
	
	
	/* This function highlights options in the "to-boxes". It is needed if the values should be remembered after submit. Call this function onsubmit for your form */
	function multipleSelectOnSubmit()
	{
		for(var no=0;no<arrayOfItemsToSelect.length;no++){
			var obj = arrayOfItemsToSelect[no];
			for(var no2=0;no2<obj.options.length;no2++){
				obj.options[no2].selected = true;
			}
		}
		
	}
	
	function createMovableOptions(fromBox,toBox,totalWidth,totalHeight,labelLeft,labelRight)
	{		
		fromObj = document.getElementById(fromBox);
		toObj = document.getElementById(toBox);
		
		arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;

		
		fromObj.ondblclick = moveSingleElement;
		toObj.ondblclick = moveSingleElement;

		
		fromBoxArray.push(fromObj);
		toBoxArray.push(toObj);
		
		var parentEl = fromObj.parentNode;
		
		var parentDiv = document.createElement('DIV');
		parentDiv.className='multipleSelectBoxControl';
		parentDiv.id = 'selectBoxGroup' + selectBoxIndex;
		parentDiv.style.width = totalWidth + 'px';
		parentDiv.style.height = totalHeight + 'px';
		parentEl.insertBefore(parentDiv,fromObj);
		
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		fromObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelLeft;
		subDiv.appendChild(label);
		
		subDiv.appendChild(fromObj);
		subDiv.className = 'multipleSelectBoxDiv';
		parentDiv.appendChild(subDiv);
		
		
		var buttonDiv = document.createElement('DIV');
		buttonDiv.style.verticalAlign = 'middle';
		buttonDiv.style.paddingTop = (totalHeight/2) - 50 + 'px';
		buttonDiv.style.width = '30px';
		buttonDiv.style.textAlign = 'center';
		parentDiv.appendChild(buttonDiv);
		
		var buttonRight = document.createElement('INPUT');
		buttonRight.type='button';
		buttonRight.value = '>';
		buttonDiv.appendChild(buttonRight);	
		buttonRight.onclick = moveSingleElement;	
		
		var buttonAllRight = document.createElement('INPUT');
		buttonAllRight.type='button';
		buttonAllRight.value = '>>';
		buttonAllRight.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllRight);		
		
		var buttonLeft = document.createElement('INPUT');
		buttonLeft.style.marginTop='10px';
		buttonLeft.type='button';
		buttonLeft.value = '<';
		buttonLeft.onclick = moveSingleElement;
		buttonDiv.appendChild(buttonLeft);		
		
		var buttonAllLeft = document.createElement('INPUT');
		buttonAllLeft.type='button';
		buttonAllLeft.value = '<<';
		buttonAllLeft.onclick = moveAllElements;
		buttonDiv.appendChild(buttonAllLeft);
		
		var subDiv = document.createElement('DIV');
		subDiv.style.width = (Math.floor(totalWidth/2) - 15) + 'px';
		toObj.style.width = (Math.floor(totalWidth/2) - 15) + 'px';

		var label = document.createElement('SPAN');
		label.innerHTML = labelRight;
		subDiv.appendChild(label);
				
		subDiv.appendChild(toObj);
		parentDiv.appendChild(subDiv);		
		
		toObj.style.height = (totalHeight - label.offsetHeight) + 'px';
		fromObj.style.height = (totalHeight - label.offsetHeight) + 'px';

			
		selectBoxIndex++;
		
	}
