var invalidObj;
var i=0;
var k=0;
var j=0;

function CompChars(mychar, char2)
{
    if(mychar.indexOf(char2) == 0)
        return true;
    else
        return false;
}

function LTrim(mystring)
{
    var index=0;
    var leng=parseInt(mystring.length);
    var locstring=mystring;

    if(leng==0)
    {
        return locstring;
    }
    while( (index<leng) && (CompChars(locstring.charAt(index), " ") ) )
        index +=1;
    return locstring.substring(index, leng);
}

function RTrim(mystring)
{
    var leng=parseInt(mystring.length);
    var locstring=mystring;
    var index=leng-1;

    if(leng==0)
    {
        return locstring;
    }
    while( (index>=0) && (CompChars(locstring.charAt(index), " ") ) )
        index -= 1;
    return locstring.substring(0, index+1);
}

function IsEmpty(obj){
	var temp=LTrim(obj.value);
	if(temp==""){
		if(invalidObj==null){
			invalidObj=obj;
		}
		return true;
	}
	return false
}

function IsEmailValid(sStr){
	return (sStr.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)!=null)
}

function ValidateFormReg1(){
	var frm=document.regform	
	invalidObj=null;

	crtObj=frm.firstname;
	if (IsEmpty(crtObj)) ;
	//	crtObj.className="inpReqFld"
	//else
	//		crtObj.className="inpFld"
		
	crtObj=frm.lastname

	if (IsEmpty(crtObj)) ;
	//	crtObj.className="inpReqFld"
	//else
	//	crtObj.className="inpFld"
	
	crtObj=frm.email
	if (IsEmpty(crtObj)) ;
	if (invalidObj==null)
	{
		if (!IsEmailValid(crtObj.value) || checkStatus=="INVALID")
		//if (!IsEmailValid(crtObj.value))
		{
			alert("Please enter a valid email address.");
			crtObj.focus();
			return false;
		}
	}
	//	crtObj.className="inpReqFld"
	//else
	//	crtObj.className="inpFld"
		
	crtObj=frm.phone
	if (IsEmpty(crtObj)) ;
	//	crtObj.className="inpReqFld"
	//else
	//	crtObj.className="inpFld"
	
	crtObj=frm.industry
	if (!IsEmpty(crtObj))	
	{
		frm.industryTxt.value=crtObj.options[crtObj.selectedIndex].text;
	}
	
	crtObj=frm.usertype;
	if (IsEmpty(crtObj));
	
	crtObj=frm.city;
	if (IsEmpty(crtObj));
	
	crtObj=frm.country;
	if (!IsEmpty(crtObj))
	{
		frm.countryTxt.value=crtObj.options[crtObj.selectedIndex].text;
	}
		
	crtObj=frm.address
	if (IsEmpty(crtObj)) ;
	//	crtObj.className="inpReqFld"
	//else
	//	crtObj.className="inpFld"
	
	if (invalidObj !=null){
		frm.industryTxt.value="";
		frm.countryTxt.value="";
		alert("Please fill in all the required fields before submitting the form.");
		invalidObj.focus();
		return false;
	}
	return true;
}


