/*
********************************************************************************
* 
* ONLOAD.JS
* Framework Interface
* 
* v2.0 (April 14, 2008)
* 
********************************************************************************
*/
function $INIT() { with (p)
{
	if (DCO.PG_IS_WINDOW) void(0);
	else
	{
		p.INNER	= $E('Inner');
		p.GC	= $E('generic-contact');
	}
	
	GC.FORM		= GC.getElementsByTagName('form')[0];
	GC.FORM.b	= GC.FORM.getElementsByTagName('img')[0];
	
	with (GC)
	{
		FORM.b.onclick	= function(){p.GC.FORM.Begin()};
		FORM.Mark		= function(obj){with(obj)className=_classname+' marked'};
		FORM.Unmark		= function(obj){with(obj)className=_classname};
		
		FORM.Begin=function() { with (this)
		{
			if (isReady())
			{
				var url = [];
				
				for (var f in e) { with (e[f])
				{
					if (isEmpty(e[f].name)) continue;
					else
					{
						url.push(
							name + '=' + value.replace(/'/,"\\'").replace(/&/g,'%26')
							)
					}
				}
				}
				
				var data=
				{
					subj	: null,
					meth	: 'REQUEST_INFO',
					http	: url.join('&'),
					delay	: 0,
					wait	: 0,
					call	: null
				}
				
				_jSend(data);
				
				{
					var msg=[];
						msg.push('<h6>Thank you for your inquiry!</h6>');
						msg.push('<h5>One of our representatives will be contacting you shortly.</h5>');
						msg=msg.join("\n");
					
					DCO.Say(msg)
				}
				
				Reset()
			}
			else
			{
				var msg=[];
					msg.push('<h6><span class="x-alert">Unable to Send</span></h6>');
					msg.push('<h5>Please enter your name and phone number or email address.</h5>');
					msg=msg.join("\n");
				
				DCO.Say(msg)
			}
		}
		};
		
		FORM.Reset=function() { with (this)
		{
			{
				this.reset()
			}
			
			for (var f in e) Unmark(e[f]);
		}
		};
		
		FORM.Sanitize=function()
		{
			for (var f in this.e) { with (this.e[f])
			{
				switch (nodeName)
				{
					case 'INPUT'	: value = sanitize(value); break;
					case 'TEXTAREA'	: value = ltrim(rtrim(value)); break;
				}
			}
			}
		};
		
		FORM.isReady=function()
		{
			var fail = false;
			var mark = false;
			
			for (var f in this.e) { with (this.e[f])
			{
				switch (nodeName)
				{
					case 'INPUT':
					switch (name)
					{
						default				: mark = (is_required && isEmpty(value)); break;
						case 'c_email'		: mark = (is_required && (isEmpty(value) || !isEmail(value))); break;
						
						case 'c_contact':
						if (
						  is_required
						  && (isEmpty(value) || (!isEmail(value) && !/\d{7,11}/.test(toNumber(value)))))
						{
							mark = true
						}
						break;
					}
					break;
					
					case 'SELECT':
					mark = (is_required && isEmpty(_String())); break;
					break;
				}
				
				if (mark)
				{
					if (!fail)
					{
						fail = true
					}
					
					this.Mark(this.e[f])
				}
			}
			}
			
			return !fail
		};
		
		for (var f in FORM.e)
		{
			if (!isEmpty(FORM.e[f]._classname))
			{
				var Obj				= FORM.e[f];
					Obj.is_required	= (Obj._classname && !isEmpty(Obj._classname) && /^req\s/.test(Obj._classname));
				
				switch (Obj.nodeName)
				{
					case 'INPUT':
					if (Obj.type == 'text')
					{
						Obj.onblur	= function(){with(this)value=sanitize(value)};
						Obj.onfocus	= function(){p.GC.FORM.Unmark(this)};
					}
					break;
				}
			}
		}
		
		$__AJAXIFY(FORM)
	}
}
};
