// JavaScript Document
function AddBrand(sibling)
{
	var matches, rowId, tmpId, tbody, prevVal, nextId = null;
	prevVal = 0;
	tbody = document.getElementById('BrandsContainer').getElementsByTagName('tbody')[0];

	// Find the highest ID
	$('tr', tbody).each(function() {

		var matches = this.id.match(/\_([0-9]+)$/);
		if (!matches) {
			return;
		}

		tmpId = parseInt(matches[1]);

		if (nextId == null || tmpId > nextId) {
			nextId = tmpId;
		}
	});

	// Increment so we can get the next ID
	nextId++;

	// Get our rowId so we can create proper field label
	rowId = $(sibling).attr('rowIndex');
	rowId++;

	// Now we can clone this row
	var newTR = $(sibling).clone();
	$(newTR).attr('id', 'BrandTR_' + nextId);

	// Change our IDs
	$(':input', newTR).each(function() {
		if (this.id !== '') {
			$(this).attr('id', this.id.replace(/\_[0-9]+$/, '_' + nextId));
			$(this).attr('name', this.name.replace(/\[[0-9]+\]$/, '[' + nextId + ']'));
			$(this).val('');
		}

		
	});

	$('span,a', newTR).each(function() {
		if (this.id !== '') {
			$(this).attr('id', this.id.replace(/\_[0-9]+$/, '_' + nextId));
			if (this.id.substr(0, 8) == 'BrandAdd') {
				this.onclick = function() { AddBrand(newTR); }
			} else if (this.id.substr(0, 8) == 'BrandDel') {
				this.onclick = function() { DelBrand(newTR); }

				// Also show our delete button
				$(this).show();

			// Assign our field label here as this new close is not part of the document yet
			} else if (this.id.substr(0, 10) == 'BrandLabel') {
				$(this).html(GetFieldLabel(parseInt(rowId)+1, "%s"));
			}
		}
	});

	$(sibling).after(newTR);

	ReBrand();
}

function DelBrand(sibling)
{
	var tbody = document.getElementById('BrandsContainer').getElementsByTagName('tbody')[0];

	// Check to see if we are the last row. If so then return
	if ($(sibling).attr('rowIndex') == 0 && tbody.rows.length <= 1) {
		return;
	}

	// Remove our row
	$(sibling).remove();

	// If we are the last one then hide the delete button
	if (tbody.rows.length == 1) {
		var matches;

		if (!(matches = tbody.rows[0].id.match(/\_([0-9]+)$/))) {
			return;
		}

		$('#BrandDel_' + matches[1]).hide();
	}

	ReBrand();
}

function ReBrand()
{
	var firstTR = null;
	var total = 0;

	// This part here will assign the new 'Bundle Products #' numbers to each label
	$('#BrandsContainer tbody tr').each(function() {

		total++;

		if (this.rowIndex == 0) {
			firstTR = this;
		}

		var matches = this.id.match(/\_([0-9]+)$/);
		if (!matches) {
			return;
		}
		$('#BrandLabel_' + matches[1]).html(GetFieldLabel(this.rowIndex+1, "%s"));
	});

	// This part here will hide/show the delete button on the first record
	if (firstTR !== null) {
		var matches = firstTR.id.match(/\_([0-9]+)$/);
		if (matches) {
			if (total > 1) {
				$('#BrandDel_' + matches[1]).show();
			} else {
				$('#BrandDel_' + matches[1]).hide();
			}
		}
	}
}

function GetFieldLabel(key, label)
{
	var newNo, parts, index, numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];

	parts = key.toString();
	parts = parts.split('');
	newNo = '';

	for (var i=0; i<parts.length; i++) {
		index = numbers.array_search(parts[i]);
		if (index !== false) {
			newNo = newNo + numbers[index];
		}
	}
	
	return label.replace(/\%s/, newNo);
}

Array.prototype.array_search = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return i;
		}
	}
	return false;
}

