
// Does not allow special characters
function no_special_characters (obj,temp)
{     
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;

		var temparray = str.split("\n");
		var new_str = '';
		Regex = /[^a-zA-Z0-9_ .\\/-]/;
	
		for(a=0;a <= temparray.length-1;a++)
		{
			if (temparray.length-1 == a)
			{
				temparray[a] = temparray[a].substring(0,temparray[a].length);
			}
			else
			{
				temparray[a] = temparray[a].substring(0,temparray[a].length-1);
			}
			
			if( temparray[a].match( Regex ) ) 
			{	
				alertOutput('No special characters allowed for '+ temp + '.');
				obj.focus();
				return false;
			} 
			else 
			{
				
			}
		}
		return true;		
	} 
	else 
	{
		str = obj.value;
		Regex = /[^a-zA-Z0-9_ .\\/-]/;
		if( str.match( Regex ) ) 
		{	
			alertOutput('No special characters allowed for '+ temp + '.');
			obj.focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
		
	


			
}
//Checks if the length of a text field/area has been reached
function is_text_limit(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}

//Checks if a number is a real value only
function is_real (obj,txt)
{           
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
	
	Regex = /[^0-9.-]/;
	if( str.match( Regex ) ) 
	{	
		alertOutput('Invalid number for ' + txt + '.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}
 

//Checks if a number is an integer only
function is_integer (obj,txt)
{           
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
	
	Regex = /[^0-9]/;
	if( str.match( Regex ) ) 
	{	
		alertOutput('Invalid number for ' + txt + '. Please enter an integer only value for this form field.');
		return false;
	} else {
				return true;
			}
}
 

//Checks if an email address is in the correct format only
function is_email(obj) {
	if(obj.value != "") 
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value))
		{
			return true;
		} else {
				alertOutput('Invalid e-mail Address! Please re-enter.');
				return false;
				obj.focus();
				}
	} else {
				alertOutput('Invalid e-mail Address! Please re-enter.');
				return false;
				obj.focus();
				} 
}
 
 
//Checks if user has selected valid option from drop-down box
function default_select (obj,txt) {
	str = obj.value;
	Regex = /-1|^0|(^$)/ ;
	
	if( str.match( Regex ) ) 
	{	
		alertOutput('Please select valid option for '+txt+'.');
//		obj.focus();
		return false;
	} else {
				return true;
			}
}


//Checks if user has selected a space, not allowed
function is_space (obj) {
	
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
	
	Regex = /^\s[\t]*$/ ;
	
	if( str.match( Regex ) ) 
	{	
		alertOutput(obj.name + ' does not allow spaces.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}

//Checks if quantity matches the amount of serialnumbers
function is_serial_match (serial,qty) {

	if (serial.type == 'textarea')
	{
		str = serial.innerHTML;
	} 
	else 
	{
		str = serial.value;
	}
	if (qty.type == 'textarea')
	{
		str2 = qty.innerHTML;
	} 
	else 
	{
		str2 = qty.value;
	}
	
	var temparray = str.split("\n");
	if(temparray.length != str2){
		alertOutput(qty.name+ " doesn't match the amount of "+serial.name+"!");
		qty.focus();
		return false;
	}else{
		return true
	}
	

}

//Checks if user has selected a blank, not allowed
function is_blank (obj) {

	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}

	Regex = /^$/ ;
	
	if( str.match( Regex ) ) 
	{	
		return false;
	} else {
				return true;
			}
}


//Checks if user has selected a blank, not compulsory, system will prompt user
function is_blank_prompt (obj,temp) {

	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}

	Regex = /^$/ ;
	
	if( str.match( Regex ) ) 
	{	

        
		alertOutput("Please enter information for: "+temp);
		obj.focus();
		return false;
	} else {
				return true;
			}
}


//Checks if a specified string contains x amount of characters
function is_length (obj, strlen,txt) {
	
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
		
	if (str.length != strlen) 
	{
		alertOutput('The [' + txt + '] field must be ' + strlen + ' characters long.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}

function alertOutput(txt){

		$('#dialogContent').html(txt);
//		$('#dialogContent').dialog({  
//                    resizable:false,
//                    draggable:false,
//		            width: 400,  
//		            modal: true,
//		            overlay: {
//				                backgroundColor: '#000',
//				                opacity: 0.5
//			         }
//		            //close: function(event,ui){
//		              //     this.destroy;
//		                //   $("#cleanup").html("<div id='dialog' title='WARNING!'></div>");
//		                   
//		            
//		            //}
//		
//		 });
//	});

$('#dialogContent').dialog('open');
}
