/**
 * @depends libs/livepipe.js
 * @depends libs/window.js
 */
/**
 * Declaration of the global MYID namespace
 * @author Amber-Lee Wolverton <awolverton@ussearch.com>
 */
if (typeof MYID == "undefined") {
    var MYID = {};
}

/**
 * Returns the MYID object for the declare namespaces
 * @author Amber-Lee Wolverton <awolverton@ussearch.com>
 * @method namespace
 * @para {String | Array} anonymous [Accepts a string or an array of strings]
 * @return {Object} reurns the MYID object with the new namespaces
 */
MYID.namespace = function () {
    var a = arguments, o = null, i, j, d;
    for (i = 0; i < a.length; ++i) {
        d = a[i].split(".");
        o = MYID;
        for (j = (d[0] == "MYID") ? 1 : 0; j < d.length; ++j) {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
    return o;
};
/**
 * Initializes creation of namespaces
 * @static
 * @private
 */
(function () {
	MYID.namespace("util","global","local","dynamic", "msg", "debug");
	MYID.global = {
		DB : (decodeURI(window.location.search).indexOf('<<DEBUG>>')!=-1),
		VERSION : '@VERSION@-@COMPILER@',
		PROTOCAL_PREFIX : window.location.protocol ,
		DATE : new Date(),
		BROWSER_TYPE : (function () {
			var y = Prototype.Browser, x;
			for (x in y) {
				if (y[x]) { 
					return x;
				}
			}			
		})()
    }
	if (MYID.global.PROTOCAL_PREFIX == "undefined") {
		MYID.global.PROTOCAL_PREFIX = "http://";
	}
})();



/**
 * This class is used to create dynamic modal windows
 @author Amber-Lee Wolverton <awolverton@ussearch.com>
 @namespace MYID.dynamic
 @class GenericModalWindow
 */
MYID.dynamic.GenericModalWindow = Class.create({
/** This is the initial method that is called when an new object is instiated
 * @method initialize
 * @param {Object} _container Link element with an href. For an element that 
 * exists on the page, the href should point to #(elementId); for an ajax call 
 * the link should be in the href, for an iframe, a link should be in the href 
 * and the optional parameter of {iframe:true}
 * @param {Object} _options Optional object containing all options that should 
 * be associated with this call. See livepipe documentation for possible options. 
 * NOTE:  passing className, closeOnClick, draggable, insertRemoteContentAt 
 * and afterOpen will overide the default actions of this function and you 
 * may want to consider calling Control.Modal instead.
 * @param {boolean} _cache Optional parameter that states whether or not 
 * to cache window. True by default 
 */    
	initialize : function (_container, _options, _cache) {
		this.cacheAjax = (typeof _cache != "undefined") ? _cache : false;
		var _options = (typeof _options != "undefined") ? _options : {};
        this.window_header = new Element('div', {
            className : 'myid-modal-border'
        });
       this.window_close = new Element('div', {
            className : 'myid-modal-close-btn'
        });
		this.window_contents = new Element('div', {
            className : 'myid-modal-container'
        });
		this.autoClose = (typeof _options.autoClose != 'undefined') ? _options.autoClose : false;
        this.w = new Control.Modal(_container, Object.extend({
            className : 'myid-dyn-modal-window',
            closeOnClick : this.window_close,
            insertRemoteContentAt : this.window_contents,
			iframeshim : false,
            afterOpen : function () {
                this.w.position();
                if (!this.cacheAjax) {
                    this.w.remoteContentLoaded = false;
                }
            }.bind(this)
        }, _options || {}));
		if (!this.cacheAjax) {
            this.w._observers.afterClose[1] = function(){
                this.window_contents.update();
            }.bind(this);
        };


        if (!this.autoClose) {
			this.window_header.insert(this.window_close);
		}
		this.window_header.insert(this.window_contents);
        if ((_options.iframe) && (MYID.global.browser = "Gecko")) { 
            this.window_contents.setStyle({
                height : '90%'
            });
		}
			
       this.w.container.insert({
			top :this.window_header
		});
		MYID.debug.info((typeof _container != 'object'))

		if(typeof _container != 'object'){
			MYID.debug.log((_container.indexOf('http') > -1));
			if (_container.indexOf('http') > -1) {
				this.w.open();
			}
		}	
	}
});



MYID.util.trackingAjax = function (_url) {
	/**
	 * Takes a url and makes an ajax call for tracking purposes,
	 * there is no action taken on the reponse text
	 * @author Amber-Lee Wolverton <awolverton@ussearch.com>
	 * @namespace MYID.util
	 * @method trackingAjax
	 * @param {String} _url The ajax url
	 * @return {Object | Boolean} will return the xmlHttp object or false if not supported
	 */
	var _xmlhttp;
	/*Creates the request object*/
	if (window.XMLHttpRequest) { 
		_xmlhttp = new XMLHttpRequest();
  	} else if (window.ActiveXObject) {
		/* For later than  IE7 */
  		_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	} else {
		return false;
	}
	_xmlhttp.onreadystatechange = function () {
		if(_xmlhttp.readyState == 4) {
			//MYIDDev.log('MYID.util.trackingAjax readyState SUCCESS');
		}
	}
	_xmlhttp.open("GET", _url, true);
	_xmlhttp.send(null);
	return _xmlhttp;
}

/**
 * This method dynamically loads a javascript using a non-blocking method
 * than runs the callback methof once loaded
 * @author ALW
 * @namespace MYID.util
 * @method loadScript
 * @param {Stirng} _url URL of file to be loaded
 * @param {Function} _callback name of function to call on  load
 */
MYID.util.loadScript = function (_url, _callback) {
	var n = document.getElementsByTagName('head')[0];
	var s = document.createElement('script');
	s.type = 'text/javascript';
	s.src = _url;
	if (_callback) {
	    s.onerror = s.onload = _callback; //firefox
	    s.onreadystatechange = function () { //for IE
	        if (this.readyState == "complete" || this.readyState == "loaded") {
	            _callback();
	        }
	    }
	}
	n.appendChild(s);

};

MYID.util.dateObject = {
	/**
	 * This is a date object and contains pieces needed to 
	 * format date
	 *  @author Amber-Lee Wolverton <awolverton@ussearch.com>
	 *  @namespace MYID.util
	 *  @object dateObject
	 */	
 	currentDate : MYID.global.DATE,
	currentMonth : MYID.global.DATE.getMonth() + 1,
	currentDay : MYID.global.DATE.getDate(),
	currentYear : MYID.global.DATE.getFullYear(),
	monthNames : ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'],
	/*
	 * This method returns the date formated
	 * @method getFormatedDate
	 * @param {String} _format Sting containing format request
	 * @return {String} The current date in formated string
	 */
	getFormatedDate : function (_format) {
		switch (_format) {
		/*
		 * TODO: Add other formats 
		 */
		case "MM/DD/YY":
			if (this.currentMonth.length > 1){
				this.currentMonth = '0' + this.currentMonth;
			}
			return (this.currentMonth + "/" + this.currentDay + "/" + this.currentYear);
			
		default:
			throw "Must Pass a Format";
		}
	},
	getMonthName : function () {
		return MYID.util.dateObject.monthNames[MYID.util.dateObject.currentMonth-1];
	}
	 
}

/**
 * This class is for all phone number search forms with three fields
 * @author ALW
 * @namespace MYID.util
 * @class AdvanceMe
 */
MYID.util.AdvanceMe = Class.create({
	/**
	 * This method is initialized when a new instance of the AdvanceMe
	 * class is instantiated.
	 * @method initialize
	 */
	initialize : function () {
		this.inputs = $$('.myid-js-advance-field'); //gets all inputs with myid-js-advance-field class
		this.inputs.each(function (_input) {
			MYID.debug.log("this is %o", this);
			_input.observe('keyup', this.handleKeyUp.bind(this));
			_input.observe('keydown', this.handleKeyDown.bind(this));
		}.bind(this));
	},
	/**
	 * This method is called when the user inputs data and 
	 * is called on keyup
	 * @param {Object} _ev This is an EVENT object which is passed by 
	 * the observer
	 */
	handleKeyUp : function (_ev) {
		MYID.debug.info("arguments %o", arguments);
		var _input = Event.element(_ev);
		var _maxLength = _input.getAttribute('maxlength');
		var _valueLength = $F(_input).length + this._increm;
		var _keyCode = _ev.keyCode;
		switch (_keyCode) {
		case 16:
			break;
		case 9: 
			break;
		case 39: 
			break;
		case 37:
			break;
		case 8:
			if (_valueLength == 0) {
	  		_input.previous('input').focus();
	  	}
			break;
			default:
				MYID.debug.info(_input.next('input') != null);
				if (_maxLength == _valueLength) {
					if (_input.next('input') != null) {
						_input.next('input').focus();
					}
				} 
		}
	},
	handleKeyDown : function (_ev) {
		MYID.debug.log("arguments %o", arguments);
		var _input = Event.element(_ev);
		MYID.debug.log('keycode on key down is %s, value %s, length %s', _ev.keyCode, _input.value, _input.value.length );	
		this._increm = 0;
		if(_input.value.length == 1 && _ev.keyCode == 8){
			this._increm = -1;
		}
	}
});


/*----------------------
 Ajax Form Submit
 How to use
 myAjax = new MYID.ajaxFormSubmit(theForm,theUpdateContainer,{options}
 Available Options:
 - method
 - parameters
 - onCreate
 - onComplete
 - onSuccess
 - onFailure
 - onException
 - callBack
 -------------------------------*/
MYID.dynamic.AjaxFormSubmit = Class.create({
	/**
	 * This method initialtes to AjaxSubmitForm Object
	 * @method initialize
	 * @param {String | Object} _form ID of form to preform submit
	 * @param {String | Object} _container ID of container to update
	 * @param {Object} _options Optional options
	 */
    initialize : function (_form, _container, _options) {
		this.form = (typeof _form == "string") ? $(_form) : _form;
        this.container = (typeof _container == "string") ? $(_container) : _container;
        this.options = Object.extend({
            method : 'post',
            parameters : {},
            onCreate : Prototype.emptyFunction,
            onComplete : this.update.bind(this),
            onSuccess : Prototype.emptyFunction,
            onFailure : Prototype.emptyFunction,
            onException : Prototype.emptyFunction,
			evalScripts : false,
            callBack : Prototype.emptyFunction,
            validateFunc : false,
            autoSubmit : false,
			scode : false
        }, _options || {});
		if (this.options.autoSubmit) {
            this.submitSearch();
        }
        Event.observe(this.form, 'submit', this.submitSearch.bindAsEventListener(this));
        
    },
    submitSearch : function (_ev) {
		if (typeof _ev != "undefined") {
        	Event.stop(_ev);
        }
        if (!this.options.validateFunc) {
            this.form.request(this.options);
        } else {
			if(this.options.validateFunc(this.form)){
				this.form.request(this.options);
			}
		}
    },
    update : function(_transport){
        this.container.update(_transport.responseText);
        this.options.callBack.apply(this);
        if (this.options.scode) {
			MYID.util.ajscode();
		}
    }
});


MYID.dynamic.dashboardNav = function (_id) {
	var _li = $('myid-navigation').select('li');
	_li.invoke('removeClassName', 'myid-active');
	$(_id).addClassName('myid-active');
}

MYID.dynamic.ajaxMenu = function () {
	$$('.myid-js-ajax-links').each(function(_el) {
		_el.observe('click', function (_ev) {
			var _el2 = Event.element(_ev);
			Event.stop(_ev);
			new Ajax.Updater($('myid-dashboard-container'), _el2.href);
			var b = $('myid-dashboard-heading').select('li');
			var q = _el2.href.split('=');
			b.invoke('removeClassName', 'myid-current');
			for(var x = 0, l = b.length; x<l; x++){
				if(b[x].down('a').href.match(q[1])){
				    b[x].addClassName('myid-current')
				}
			}
		});
	})
}

/**
 * This class is to open the static alerts inside of the report
 * @author ALW
 * @namespace MYID.dynamic
 * @class staticModal
 */
MYID.dynamic.StaticModal = Class.create({
	/**
	 * This method intializes the class. On click, an instance of this
	 * class is generated an the element clicked on is passed
	 * @method initialize
	 * @param {HTML Element} _el Element clicked on
	 */
	initialize : function (_el) {
		_el = ( _el.hasAttribute('href')) ? _el : _el.up('a'); // this checks for the link incase the image is the passed element 
		var _elId = _el.href.indexOf('#') + 1; // parse out the id in the href
		var _elId = _el.href.substring(_elId); // assign element id
		this.createMarkUp(_elId);
	},
	/**
	 * This method create the markup to make the modal window than inserts the content of the appropriate 
	 * div in to the window
	 * @param {String} _id Id of element from href
	 */
	createMarkUp : function (_id) {
		this.windowHeader = new Element('div', {
            className : 'myid-modal-border'
        });
       this.windowClose = new Element('div', {
            className : 'myid-modal-close-btn'
        });
		this.windowContents = new Element('div', {
            className : 'myid-modal-container'
        });
		this.windowContainer = new Element('div');
		this.windowHeader.insert(this.windowClose); 
		var _cloneNode = $(_id).cloneNode(true); //don't want to lose it when the user closes the window
		_cloneNode.show(); // Show it
		this.windowContents.insert(_cloneNode); //Place it in the window
		this.windowHeader.insert(this.windowContents);
		this.windowContainer.insert(this.windowHeader);
		$(document.body).insert(this.windowContainer); //insert the window into the doc
		this.modalWindow = new Control.Modal(this.windowContainer, { //make modal window class call
			className : 'myid-dyn-modal-window',
            closeOnClick : this.windowClose,
			fade : true,
			afterClose : function () {
				this.destroy(); //destroy it
			}
        });
		this.modalWindow.open(); //Now open window
		MYID.global.modal[_id] = this.modalWindow;
	}
});

/**
 * This function is called when the dashboard loads the report and it 
 * attach as the appropriate events for the dashboard.
 * @author ALW
 * @namespace MYID.dynamic
 * @function manageWindows
 * @param {Object} _options Options that will be passed by the modal window functions
 */
MYID.dynamic.manageWindows = function (_options) {
	var options = (_options != null) ? _options : {}; //incase options are null
	MYID.global.modal = {}; //sets a global modal window var
	MYID.debug.info("$$('.myid-js-modal-link') is %o", $$('.myid-js-modal-link'))
	
$$('.myid-js-modal-link').each(function (_el) { //for each link that has the CSS Class myid-js-modal-link ...
        try { //try 
            if (_el.id != 'edit_ssn') { //don't do this for SSN
            	options.method='GET';
				MYID.global.modal[_el.id] = new MYID.dynamic.GenericModalWindow(_el, options, false); //new generic modal window and add it to the global modal object
			};
        } catch (e) {
        	MYID.debug.warn(e.message); //alert error
        };
   });
 MYID.global.modal.edit_ssn = new MYID.dynamic.GenericModalWindow($('edit_ssn'), { //for the edit social security window ...
        fade : true,
		method : 'GET',
		beforeOpen : function (){
			MYID.dashboard.activeWindow =  this;
		}
   });

}

/**
 * Loads the dynamic loading for the report update
 * @author ALW
 * @namespace MYID.util
 * @function ajaxLoading
 */
MYID.dynamic.ajaxLoading = function () {
	var _el = new Element('div', {
		className : 'myid-dyn-ajaxLoading-70' //class is in global style sheet
	});
	_el.update('<p>Updating...</p>'); 
	return _el;
}

/**
 * This function is used by the articles inside the dashboard cms to load the appropriate article
 * @author CG
 * @namespace MYID.util
 * @function getArticleURL
 * @param {String} _articleName Name of article as it coresponds to the source name is the CMS
 */
MYID.util.getArticleURL = function (_articleName) {
	new Ajax.Updater($('myid-dashboard-container'), window.location.protocol + '//' + window.location.host +'/cmsDashboard.html?cmsID=' + _articleName);
}


/**
 * This function checks for required fields and does validation based on CSS class names.
 * @author ALW
 * @namespace MYID.util
 * @function requiredFields
 * @param {Object | Array} _elements Array of form elements 
 */
MYID.util.requiredFields = function (_elements) {
	MYID.debug.info('all elements: %o', _elements);
	var _elements = _elements.findAll(function (_element) { //search for all required elements
		return _element.className.match(/required/g);
	});
	MYID.debug.info('required elements: %o', _elements);
	var _errors = []; //reset errors;
	_elements.each(function (_element) { //for each required element ...
		var _value = $F(_element); //... get it's value
		if (_value != null) { //if it's not null ... 
			if( _value.length > 0) { // ... and it's length is greater than 0 ...
				var _validations = _element.className.match(/isValid\w+/g); //find all the validations classes
				MYID.debug.log('$%o is the element and %o is the validations', _element, _validations)
				if (_validations != null) { //if there are validation classes ...
					_validations.each(function (_validation) { // for each validation ...
						if (_element[_validation] && !_element[_validation]()) { // ... if the validation exists and it returns false ...
							_errors.push({'el' : _element, 'val' : _validation}); //... push the element and is validation error to the error array
							throw $break; // Stop checking
						};
					});
				};	
			} else { //... if the length is 0 then ...
				_errors.push({'el' : _element, 'val' : 'empty'}); //... push the element and is validation error of empty to the error array
				throw $break;
			};
		} else { //if the value is null...
			_errors.push({'el' : _element, 'val' : 'empty'}); //... push the element and is validation error of empty to the error array
		};
	});
	return _errors; //return the errors array
};

/**
 * This class is used to create form validation that stops on the firs error. Validation 
 * is based on an errorMessage object that is passed which contains objects  named after 
 * the name of the input field, with the message assigned to the type of error. empty is 
 * the result of required.
 * @author ALW
 * @namespace MYID.util
 * @class FormValidation
 * @dependencies MYID.util.requiredFields
 */
MYID.util.FormValidation = Class.create({
	/**
	 * This method sets the options passed and attaches an observe to the form passed to it.
	 * @method initialize
	 * @param {Object} _form The form to be validated
	 * @param {Object} _errorMessages The object that holds the error messages 
	 * {fieldName : {empty:'Empty Message', validationPreformed:'Validation Specific Message' ...}, fieldName2 : {...}}
	 * empty is ALWAYS required
	 * @param {Object} _callback* If a callback is passed, the form action will stop and the form will be
	 * passed as a variable to the callback function
	 */
    initialize : function (_form, _errorMessages, _callback, _noObserve) { //Pass form element and the error messages object
        this.errorMess = _errorMessages;
        this.form = _form;
        this.callback = (typeof _callback != 'undefined') ? _callback : false;
		this.noObserve = (typeof _noObserve != 'undefined') ? _noObserve : false;
        if (!this.noObserve) {
			this.form.observe('submit', this.runValidation.bindAsEventListener(this));
		} else {
			this.runValidation();
		}
    },
	/**
	 * This is called on submit. It form elements to the MYID.util.requiredFields function.
	 * If it returns an array of errors, then it attachs the validation error css class, then
	 * it stops the event and alerts the first error. If no error, then checks if there is a
	 * callback. If a call back exists, the form event stops and the form is passed to the callback, 
	 * otherwise, submit continues.
	 * @param {Object} _ev The submit event
	 */
    runValidation : function (_ev) {
		this.elements = this.form.getElements(); //Get all the form elements
	    this.elements.invoke('removeClassName', 'myid-dyn-validation-error'); //Reset previous validation errors
	    this.myReturn = MYID.util.requiredFields(this.elements); //Pass elements to validation function
	    if (this.myReturn.length > 0) { //if the array has errors
			if (typeof _ev != 'undefined') {
				Event.stop(_ev);
			}; 
            this.myReturn[0]['el'].addClassName('myid-dyn-validation-error'); //Attach the error css class
            var _elementName = this.myReturn[0]['el'].name; //Get the name of the element
            var _elementError = this.myReturn[0]['val']; //Get the validation error
            var _mess = (typeof this.errorMess[_elementName] != 'undefined') ? this.errorMess[_elementName][_elementError] : 'Error Occured'; //If the error object exists for the name object, then assign that message else assign a generic message
            alert (_mess);
            this.myReturn[0]['el'].focus(); //place focus onto that element
        } else {
            if (this.callback) { //if there is a callback 
				if (typeof _ev != 'undefined') {
					Event.stop(_ev);//stop event
				}; 
				this.callback(this.form); //pass form to callback
			};
        };
    }
});

/**
 * Function for find password
 * @author cg
 * @namespace MYID.dynamic
 * @function findPass
 * @dependencies MYID.dynamic.GenericModalWindow, MYID.util.FormValidation
 */
MYID.dynamic.findPass = function(){
	var _errorMess = {
		fname : {
			empty : 'First Name is required',
			isValidAlpha : 'Please enter a valid First Name'
		},
		lname : {
			empty : 'Last Name is required',
			isValidAlpha : 'Please enter a valid Last Name'
		},
		username : {
			empty : 'User Name is required'
		},
		securityAnswer : {
			empty : 'Security Answer is required'
		},
		email : {
			empty : 'Email is required',
			isValidEmail : 'This is not a valid Email Address'
		},
		password : {
			empty : 'Password is required'
		}
	};
	MYID.dynamic.findPassModal = new MYID.dynamic.GenericModalWindow(window.location.protocol + '//' + window.location.host + '/findPass.html', {
		fade : true,
		method : 'GET',
		autoClose : false,
		afterOpen :	function () {
			new MYID.util.FormValidation($$('form')[1], _errorMess, function (_form) {
				_form.request({
					onComplete : function(_trans){
						$('myid-find-pass-wrapper').update(_trans.responseText);
						new MYID.util.FormValidation($('myid-js-security-form'), _errorMess, function (_form){
							_form.request({
								onComplete : function(_trans){
									$('myid-find-pass-wrapper').update(_trans.responseText);
								}
							})
						});
					}
			});
		});
	}
});
}

/**
 * Function for find username
 * @author cg
 * @namespace MYID.dynamic
 * @function findUserName
 * @dependencies MYID.dynamic.GenericModalWindow, MYID.util.FormValidation
 */
MYID.dynamic.findUserName = function(){
	var _errorMess = {
		fname : {
			empty : 'First Name is required',
			isValidAlpha : 'Please enter a valid First Name'
		},
		lname : {
			empty : 'Last Name is required',
			isValidAlpha : 'Please enter a valid Last Name'
		},
		username : {
			empty : 'User Name is required'
		},
		securityAnswer : {
			empty : 'Security Answer is required'
		},
		email : {
			empty : 'Email is required',
			isValidEmail : 'This is not a valid Email Address'
		},
		password : {
			empty : 'Password is required'
		}
	};	
	MYID.dynamic.userNameModal = new MYID.dynamic.GenericModalWindow(window.location.protocol + '//' + window.location.host + '/findUser.html', {								
		fade : true,
		method : 'GET',
		autoClose : false,
		afterOpen :	function () {
			new MYID.util.FormValidation($$('form')[1], _errorMess, function (_form) {
				_form.request({					
					onComplete : function(_trans){
						$('myid-find-pass-wrapper').update(_trans.responseText);
						new MYID.util.FormValidation($('myid-js-security-form'), _errorMess);
					}
				})
			});
		}			
	});
}


MYID.dynamic.contactUs = function (_ev) {
	Event.stop(_ev);
	var _errorMess = {
		name : {
			empty : 'Please enter your Name',
			isValidAlpha : 'Please enter a valid Name'
		},
		areaCode : {
			empty : 'Valid Phone Number is required',
			isValidInteger : 'Please enter only numbers',
			isValidLength : 'Must be 3 digits'
		},
		exchange : {
			empty : 'Valid Phone Number is required',
			isValidInteger : 'Please enter only numbers',
			isValidLength : 'Must be 3 digits'
		},
		number : {
			empty : 'Valid Phone Number is required',
			isValidInteger : 'Please enter only numbers',
			isValidLength : 'Must be 4 digits'
		},
		email : {
			empty : 'Email Address is Required',
			isValidEmail : 'Please enter a valid Email'
		},
		subject : {
			empty : 'Please Select a Question'
		},
		comments : {
			empty : 'Please enter your Comments'
		}
	};
	var _afterOpen = function (){
		$('myid-js-textarea').observe('keyup', function (_ev){
			var _keyNum = 750;
			_el = Event.element(_ev);
			if ($F(_el).length < (_keyNum + 1)) {
				$('myid-js-max-char').update();
			};
			if ($F(_el).length >= _keyNum) {
				_el.value = $F(_el).substring(0, _keyNum);
				$('myid-js-max-char').update('Character Limit Reached');
			}
		})
		
		new MYID.util.FormValidation($('myid-js-contact-form'), _errorMess, function(_form){
				_form.request({
					onSuccess : function (_trans) {
						$('myid-js-contactus-form-container').replace(_trans.responseText);
						_afterOpen();
					}
				});
			})
	}
	MYID.global.CONTACTWIN = new MYID.dynamic.GenericModalWindow(window.location.protocol + '//' + window.location.host +'/contactUs.html', {
		method : 'GET',
		fade : true,
		afterOpen : _afterOpen
	});	
}

MYID.dynamic.footerLinks = function(_el){
	window.open(_el.href, _el.title, 'width=650,height=400,scrollbars=yes,toolbar=no,directories=no,status=no,menubar=yes,resizable=yes');
	return false;
	
}

/*FORM ELEMENTS EXTENSIONS*/
MYID.namespace('methods');
MYID.methods.inputElements = {
	isModified : function (element) {
	    return !!element.className.match(/mod/); 
  	},
	isValidEmail : function (element) {
	    return !!$F(element).match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/); 
  	},
	isValidInteger : function (element) {
		return !!$F(element).match(/(^-?\d+$)/);
  	},
  	isValidNumeric : function (element) {
    	return !!$F(element).match(/(^-?\d\d*[\.|,]\d*$)|(^-?\d\d*$)|(^-?[\.|,]\d\d*$)/);
  	},
  	isValidAlphaNumeric : function (element) {
		return !!$F(element).match(/^[_\-\sa-z0-9]+$/gi);
	},
	isValidAlpha : function (element) {
		return !!$F(element).match(/^[a-z_ '-]+$/gi);
  	},
	isValidPhone : function (element) {
		var x = $F(element).replace(/\D/g, "");
		$(element).value = x;/*AT SOME POINT THIS WILL BE PART OF A FORMATING CLASS*/
		return x.match(/\d{10}/) && true || false;
	},
	isValidZipCode : function (element) {
		var x = $F(element);/*.replace(/\D/g, "");*/
		return x.match(/^\d{5}\-?\d{4}$|^\d{5}$/) && true || false;
 	},
	isValidStreet : function (element) {
		return $F(element).match(/(^\d+) ([0-9a-zA-Z]+)/);
	},
	isValidPassword : function (element) {
		/*var _val = $F(element);
		var _validation = _val.match(/^[_\-a-z0-9]+$/);
		if (_validation) {
			var c = 0;
			for(x = 0, l=_val.length; x < l; x++){
   				if(_val.charAt(x).match(/\d/)){
        			c++
    			}
			}
			_validation = (c > 1);  
		}
		return _validation;*/
		return true;
	},
	isValidPasswordLength : function (element) {
		return ($F(element).length > 7 && $F(element).length < 15);
	},
	isValidMatch : function (element) {
		var _val = $F(element)
		var _q = element.className;
		var _l = _q.indexOf('isValidMatch-')+13;
		var _name = _q.substring(_l);
		_name = _name.split(' ');
		var _compareTo = $F(document.getElementsByName(_name[0])[0]);
		MYID.debug.log(_compareTo);
		return (_val === _compareTo)
	},
	isValidUsernameLength : function (element) {
		return ($F(element).length > 5);
	},
	isValidCreditCardNum : function (_element) {
		return ($F(_element).length > 14);
	},
	isValidCVVNum : function (_element) {
		//return ($F(_element).length > 2 && $F(_element).length < 5);
		var _x = $F(_element);
		return _x.match(/(^-?\d+$)/) && (_x.length > 2 && _x.length < 5) && true || false
	},
	isValidLength : function (_element) {
		var _val = $F(_element)
		var _q = _element.className;
		var _l = _q.indexOf('isValidLength-')+14;
		var _name = _q.substring(_l);
		_name = _name.split(' ');
		var _length = parseInt(_name[0]);
		MYID.debug.log(_length);
		return (_val.length == _length);	
	}
}
Element.addMethods('INPUT', MYID.methods.inputElements);

if(unescape(window.location.search).indexOf('<<DEBUG>>')!=-1){
	MYID.util.loadScript(window.location.protocol+'//'+window.location.host+'/includes/js/test/testTools.js');
}


document.observe("dom:loaded", function() {

	try {
		$$('.myid-js-contact-us-link').invoke('observe', 'click', MYID.dynamic.contactUs);
	} catch (e) {
		MYID.debug.warn(e.message);
	}
});
Ajax.Responders.register({
	
	onComplete:function(_obj){
		try{

			if(_obj.transport.status==500){
				$$('.myid-modal-container').invoke('update', ' ');
				alert('Your Session Has Timed Out');
				window.location = 'http://www.usidentityshield.com/logout.html';
			}
			new MYID.util.AdvanceMe();
			}catch(e){alert(e.message)}
			}
	});
(function () {
	if (typeof console != "undefined" && MYID.global.DB === true){
	MYID.debug.log = console.log;
	MYID.debug.debug = console.debug;
	MYID.debug.info = console.info;
	MYID.debug.warn = console.warn;
	MYID.debug.error = console.error;
	MYID.debug.assert = console.assert;
	MYID.debug.dir = console.dir;
	MYID.debug.trace = console.trace;
	MYID.debug.group = console.group;
	MYID.debug.groupEnd = console.groupEnd;
	MYID.debug.time = console.time;
	MYID.debug.timeEnd = console.timeEnd;
	MYID.debug.profile = console.profile;
	MYID.debug.profileEnd = console.profileEnd;
	MYID.debug.count = console.count;
	MYID.debug.clear = console.clear;
} else {
	MYID.debug.log = function () {};
	MYID.debug.debug = function () {};
	MYID.debug.info = function () {};
	MYID.debug.warn = function () {};
	MYID.debug.error = function () {};
	MYID.debug.assert = function () {};
	MYID.debug.dir = function () {};
	MYID.debug.trace = function () {};
	MYID.debug.group = function () {};
	MYID.debug.groupEnd = function () {};
	MYID.debug.time = function () {};
	MYID.debug.timeEnd = function () {};
	MYID.debug.profile = function () {};
	MYID.debug.profileEnd = function () {};
	MYID.debug.count = function () {};
	MYID.debug.clear = function () {};
}
})()



MYID.global.ERRORMESS = {
	customerEmail: {
		empty: 'Please enter your Email Address',
		isValidEmail: 'Please enter a valid Email Address'
	},
	loginEmail: {
		empty: 'Please enter your User Name',
		isValidAlphaNumeric: 'Please a valid User Name',
		isValidUsernameLength: 'Your User Name must contain at least 6 characters'
	},
	loginConfirmEmail: {
		empty: 'Please confirm your Username',
		isValidMatch: 'Usernames do not match'
	},
	loginPassword: {
		empty: 'Please enter your Password',
		isValidPasswordLength: 'Please limit your Password between 8 - 14 characters'
	},
	loginConfirmPassword: {
		empty: 'Please confirm your Password',
		isValidMatch: 'Passwords do not match'
	},
	longinQuestion: {
		empty: 'Please select your Security Question'
	},
	loginAnswer: {
		empty: 'Please enter your Security Answer'
	},
	cardNumber: {
		empty: 'Please enter your Credit Card Number',
		isValidNumeric: 'Please enter your Credit Card Number',
		isValidCreditCardNum: 'Please limit your Credit Card to 16 digits'
	},
	cardSecurity: {
		empty: 'Please select your credit Card Security Code (CVV)',
		isValidNumeric: 'Please select your credit Card Security Code (CVV)',
		isValidCVVNum: 'Please limit your credit Card Security Code (CVV) to 3 or 4 characters'
	},
	cardName: {
		empty: 'Please enter the name as it appears on the Credit Card',
		isValidAlpha: 'Please enter the name as it appears on the Credit Card'
	},
	billingAddress: {
		empty: 'Please enter your Billing Address',
		isValidStreet: 'Please enter your Billing Address'
	},
	billingCity: {
		empty: 'Please enter your Billing City',
		isValidAlpaha: 'Please enter your Billing City'
	},
	billingZip: {
		empty: 'Please enter your Billing Zip Code',
		isValidNumeric: 'Please enter your USA Billing Zip Code',
		isValidZipCode: 'Please limit your Zip Code to 5 characters'
	},
	billingPhoneArea: {
		empty: 'Please enter your Billing Phone Number',
		isValidNumeric: 'Please enter your Billing Phone Number',
		isValidLength: 'Please enter your Billing Phone Number'
	},
	billingPhoneExchange: {
		empty: 'Please enter your Billing Phone Number',
		isValidNumeric: 'Please enter your Billing Phone Number',
		isValidLength: 'Please enter your Billing Phone Number'
	},
	billingPhoneNumber: {
		empty: 'Please enter your Billing Phone Number',
		isValidNumeric: 'Please enter your Billing Phone Number',
		isValidLength: 'Please enter your Billing Phone Number'
	},
	acceptTerms: {
		empty: 'You must agree to the Terms and Condtions to Continue'
	}
}



MYID.util.ie6PngFix = function () {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	      {
	         var imgID = (img.id) ? "id='" + img.id + "' " : ""
	         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	         var imgStyle = "display:inline-block;" + img.style.cssText 
	         if (img.align == "left") imgStyle = "float:left;" + imgStyle
	         if (img.align == "right") imgStyle = "float:right;" + imgStyle
	         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	         var strNewHTML = "<span " + imgID + imgClass + imgTitle
	         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
	         img.outerHTML = strNewHTML
	         i = i-1
	      }
	   }
	}
}