function validbrandfreelist(type) {
	var obj = document.brandsfreelist;
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	/*
	if(obj.poboxno.value == "") {
		alert("Please enter P.O. Box number!");
		obj.poboxno.focus();
		return false;
	}
	
	if (isNaN(obj.poboxno.value)) {
		alert("Please enter number only for P.O. Box number!");
		obj.poboxno.focus();
        return false ;
	} */
	
	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************
	
		
	//Fax number validation start here
	if (obj.fax.value.length > 0) {
		if (checkInternationalPhone(obj.fax.value)==false) {
		alert("Please Enter a Valid Fax Number");
		obj.fax.value="";
		obj.fax.focus();
		return false;
		}
	}
	//Fax number validation ends here

	//Mobile number validation start here
	if (obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
		alert("Please Enter a Valid Mobile Number");
		obj.mobile.value="";
		obj.mobile.focus();
		return false;
		}
	}
	//Mobile number validation ends here
	

	if(obj.cat_id.selectedIndex == -1) {
		alert('Please choose at least 1 category!');
		obj.cat_id.focus();
		return false;
	}

	/*
	if(document.brandsfreelist["cat_id[]"].value == "") {
		alert('Please choose a category!');
		//obj.cat_id[].focus();
		return false;
	}

	var total = "";
	for(var i=0; i < document.brandsfreelist.category.length; i++){
		if(document.forms[1].options[document.brandsfreelist.category[].selectedIndex].value!="")
		total +=document.brandsfreelist.category.options[document.brandsfreelist.category[].selectedIndex].value + "\n"
	}
	
	if(total=="") {
		alert("select atleast one Product Category") 
		return false;
	}else {
		alert (total);
		return false;
	}*/
	
	
	/*if(document.brandsfreelist["category[]"].value == "") {
		alert('Please choose a Product category!');
		obj.category[].focus();
		return false;
	}

	if(document.brandsfreelist["brand[]"].value == "") {
		alert('Please enter a brand!');
		obj.brand[].focus();
		return false;
	}*/

	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here
	
	//Website validation starts here
	if(obj.website.value.length > 0) {
		if(checkUrl(obj.website)== false) {
			alert("Please enter a valid website starting with 'http://'!");
			obj.website.focus();
			return false;
		}
	}
   // website validation ends here
	
	//var getReturn = checkUrl(obj.website);
	//if(getReturn == false)
	//	return false;
	
	
	if(obj.location.value == "") {
		alert("Please enter Location!");
		obj.location.focus();
		return false;
	}
	
	if(obj.business_timings.value == "") {
		alert("Please enter your business timings!");
		obj.business_timings.focus();
		return false;
	}
	
	/*if(obj.activities.value == "") {
		alert("Please enter activities!");
		obj.activities.focus();
		return false;
	}
	*/
	if(obj.key_staff_name.value == "") {
		alert("Please enter key staff name!");
		obj.key_staff_name.focus();
		return false;
	}
	
	if(obj.key_staff_designation.value == "") {
		alert("Please enter designation!");
		obj.key_staff_designation.focus();
		return false;
	}
	
	var getBrandReturn = chkBrandDetails();
	if(getBrandReturn == false)
		return false;

	//else {
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}

	//}
}

function chkBrandDetails() {
	var badNode = null;
	var badError = '';
	var badRow = getRVal = 0;
	$('#BrandsContainer tr').each(function() {
		badRow++;
		var cat = '';
		if (badNode !== null) {
			return;
		}

		// Else we validate
		var matches, rowId = null;
		$(':input', this).each(function() {

			if (rowId == null) {
			
				matches = $(this).attr('name').match(/\[([0-9]+)\]$/);
				rowId = parseInt(matches[1]);
			}

			if (badNode !== null) {
				return;
			}
			
			if ($(this).attr('id').substring(0, 9) == 'category_') {
				if ($(this).val() != '') {
					cat = $(this).val();
				}else {
					alert("Please select atleast 1 Brand Category");
					getRVal = 1;
					document.getElementById('category_'+badRow).focus();
					return false;
				}
			}
			else if ($(this).attr('id').substring(0, 6) == 'brand_') {
				if ($(this).val() == '' && cat != '') {
					badNode = this;
					badError = "Please Enter Brand for SR.No %d.";
					badError = badError.replace(/\%d/, badRow);
					
					getRVal = 1;
					alert(badError);
					document.getElementById('brand_'+badRow).focus();
					return false;
				}
			}
			else if ($(this).attr('id').substring(0, 5) == 'desc_') {
				if ($(this).val() == '' && cat != '') {
					badNode = this;
					badError = "Please Enter Description for SR.No %d.";
					badError = badError.replace(/\%d/, badRow);
					
					getRVal = 1;
					alert(badError);
					document.getElementById('desc_'+badRow).focus();
					return false;
				}
			}
		});
	});
	
	if(getRVal == 1)
		return false;
	else 
		return true;
}

