// JavaScript Document



function isEmail(email) //checks if email is valid or not. returns true|false. if email is empty returns false.

{



if(email=='')

{

	return false;

}

 var reEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;

        return reEmail.test(email);

 

}

function validate_username(username) // returns true|false

{

	//check if username is atleast 4 char and max 25 char.

	

	//check if username starts with an alphabet

	

	//valid character range {0 - 9}, { a - z } , { A - Z } , {"_"}

	var u=username.toLowerCase();

	

	if(username=='')

	return false;

	

	var len;

	//retrieving length

	len=username.length;

	if(len<=3 || len>=26)

	return false;

	//retriving first charecter

	 var char=u.charCodeAt(0);

	 if(char<97 || char >122)

	 return false;

	 //checking valid range

	 var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";



		var allValid = true;

		for (i = 0;  i < username.length;  i++)

		{

		ch = username.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)

			{

			if (ch == checkOK.charAt(j))

			break;

			}

		if (j == checkOK.length)

			{

			allValid = false;

			break;

			}

		}

		if (!allValid)

		{

		return false;

		}



	 return true;

	

		

}

function validate_email(email) // depends on common.js->isEmail(). returns true|false

{

//check if email is not empty



//check if email is of valid format abc@company.com

return(isEmail(email));



}

function validate_password(password) // returns true|false

{

//check if password entered is min 4 char and max 25 char.



//valid character range {0 - 9}, { a - z } , { A - Z }

len=password.length;

	if(len<=3 || len>=26)

	return false;

//var pattern=/[A-Za-z0-9]{4,25}/;

//return pattern.test(password);

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";



		var allValid = true;

		for (i = 0;  i < password.length;  i++)

		{

		ch = password.charAt(i);

		for (j = 0;  j < checkOK.length;  j++)

			{

			if (ch == checkOK.charAt(j))

			break;

			}

		if (j == checkOK.length)

			{

			allValid = false;

			break;

			}

		}

		if (!allValid)

		{

		return false;

		}

		return true;



}

function createAjax() //creates a XMLHTTP Object and returns

{

	if (window.ActiveXObject)       



return new ActiveXObject("Microsoft.XMLHTTP");   



else if (window.XMLHttpRequest)        



return new XMLHttpRequest();   



else {      



//alert("Your browser does not support AJAX.");    



return null;  

}

}

//for displaying country image

function display_flag(obj,img_name)

{

	//alert('image block');

	id=obj.options[obj.selectedIndex].value;

	if (id == 'none')

	image = "images/flags/white.jpg";

	else

	image="show_flag.php?id=" + id;

	document.getElementById(img_name).src = image;

}

//for displaying country image in profileedit.php page

function display_flag1(obj,img_name)

{

	//alert('image block');

	id=obj.options[obj.selectedIndex].value;

	if (id == 'none')

	image = "images/flags/white.jpg";

	else

	image="show_flag.php?name=" + id;

	document.getElementById(img_name).src = image;

}

//for displaying country image in register.php page

function display_flag2(obj,img_name)

{

	//alert('image block');

	name=obj.options[obj.selectedIndex].value;

	if (name == 'none')

	image = "images/flags/white.jpg";

	else

	image="show_flag.php?name=" + name;

	document.getElementById(img_name).src = image;

}




//member form check

function validate_member()

{

	

	if(document.Member.member_name.value=='')

	{

	alert('Please enter search name');

	document.Member.member_name.focus();

	return false;

	}

	//if(document.Member.country.value=='none')

//	{

//	alert('Please choose country');

//	document.Member.country.focus();

//	return false;

//	}

//	if(document.Member.sex.value=='Select')

//	{

//	alert('Please choose sex');

//	document.Member.sex.focus();

//	return false;

//	}

}

function validate_form()

{

	if(document.loginForm.username.value==''){

	alert('Please enter valid username');

	document.loginForm.username.focus();

	return false;}

	if(document.loginForm.password.value==''){

	alert('Please enter valid password');

	document.loginForm.password.focus();

	return false;}

	

	return true;

}