

/* This function call is specific to EW */
tii_callFunctionOnWindowLoad (function ()
	{
		var popup_form = document.getElementById ('popupform');
		if (popup_form)
		{
			var popup_form_validation = new tii_ValidatedForm (popup_form);
		}
		var cancelAndClose = document.getElementById ('cancelandclose');
		if (cancelAndClose)
		{
			function cancelAndCloseWindow (event)
			{
				if ((event.type == 'keydown' || event.type == 'keypress') && event.keyCode != 13)
				{
					return false;
				}
				window.close ();
			}
			tii_addEventHandler (cancelAndClose, 'click', cancelAndCloseWindow, false);
			var keyevent = ew_issafari || ew_isie ? 'keydown' : 'keypress';
			tii_addEventHandler (cancelAndClose, keyevent, cancelAndCloseWindow, false);
		}
	});

/* Override default declaration with this one */
tii_ValidatedForm.prototype.printErrors=function ()
{
	var parent=this.invalid [0].node.parentNode;
	this.invalid [0].element.focus ();
	if (this.msg != null)
	{
		parent.parentNode.removeChild (this.msg);
	}
	this.msg=document.createElement ("ul");
	this.msg.className="errormessage";
	parent.parentNode.insertBefore (this.msg, parent);
	var message="<li><h3>WE'RE SORRY, we need you to correct or provide more information</h3></li>";
	for (var i=0; i<this.invalid.length; i++)
	{
		var item=this.invalid [i];
		message += "<li><label for=" + item.element.id + ">" + item.name + ":</label> " + item.message + "</li>";
	}
	this.msg.innerHTML = message;
}

/* Override the default declaration */
tii_ValidatedItem.prototype.updateCharLeft=function(e){
	if(this.updating||this.max==Number.POSITIVE_INFINITY)return;
	this.updating=true;
	var curr=this.max-this.element.value.length;
	if(curr<0){
		this.element.value=this.element.value.substring(0,this.max);
		this.element.scrollTop=this.element.scrollHeight;
		curr=0;
	}
	if(this.note!=null&&this.last!=curr){
		this.note.firstChild.data = curr + ' Characters';
		this.last=curr;
	}
	this.updating=false;
}

/* Customized */
function tii_validateEmail(){
	if(!this.validateRequired())
		return false;
	if (!this.required && this.value == '')
	{
		return true;
	}
	var emails=this.value.split(",");
	if(this.max==1){
		pluralObject="email"
	}else{
		pluralObject="emails"
	}
	if(emails.length>this.max){
		this.message="There is a limit of "+this.max+" "+pluralObject+" for this field";
		return false;
	}
	for(var i=0;i<emails.length;i++){
		var email=emails[i];
		var split1=email.split("@");
		if(split1.length!=2||split1[1].split(".").length < 2){
			this.message=this.type.errorMsg;
			return false;
		}
	}
	return true;
}

/* Customized */
function tii_validateURL(){
	if(!this.validateRequired())
		return false;
	if (!this.required && this.value == '')
	{
		return true;
	}
	if(this.value!=""){
		var split1=this.value.split("://");
		if(split1.length!=2||split1[1].split(".").length<3){
			this.message=this.type.errorMsg;
			return false;
		}
	}
	return true;
}

