// Does not allow special characters
function no_special_characters (obj)
{     
	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 ) ) 
			{	
				alert('No special characters allowed for '+ obj.name + '.');
				obj.focus();
				return false;
			} 
			else 
			{
				
			}
		}
		return true;		
	} 
	else 
	{
		str = obj.value;
		Regex = /[^a-zA-Z0-9_ .\\/-]/;
		if( str.match( Regex ) ) 
		{	
			alert('No special characters allowed for '+ obj.name + '.');
			obj.focus();
			return false;
		}
		else 
		{
			return true;
		}
	}
		
	


			
}


//Checks if MSISDN starts with 27, only numeric digits & 11 digits long
function is_msisdn (obj)
{
	ref = obj.value;
	if( !ref.match(/^[27][0-9]{10}$/) )
	{ 
		alert( 'Invalid MSISDN. \n \n MSISDN must start with 27. \n MSISDN must contain only digist 0 to 9\n MSISDN must be 11digits long.' );
		obj.focus();
		return false;
	} else {
				return true;
			}
}

//Checks if Invoice starts with MS, only numeric digits
function is_invoice (obj)
{
	ref = obj.value;
	if( !ref.match(/(^[MSms]{1,2})([0-9]{1,})/) )
	{ 
		alert( 'Invalid invoice number. \n \n Invoice number must start with MS. \n Invoice number contain only digist 0 to 9.' );
		obj.focus();
		return false;
	} else {
				return true;
			}
}

//Checks if Account start with alpha numeric, only 7 numeric digits
function is_accountno (obj)
{
	ref = obj.value;
	if( !ref.match(/(^[A-Z]{1,1})([0-9]{1,})/) )
	{ 
		alert( 'Invalid account number. \n \n Account number must start with alpha numeric. \n Account number must contain 7 digits.' );
		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)
{           
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
	
	Regex = /[^0-9.-]/;
	if( str.match( Regex ) ) 
	{	
		alert('Invalid number for ' + obj.name + '.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}
 

//Checks if a number is an integer only
function is_integer (obj)
{           
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
	
	Regex = /[^0-9]/;
	if( str.match( Regex ) ) 
	{	
		alert('Invalid number for ' + obj.name + '. Please enter an integer only value for this form field.');
		obj.focus();
		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 {
				alert("Invalid e-mail Address! Please re-enter.");
				return false;
				obj.focus();
				}
	} else {
				alert("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) {
	str = obj.value;
	Regex = /-1|^0|(^$)/ ;
	
	if( str.match( Regex ) ) 
	{	
		alert('Please select valid option for drop-down box.');
		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 ) ) 
	{	
		alert(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){
		alert(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) {

	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}

	Regex = /^$/ ;
	
	if( str.match( Regex ) ) 
	{	
		alert('No input specified for '+ obj.name + '.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}


//Checks if a specified string contains x amount of characters
function is_length (obj, strlen) {
	
	if (obj.type == 'textarea')
	{
		str = obj.innerHTML;
	} 
	else 
	{
		str = obj.value;
	}
		
	if (str.length != strlen) 
	{
		alert('The [' + obj.name + '] field must be ' + strlen + ' characters long.');
		obj.focus();
		return false;
	} else {
				return true;
			}
}