function checkUrl(theUrl) {
	if(theUrl.value.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#]\w+)*\/?$/i) || theUrl.value.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i)) {
		//return true;
	} else {
		alert("Please enter your valid website!");
		theUrl.focus();
		return false;
	}
}

function validadvertisetariff(type) {
	var obj = document.advertisetariff;
	
	if(obj.contact_person.value == "") {
		alert("Please enter contact person!");
		obj.contact_person.focus();
		return false;
	}
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here
	
	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************
	
	//Mobile number validation start here
	if(obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
			alert("Please Enter a Valid Mobile Number");
			obj.mobile.value="";
			obj.mobile.focus();
			return false;
		}
	}
	//Mobile number validation end here
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
}

function validfreelisting(type) {
	var obj = document.freelisting;	
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	/*
	if(obj.poboxno.value == "") {
		alert("Please enter P.O. Box number!");
		obj.poboxno.focus();
		return false;
	}
	
	if (isNaN(obj.poboxno.value)) {
		alert("Please enter number only for P.O. Box number!");
		obj.poboxno.focus();
        return false ;
	} */
	
	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************
	
	//Fax number validation start here
	if (obj.fax.value.length > 0) {
		if (checkInternationalPhone(obj.fax.value)==false) {
		alert("Please Enter a Valid Fax Number");
		obj.fax.value="";
		obj.fax.focus();
		return false;
		}
	}
	//Fax number validation end here

	//Mobile number validation start here
	if (obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
		alert("Please Enter a Valid Mobile Number");
		obj.mobile.value="";
		obj.mobile.focus();
		return false;
		}
	}
	//Mobile number validation ends here
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here
	
	/*
	//Website validation starts here
	if(obj.website.value.length > 0) {
		if(checkUrl(obj.website) == false) {
			alert("Please enter your website starting with 'http://'!");
			obj.website.focus();
			return false;
		}
	}
	//Website validation end here
	*/

	/*var getReturn = checkUrl(obj.website);
	if(getReturn == false)
		return false; */
	
	
	if(obj.location.value == "") {
		alert("Please enter location!");
		obj.location.focus();
		return false;
	}
	
	/*if(document.freelisting["cat_id[]"].value == "") {
		alert('Please choose a category!');
		obj.cat_id.focus();
		return false;
	}*/

	if(obj.cat_id.selectedIndex == -1) {
		alert('Please choose at least 1 category!');
		obj.cat_id.focus();
		return false;
	}
	
	if(obj.key_staff_name.value == "") {
		alert("Please enter key staff name!");
		obj.key_staff_name.focus();
		return false;
	}
	
	if(obj.key_staff_designation.value == "") {
		alert("Please enter key staff designation!");
		obj.key_staff_designation.focus();
		return false;
	}
	
	if(obj.business_timings.value == "") {
		alert("Please enter your business timings!");
		obj.business_timings.focus();
		return false;
	}
	
	/*if(obj.activities.value == "") {
		alert("Please enter activities!");
		obj.activities.focus();
		return false;
	}
	
	if(obj.comments.value == "") {
		alert("Please enter comments!");
		obj.comments.focus();
		return false;
	}*/
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
}

