/* Copyright (c) 2000 Affno (Pvt) Ltd, . All rights reserved.

 This software is the confidential and proprietary information of        
 Affno  ("Confidential Information").  You shall not disclose such 
 Confidential Information and shall use it only in accordance with
 the terms of the license agreement you entered into with Affno.

File Name		: validation.js
Description		: Acceptable characters for fields v3.0 (Send by Rangika Wed 9/21/2005 10:03 AM)
Created By		: Roshani de Silva
Created Date	: 23-October-2005
Modified By		: Bjorn de Lima
Modified Date	: 30-October-2006
Version			: 1.00.000

*/


function validate(){
// First we need to reset Firstname and Lastname if in case default value is still there
if ($('fname').value=="First name"){ 
$('fname').value = "";
$('fname').style.color = "#222222";
}
if ($('lname').value=="Last name"){ 
$('lname').value = "";
$('lname').style.color = "#222222";
}
$('fname').style.backgroundColor = $('lname').style.backgroundColor = $('address1').style.backgroundColor = $('email').style.backgroundColor = "#ffffff";

// If name has been entered validate value
if (!isName($('fname').value)){
$('fname').style.backgroundColor = "#FFFFCC";
alert("Please enter a valid First name");
$('fname').focus();
return false;
}

// If name has been entered validate value
if (!isName($('lname').value)){
$('lname').style.backgroundColor = "#FFFFCC";
alert("Please enter a valid Last name");
$('lname').focus();
return false;
}

// If address has been entered validate value
if (isEmpty($('address1').value)){
$('address1').style.backgroundColor = "#FFFFCC";
alert("Please enter your address");
$('address1').focus();
return false;
}

// If email has been entered validate value
if (!isEmail($('email').value)){
$('email').style.backgroundColor = "#FFFFCC";
alert("Please enter a valid Email address");
$('email').focus();
return false;
}

return true;
}


function validateContact(){
$('name').style.backgroundColor = $('email').style.backgroundColor =  "#ffffff";	
	
// If name has been entered validate value
if (!isName($('name').value)){
$('name').style.backgroundColor = "#FFFFCC";
alert("Please enter a valid Name");
$('name').focus();
return false;
}


// If email has been entered validate value
if (!isEmail($('email').value)){
$('email').style.backgroundColor = "#FFFFCC";
alert("Please enter a valid Email address");
$('email').focus();
return false;
}

return true;	
}



// Empty or Null
function isEmpty(inputStr) {
	if ((inputStr == null) || (inputStr=="")) return true
	else return false
}

// Space
function isSpace(str) {
	pattern = /^[\s]+$/
        if (str.match(pattern)) return true
           else return false;
}

// Numbers, Letters and Space - (Search, Identity card number, Passport number)
function isAlphaNu(str) {
	pattern = /^[a-zA-Z0-9\s]+$/
		if (!str.match(pattern)) return false
			else return true;
}

/* 
---- all charactors allowed --------	
	Address(postal, resident, mailing, shipping)
 	Zip code, postal code
 	Organization, Company
 	Message, remarks, comments, qualifications
*/	 

// Name - (first, last, full name)
function isName(str) {
	pattern = /^[a-zA-Z\s\-\.\']+$/
		if (!str.match(pattern)) return false
			else return true;
}
// Email
function isEmail(str) {
     pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/
        if (str.match(pattern)) return true
           else return false;
}

// Mobile Number
function isMobile(str) {
	pattern =/^[0-9\s\-\/\+]+$/
		if (!str.match(pattern)) return false
			else return true;
}