//validate registration data
function checkRegData()
{
    if(isBlank(document.getElementById('txtEmail').value))
    {
        alert('Please Enter Email address');
        document.getElementById('txtEmail').focus();
        document.getElementById('txtEmail').select();
        return false;
    }
	else if(!checkEmail(document.getElementById('txtEmail').value))
    {
        alert('Email address is invalid, Please enter in proper format.');
        document.getElementById('txtEmail').focus();
        document.getElementById('txtEmail').select();
        return false;
    }

    if(isBlank(document.getElementById('txtFirstName').value))
    {
        alert('Please Enter First Name');
        document.getElementById('txtFirstName').focus();
        document.getElementById('txtFirstName').select();
        return false;
    }
    else if(!checkName(document.getElementById('txtFirstName').value))
    {
        alert('Invalid First Name, Please enter in proper format.');
        document.getElementById('txtFirstName').focus();
        document.getElementById('txtFirstName').select();
        return false;
    }

    if(isBlank(document.getElementById('txtLastName').value))
    {
        alert('Please Enter Last Name');
        document.getElementById('txtLastName').focus();
        document.getElementById('txtLastName').select();
        return false;
    }
    else if(!checkName(document.getElementById('txtLastName').value))
    {
        alert('Invalid Last Name, Please enter in proper format.');
        document.getElementById('txtLastName').focus();
        document.getElementById('txtLastName').select();
        return false;
    }

    if(isBlank(document.getElementById('card_number').value))
    {
        alert('Please Enter card number ');
        document.getElementById('card_number').focus();
        document.getElementById('card_number').select();
        return false;
    }
    else if(!checkLength(document.getElementById('card_number').value,10,10))
    {
        alert('Please Enter card number in 10 digits only');
        document.getElementById('card_number').focus();
        document.getElementById('card_number').select();
        return false;
    }

    if(isBlank(document.getElementById('txtPassword').value))
    {
        alert('Please Enter Password');
        document.getElementById('txtPassword').focus();
        document.getElementById('txtPassword').select();
        return false;
    }

    if(isBlank(document.getElementById('txtConfirm').value))
    {
        alert('Please Enter confirm password');
        document.getElementById('txtConfirm').focus();
        document.getElementById('txtConfirm').select();
        return false;
    }

    if(document.getElementById('txtConfirm').value!=document.getElementById('txtPassword').value)
    {
        alert('Confirm password do not match, Please check the entered password');
        document.getElementById('txtConfirm').focus();
        document.getElementById('txtConfirm').select();
        return false;
    }
    return true;
}
// validate login form
function checkLogin()
{
    if(isBlank(document.getElementById('email').value))
    {
        alert("Please Enter Email");
        document.getElementById('email').focus();
        return false;
    }
    if(isBlank(document.getElementById('passwd').value))
    {
        alert("Please Enter password");
        document.getElementById('passwd').focus();
        return false;
    }
    if(!emailInvalid(document.getElementById('email').value))
    {
        alert('Email Address is invalid');
        document.getElementById('email').focus();
        return false;
    }
    return true;

}
// Function which checks whether given email is valid or not
function emailInvalid(s)
{
	if(s.match(/^\w+([\.\+]?[-]{0,2}\w+)*[\.]?@\w+([\.-]?\w+)*(\.\w{2,4})+$/i))
		return true;
	else
		return false;
}
// chenge class
function changeClass(id,cls)
{
	if(document.getElementById(id).className=='fieldheader')
		document.getElementById(id).className=cls;
	else
		document.getElementById(id).className='fieldheader';
}
// validate forget password form
function checkForgetPassword()
{
    if(isBlank(document.getElementById('txtEmail').value))
    {
        alert("Please enter your email");
        document.getElementById('txtEmail').focus();
        return false;
    }
    if(!emailInvalid(document.getElementById('txtEmail').value))
    {
        alert('Email address is invalid. Please re-enter');
        document.getElementById('txtEmail').focus();
        return false;
    }
    return true;
}
// validate buy member form
function chechBuyMember()
{
	if(isBlank(document.getElementById('firstname').value))
	{
		alert("Please enter First Name");
		document.getElementById('firstname').focus();
		return false;
	}
	if(isBlank(document.getElementById('lastname').value))
	{
		alert("Please enter Last Name");
		document.getElementById('lastname').focus();
		return false;
	}
	if(isBlank(document.getElementById('address1').value))
	{
		alert("Please enter Address ");
		document.getElementById('address1').focus();
		return false;
	}
	if(isBlank(document.getElementById('cityname').value))
	{
		alert("Please enter City Name");
		document.getElementById('cityname').focus();
		return false;
	}
	if(isBlank(document.getElementById('zipcode').value))
	{
		alert("Please enter ZipCode");
		document.getElementById('zipcode').focus();
		return false;
	}
	
	return true;
}

// Function which checks whether given email is valid or not.
function checkEmail(ss__email)
{
	if(ss__email.match(/^\w+([\.-]?\w+)*[\.]?@\w+([\.-]?\w+)*(\.\w{2,4})+$/i))
		return true;

	return false;
}

// Function which checks whether given url address is valid or not.
function checkUrl(ss__str)
{
	if(ss__str.match(/^http:\/\/[a-zA-Z0-9]+([_|\.-][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~-]{1,})*$/i) || ss__str.match(/^ftp:\/\/[a-zA-Z0-9]+([_|\.][a-zA-Z0-9~-]{1,})*\.([a-z]{2,4})(\/[a-zA-Z0-9~-]{1,}[_|\.]{0,1}[a-zA-Z0-9~]{1,}\/?)*([_|\.][a-zA-Z0-9~]{1,})*$/i))
		return true;

	return false;
}

// Function to check whether given string is really empty or not.
function isBlank(ss__str)
{
	for(var sn__i=0; sn__i < ss__str.length; sn__i++)
	{
		var ss__char=ss__str.charAt(sn__i);

		if( (ss__char != ' ') && (ss__char != "\n") && (ss__char != "\t") )
			return false;
	}
	return true;
}

// Function to check whether given string is desired length.
function checkLength(ss__str,sn__lowerLimit,sn__upperLimit)
{
	if(ss__str.length >= sn__lowerLimit && ss__str.length <= sn__upperLimit)
		return true;

	return false;
}

function checkEmail(ss__email)
{
	if(ss__email.match(/^\w+([\.-]?\w+)*[\.]?@\w+([\.-]?\w+)*(\.\w{2,4})+$/i))
		return true;

	return false;
}
function checkName(ss__str)
{
	if(ss__str.match(/^[\w]{1}[\w\s-]{1,24}[\w]{1,24}$/))
		return true;

	return false;
}
function checkLength(ss__str,sn__lowerLimit,sn__upperLimit)
{
	if(ss__str.length >= sn__lowerLimit && ss__str.length <= sn__upperLimit)
		return true;

	return false;
}
function openPopup(ss__url,sn__w,sn__h,resize,scroll_bar,ss__winName)
{
var ss__myfeatures='directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,resizable='+resize+',top='+(screen.width-sn__w)/2+',left='+(screen.height-sn__h)/2+',scrollbars='+scroll_bar+',width='+sn__w+',height='+sn__h+'';

if(ss__winName == '')
ss__winName='NEW';

var ss__newWin=open(ss__url,ss__winName,ss__myfeatures);

ss__newWin.focus();
}