function validfeedback(type) {
	var obj = document.feedback;
	
	var getSelRad = checkRadio("feedback","feedback_type");
	
	if(getSelRad == false) {
		alert("Please select the feedback type!");
		document["feedback"].elements["feedback_type"][0].focus();
		return false;
	}
	
	if(obj.contact_name.value == "") {
		alert("Please enter name!");
		obj.contact_name.focus();
		return false;
	}
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here


	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************

	//Fax number validation start here
	if (obj.fax.value.length > 0) {
		if (checkInternationalPhone(obj.fax.value)==false) {
		alert("Please Enter a Valid Fax Number");
		obj.fax.value="";
		obj.fax.focus();
		return false;
		}
	}
	//Fax number validation end here

	//Mobile number validation start here
	if (obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
		alert("Please Enter a Valid Mobile Number");
		obj.mobile.value="";
		obj.mobile.focus();
		return false;
		}
	}
	//Mobile number validation end here
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
}

function checkRadio (frmName, rbGroupName) {
	var radios = document[frmName].elements[rbGroupName];
	for (var i=0; i <radios.length; i++) {
		if (radios[i].checked) {
			return true;
		}
	}
	return false;
}

function validcontactus(type) {
	var obj = document.contactus;
	
	if(obj.contact_person.value == "") {
		alert("Please enter contact person!");
		obj.contact_person.focus();
		return false;
	}
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here
	
	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************
	
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here

	//Mobile number validation start here
	if (obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
		alert("Please Enter a Valid Mobile Number");
		obj.mobile.value="";
		obj.mobile.focus();
		return false;
		}
	}
	//Mobile number validation end here
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
}

function checkValidData(chkuser,chkpass,type,form)
{
	var response = new String();
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else {// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			if(xmlhttp.responseText == 0 && type == 'all')
			{
				alert("Invalid username/password!");
				form.login_password.focus();
				return false;
			}
			else if(xmlhttp.responseText == 2 && type == 'all')
			{
				alert("Your Account has not been Activated yet. Kindly activate your account from your Email!");
				form.login_password.focus();
				return false;
			}
			else if(xmlhttp.responseText == 3 && type == 'all')
			{
				alert("Your Account has not been Activated yet. Kindly activate your account from your Email!");
				form.login_password.focus();
				return false;
			}
			else if(xmlhttp.responseText == 0 && type == 'register')
			{
				alert("The username you have selected is not available please select another!");
				form.reg_username.focus();
				return false;
			}
			else if(xmlhttp.responseText == 0 && type == 'fpassword')
			{
				alert("The username is not registered with us, please enter a valid username/sign up!");
				form.fpass_emailid.focus();
				return false;
			}
			else
				form.submit();
			
			
		}
	}
	xmlhttp.open("POST","checkregister.php?chkuser="+chkuser+"&chkpass="+chkpass+"&type="+type,true);
	xmlhttp.send();
}

function validregister(type) {
	var obj = document.register;
	
	var getError = validateUsername(obj.reg_username);
	
	if(getError != "") {
		alert(getError);
		obj.reg_username.focus();
		return false;
	}
	
	
	/*alert(getAvail);
	if(getAvail == false) {
		alert("Username already exists please select!");
		obj.reg_username.focus();
		return false;
	}*/
	
	//Email validation start here
	if(obj.reg_emailid.value == "") {
		alert("Please enter your email address!");
		obj.reg_emailid.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.reg_emailid.value)) {
        //return true;
    } else {
        alert("Please enter valid email address!");
		obj.reg_emailid.focus();
        return false;
    }
	//Email validation end here
	
	//Confirm Email validation start here
	if(obj.reg_conf_emailid.value == "") {
		alert("Please confirm your email address!");
		obj.reg_conf_emailid.focus();
		return false;
	}
	
    if(RegExp.test(obj.reg_conf_emailid.value)) {
        //return true;
    } else {
        alert("Please enter valid confirm email address!");
		obj.reg_conf_emailid.focus();
        return false;
    }
	//Confirm Email validation end here
	
	if(obj.reg_emailid.value != obj.reg_conf_emailid.value) {
		alert("Both emails need to match!");
		obj.reg_conf_emailid.focus();
		return false;
	}
	
	if(obj.reg_fname.value == "") {
		alert("Please enter your first name!");
		obj.reg_fname.focus();
		return false;
	}
	
	if(obj.reg_lname.value == "") {
		alert("Please enter your last name!");
		obj.reg_lname.focus();
		return false;
	}
	
	//Reg Phone number validation start here
	
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.reg_telephone.value==null)||(obj.reg_telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.reg_telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.reg_telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.reg_telephone.value="";
		obj.reg_telephone.focus();
		return false;
	}
	
	
	//Telephone number validation end here*******************************
	
	//Mobile number validation start here
	/*if ((obj.mobile.value==null)||(obj.mobile.value=="")) {
		alert("Please Enter your Mobile Number");
		obj.mobile.focus();
		return false;
	}*/
	
	if(obj.reg_mobile.value.length > 0) {
		if (checkInternationalPhone(obj.reg_mobile.value)==false) {
			alert("Please Enter a Valid Mobile Number");
			obj.reg_mobile.focus();
			return false;
		}
	}
	//Mobile number validation end here
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
	
	checkValidData(obj.reg_username.value,"","register",obj);
	return false;
}

