
//function addEvent( obj, type, fn, tmp ) {
//        if( obj.attachEvent ) {
//                obj["e"+type+fn] = fn;
//                obj[type+fn] = function(){obj["e"+type+fn]( window.event
//);}
//                obj.attachEvent( "on"+type, obj[type+fn] );
//        } else
//                obj.addEventListener( type, fn, false );
//}

//function removeEvent( obj, type, fn ) {
//        if( obj.detachEvent ) {
//                obj.detachEvent( "on"+type, obj[type+fn] );
//                obj[type+fn] = null;
//        } else
//                obj.removeEventListener( type, fn, false );
//}


//// Declare the namespace
//var fdTextareaController;

//(function() {
//        function fdTextareaMaxlength(inp, maxlength) {
//                this._inp       = inp;
//                this._max       = Number(maxlength);
//                var self        = this;

//                self.maxlength = function() {
//                        if(self._inp.disabled) return false;

//                        if(self._inp.value.length > self._max) {
//                                self._inp.value = self._inp.value.substring(0, self._max);
//                                return false;
//                        }

//                        return true;
//                }
//                
//                // Has Safari keypress foibles ? Needs tested...
//                addEvent(self._inp, 'keypress', self.maxlength, false);
//                
//                // Sorry folks, but using the "onblur" event is the only way to cut the text down to size
//                // after a users cut & paste action
//                addEvent(self._inp, 'blur', self.maxlength, false);

//                // IE only event 'onpaste'

//                // Conditional compilation used to load only in IE win.
//                // As we don't need the onblur event for IE, we remove it at the same time.

//                /*@cc_on @*/
//                /*@if (@_win32)
//                addEvent(self._inp, 'paste', function(){
//event.returnValue = false; self._inp.value =
//window.clipboardData.getData("Text").substring(0,self._max); }, true);
//                removeEvent(self._inp, 'blur', self.maxlength, false);
//                /*@end @*/
//                
//                // Call the maxlength function immediately to trim any text inserted server-side to the required length.
//                self.maxlength();
//        };

//        // Construct the previously declared namespace
//        fdTextareaController = {
//                textareas: [],

//                _construct: function( e ) {

//                        var regExp_1 = /fd_max_([0-9]+){1}/ig;

//                        var textareas =
//document.getElementsByTagName("textarea");

//                        for(var i = 0, textarea; textarea =
//textareas[i]; i++) {
//                                if(textarea.className &&
//textarea.className.search(regExp_1) != -1) {
//                                        max =
//parseInt(textarea.className.match(regExp_1)[0].replace(/fd_max_/ig,
//''));
//                                        if(max)
//fdTextareaController.textareas[fdTextareaController.textareas.length] =
//new fdTextareaMaxlength(textarea, max);
//                                }
//                        }

//                },

//                _deconstruct: function( e ) {
//                        /* TODO: Clean up for IE memory leaks.. */
//                }
//        }
//})();

//// onload events
//addEvent(window, 'load', fdTextareaController._construct, false);
//addEvent(window, 'unload', fdTextareaController._deconstruct, false);

var i = 0;
function LengthValidate(source, arguments)
{           
      if (arguments.Value.length<5)
      {
         arguments.IsValid=false
      }
      else
      {
         arguments.IsValid=true
      }
}

function ValidatePic(source, arguments)
{
	if (arguments.Value.substring(arguments.Value.length-3,arguments.Value.length).toLowerCase()!='jpg')
	{
		if (arguments.Value.substring(arguments.Value.length-3,arguments.Value.length).toLowerCase()!='gif')
		{
			if (arguments.Value.substring(arguments.Value.length-4,arguments.Value.length).toLowerCase()!='jpeg')
		    {
			    arguments.IsValid = false;
		    }
		}
		
		
	}
	else
	{
		objNode = document.getElementById(source.getAttribute("controltovalidate"));
		if ((objNode.isValidFile!=true)&&(objNode.isValidFile!=false))
		{
			arguments.IsValid = true;
		}
		else
		{
			arguments.IsValid = objNode.isValidFile;
		}
	}
	//isValidPic(source,arguments,32);
}

function validateImg(fieldNode, maxSize){
	//fieldNode = document.getElementById(fieldNodeID);
	var imgURL = "file:///" + fieldNode.value;
	var img = new Image();
	img.maxSize =  maxSize;
	// Store a reference to the input field
	img.fieldNode = fieldNode;
	// The image's data can be read only after loading. That's why we need a callback
	img.onload = validateImgCallback;
	img.src = imgURL;
}
function validateImgCallback(){
	var errorsCount = 0;
	// Check every constrain and increment the error counter accordingly
	if(this.fileSize && this.maxSize && (this.fileSize/1024) > this.maxSize){
		errorsCount ++;
	}
	/*if(this.maxWidth && (this.width > this.maxWidth)){
		errorsCount ++;
	}
	if(this.minWidth && (this.width < this.minWidth)){
		errorsCount ++;
	}
	if(this.maxHeight && (this.height > this.maxHeight)){
		errorsCount ++;
	}
	if(this.minHeight && (this.height < this.minHeight)){
		errorsCount ++;
	}//*/
	// Store the valid flag inside the DOM node itself
	this.fieldNode.isValidFile = (errorsCount != 0) ? false : true;
}


function isPhyAddress(source, arguments)
{
	if (startsWith((trim(arguments.Value).toLowerCase()),"po "))
	{
	arguments.IsValid = false;
	}
	else if (startsWith((trim(arguments.Value).toLowerCase()),"p.o"))
	{
	arguments.IsValid = false;
	}
	else if (startsWith((trim(arguments.Value).toLowerCase()),"pobox"))
	{
	arguments.IsValid = false;
	}
	else if (startsWith((trim(arguments.Value).toLowerCase()),"box"))
	{
	arguments.IsValid = false;
	}
	else
	{
	arguments.IsValid = true;
	}
	
}

function trim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function startsWith(sString, cString) 
{
	if (sString.length < cString.length)
	{
		return false;
	}
	for (i=0; i < cString.length-1; i++)
	{
		if (sString.substring(i,i+1) != cString.substring(i,i+1))
		{
			return false;
		}
	}
return true;
}