function validateUsername(fld) {
   var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
	reWhiteSpace = new RegExp(/\s/);
	
	
    if (fld.value == "") {
        error = "Please enter a username.\n";
    } else if ((fld.value.length < 6) || (fld.value.length > 20)) {
        error = "Please enter a username (Must be between 6 and 20 characters).\n";
    }else if (reWhiteSpace.test(fld.value)) {
        error = "Username cannot contain blank space.\n";
    }else if (illegalChars.test(fld.value)) {
       
		error = "Invalid username (Only letters, numbers and underscores are allowed).\n";
		
    }
    return error;
}



function validforgotpassword(type) {
	var obj = document.forgotpassword;
	
	var getError = validateUsername(obj.fpass_emailid);
	
	if(getError != "") {
		alert(getError);
		obj.fpass_emailid.focus();
		return false;
	}
	
	checkValidData(obj.fpass_emailid.value,"","fpassword",obj);
	return false;
}

function validupdatecompanyinfo(type) {
	var obj = document.updatecompanyinfo;
	
	if(obj.company_name.value == "") {
		alert("Please enter company name!");
		obj.company_name.focus();
		return false;
	}
	
	/*
	if(obj.poboxno.value == "") {
		alert("Please enter P.O. Box number!");
		obj.poboxno.focus();
		return false;
	}
	
	if (isNaN(obj.poboxno.value)) {
		alert("Please enter number only for P.O. Box number!");
		obj.poboxno.focus();
        return false ;
	}
	*/
	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************
	
	//Fax number validation start here
	if (obj.fax.value.length > 0) {
		if (checkInternationalPhone(obj.fax.value)==false) {
		alert("Please Enter a Valid Fax Number");
		obj.fax.value="";
		obj.fax.focus();
		return false;
		}
	}
	//Fax number validation end here

	//Mobile number validation start here
	if(obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
			alert("Please Enter a Valid Mobile Number");
			obj.mobile.value="";
			obj.mobile.focus();
			return false;
		}
	}
	//Mobile number validation end here
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation end here
	
	//Website validation starts here
	if(obj.website.value.length > 0) {
		if(checkUrl(obj.website)== false) {
			alert("Please enter a valid website starting with 'http://'!");
			obj.website.focus();
			return false;
		}
	}
   // website validation ends here
	
	//var getReturn = checkUrl(obj.website);
	//if(getReturn == false)
	//	return false;
	//Website validation end here
	
	if(obj.location.value == "") {
		alert("Please enter location!");
		obj.location.focus();
		return false;
	}
	
	if(obj.cat_id.selectedIndex == -1) {
		alert('Please choose at least 1 category!');
		obj.cat_id.focus();
		return false;
	}

	/*if(document.freelisting["cat_id[]"].value == "") {
		alert('Please choose a category!');
		obj.cat_id.focus();
		return false;
	}*/
	
	if(obj.key_staff_name.value == "") {
		alert("Please enter key staff name!");
		obj.key_staff_name.focus();
		return false;
	}
	
	if(obj.key_staff_designation.value == "") {
		alert("Please enter key staff designation!");
		obj.key_staff_designation.focus();
		return false;
	}
	
	if(obj.business_timings.value == "") {
		alert("Please enter your business timings!");
		obj.business_timings.focus();
		return false;
	}
	/*
	if(obj.activities.value == "") {
		alert("Please enter activities!");
		obj.activities.focus();
		return false;
	}
	
	if(obj.comments.value == "") {
		alert("Please enter comments!");
		obj.comments.focus();
		return false;
	}*/
	
	if(obj.uword.value == "") {
		alert("Please enter verfication code!");
		obj.uword.focus();
		return false;
	}
	
	var uword = hex_md5(obj.uword.value);
	if (uword!=cword[anum-1]) {
		alert("Enter the verfication code as it is shown above.");
		obj.uword.focus();
		return false;
	}
}

function validlogin(type) {
	var obj = document.login;
	
	if(obj.login_username.value == "") {
		alert("Please enter the username!");
		obj.login_username.focus();
		return false;
	}
	
	if(obj.login_password.value == "") {
		alert("Please enter the password!");
		obj.login_password.focus();
		return false;
	}
	
	checkValidData(obj.login_username.value,obj.login_password.value,"all",obj);
	return false;
}

// function for validating personal information form of logged in user
function validatepersonalinfo(obj) {
	
	//Email validation start here
	if(obj.email_id.value == "") {
		alert("Please enter your email id!");
		obj.email_id.focus();
		return false;
	}
	
	var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/;
    if(RegExp.test(obj.email_id.value)) {
        //return true;
    } else {
        alert("Please enter valid email id!");
		obj.email_id.focus();
        return false;
    }
	//Email validation ends here
	
	if(obj.fname.value == "") {
		alert("Please enter your first name!");
		obj.fname.focus();
		return false;
	}
	
	if(obj.lname.value == "") {
		alert("Please enter your last name!");
		obj.lname.focus();
		return false;
	}

	//Telephone number validation start here*****************************
	var ValidChars = "0123456789";
	var phoneNumberDelimiters = "()-,.+ ";  // Special characters that can be included in a phone number
	var IsNumber=true;
	var Char;		
		
	function trim(strPhone)
	{   var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not a whitespace, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (c != " ") returnString += c;
		}
		return returnString;
	}
		
	function stripCharsInBag(strPhone, phoneNumberDelimiters){
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in phoneNumberDelimiters, append to returnString.
		for (i = 0; i < strPhone.length; i++)
		{   
			// Check that current character isn't whitespace.
			var c = strPhone.charAt(i);
			if (phoneNumberDelimiters.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
		
	function IsNumeric(strPhone){		
		for (i = 0; i < strPhone.length && IsNumber == true; i++) 
		{ 
			Char = strPhone.charAt(i);
			// Checking for all 0's in the string - Valid for upto 16 0's only...........
			/*if (strPhone == "0" || strPhone == "00" || strPhone == "000" || strPhone == "0000" || strPhone == "00000" || strPhone == "000000" || strPhone == "0000000" || strPhone == "00000000" || strPhone == "000000000" || strPhone == "0000000000" || strPhone == "00000000000" || strPhone == "000000000000" || strPhone == "0000000000000" || strPhone == "00000000000000" || strPhone == "000000000000000" || strPhone == "0000000000000000") return false; */
			if (strPhone.match(/^0+$/)) return false;
			
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
			}
		}
		return IsNumber;		
	}
		
	function checkInternationalPhone(strPhone){		
		strPhone=trim(strPhone);
		strPhone=stripCharsInBag(strPhone, phoneNumberDelimiters);
		return (IsNumeric(strPhone) && strPhone.length >= 8);
	}
		
		
	if ((obj.telephone.value==null)||(obj.telephone.value=="")) {
		alert("Please Enter your Telephone Number!");
		obj.telephone.focus();
		return false;
	}
	
	if (checkInternationalPhone(obj.telephone.value)==false) {
		alert("Please Enter a Valid Telephone Number!")
		obj.telephone.value="";
		obj.telephone.focus();
		return false;
	}
	//Telephone number validation end here*******************************

	//Mobile number validation start here
	if(obj.mobile.value.length > 0) {
		if (checkInternationalPhone(obj.mobile.value)==false) {
			alert("Please Enter a Valid Mobile Number");
			obj.mobile.value="";
			obj.mobile.focus();
			return false;
		}
	}
	//Mobile number validation end here

}

