/***************************************************************************/
/*     PROGRAMMER     :  JX                                                */
/*     SCRIPT NAME    :  js.js			                                   */
/*     CREATED ON     :  19/AUG/2006                                       */
/*     LAST MODIFIED  :  19/AUG/2006                                       */
/*                                                                         */
/*     Java Script Functions For the Front End                             */
/***************************************************************************/

    /*----------------------------------------------------------------
    Description   :- function to validate an email id
    Programmer    :- JX
    Last Modified :- 21/AUG/2006
    -------------------------------------------------------------------*/
	function isBadEmail(strg) {
		email_array = strg.split('@');
		if (email_array.length != 2) return true;
		if (email_array[1].split(".").length < 2) return true;
		if (email_array[1].split(".")[1].length < 1) return true;
		if (strg.indexOf('@') < 1) return true;
		if (strg.indexOf(' ') != -1) return true;
		if (email_array[1].indexOf('.') < 1) return true;
		if (strg.length < 5) return true;
		return false;
	}

    /*----------------------------------------------------------------
    Description   :- function to validate yellow page manager
    Programmer    :- JX    Last Modified :- 19/AUG/2006
    -------------------------------------------------------------------*/
        function LTrim(str)
        {
          var whitespace = new String(" \t\n\r");

          var s = new String(str);

          if (whitespace.indexOf(s.charAt(0)) != -1) {
            // We have a string with leading blank(s)...

            var j=0, i = s.length;

            // Iterate from the far left of string until we
            // don't have any more whitespace...
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            j++;

            // Get the substring from the first non-whitespace
            // character to the end of the string...
            s = s.substring(j, i);
          }

          return s;
        }

    /*----------------------------------------------------------------
    Description   :- function to validate yellow page manager
    Programmer    :- JX    Last Modified :- 19/AUG/2006
    -------------------------------------------------------------------*/
        function RTrim(str)
        {
          // We don't want to trip JUST spaces, but also tabs,
          // line feeds, etc.  Add anything else you want to "trim" here in Whitespace
          var whitespace = new String(" \t\n\r");

          var s = new String(str);

          if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            // We have a string with trailing blank(s)...

            var i = s.length - 1;       // Get length of string

            // Iterate from the far right of string until we
            // don't have any more whitespace...
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
              i--;

            // Get the substring from the front of the string to
            // where the last non-whitespace character is...
            s = s.substring(0, i+1);
          }

          return s;
        }

    /*----------------------------------------------------------------
    Description   :- function to validate yellow page manager
    Programmer    :- JX    Last Modified :- 19/AUG/2006
    -------------------------------------------------------------------*/
        function Trim(str)
        {
          return RTrim(LTrim(str));
        }


    /*----------------------------------------------------------------
    Description   :- function to validate the user login form
    Programmer    :- JX
    Last Modified :- 22/AUG/2006
    -------------------------------------------------------------------*/
	function login_validate()
	{
		//username
		if(document.frm_login.txt_login.value=="")
		{
			alert("Please enter the user name");
			document.frm_login.txt_login.focus();
			return false;
		}
		//password
		if(document.frm_login.txt_pwd.value=="")
		{
			alert("Please enter the password");
			document.frm_login.txt_pwd.focus();
			return false;
		}
	}

    /*----------------------------------------------------------------
    Description   :- function to validate the update password form
    Programmer    :- JX
    Last Modified :- 23/AUG/2006
    -------------------------------------------------------------------*/
	function update_pwd_validate()
	{
		//old password
		if(document.frm_password.txt_old.value=="")
		{
			alert("Please enter your existing password");
			document.frm_password.txt_old.focus();
			return false;
		}
		//new password
		if(document.frm_password.txt_new.value=="")
		{
			alert("Please enter your new password");
			document.frm_password.txt_new.focus();
			return false;
		}
		//retype password
		if(document.frm_password.txt_retype.value=="")
		{
			alert("Please enter retype the new password");
			document.frm_password.txt_retype.focus();
			return false;
		}
		//confirm password
		if(document.frm_password.txt_retype.value!=document.frm_password.txt_new.value)
		{
			alert("Please confirm your password");
			document.frm_password.txt_retype.focus();
			return false;
		}
		return true;
	}

    /*----------------------------------------------------------------
    Description   :- function to validate the update personal details form
    Programmer    :- JX
    Last Modified :- 23/AUG/2006
    -------------------------------------------------------------------*/
	function update_personal_validate()
	{
		//first name
		if(document.frm_personal.txt_fname.value=="")
		{
			alert("Please enter the first name");
			document.frm_personal.txt_fname.focus();
			return false;
		}
		//last name
		if(document.frm_personal.txt_lname.value=="")
		{
			alert("Please enter the last name");
			document.frm_personal.txt_lname.focus();
			return false;
		}
		//email id
		if(document.frm_personal.txt_emailid.value=="")
		{
			alert("Please enter your email id");
			document.frm_personal.txt_emailid.focus();
			return false;
		}
		//validate email id
		if(isBadEmail(document.frm_personal.txt_emailid.value))
		{
			alert("Please enter a valid email id");
			document.frm_personal.txt_emailid.focus();
			return false;
		}
        /*//address
        if(document.frm_personal.txt_address.value=="")
        {
            alert("Please enter your address");
            document.frm_personal.txt_address.focus();
            return false;
        }
        //city
        if(document.frm_personal.txt_city.value=="")
        {
            alert("Please enter your city");
            document.frm_personal.txt_city.focus();
            return false;
        }
        //state
        if(document.frm_personal.txt_state.value=="")
        {
            alert("Please enter your state");
            document.frm_personal.txt_state.focus();
            return false;
        }
        //zipcode
        if(document.frm_personal.txt_zipcode.value=="")
        {
            alert("Please enter the zipcode");
            document.frm_personal.txt_zipcode.focus();
            return false;
        }
        //country
        if(document.frm_personal.list_country.value=="")
        {
            alert("Please select your country name");
            document.frm_personal.list_country.focus();
            return false;
        }*/
		return true;
	}
   /*----------------------------------------------------------------
    Description   :- function to validate the update user name form
    Programmer    :- JX
    Last Modified :- 23/AUG/2006
    -------------------------------------------------------------------*/
	function update_uname_validate()
	{
		//user name
		if(document.frm_uname.txt_uname.value=="")
		{
			alert("Please enter the user name");
			document.frm_uname.txt_uname.focus();
			return false;
		}
		return true;
	}

    /*----------------------------------------------------------------
    Description   :- function to validate the forgotpassword form
    Programmer    :- JX
    Last Modified :- 23/AUG/2006
    -------------------------------------------------------------------*/
	function forgotpassword_validate()
	{
		//user name
		if(document.form_forgot.txt_uname.value=="")
		{
			alert("Please enter your user name");
			document.form_forgot.txt_uname.focus();
			return false;
		}
		return true;
	}

    /*----------------------------------------------------------------
    Description   :- function to validate the signup form
    Programmer    :- JX
    Last Modified :- 21/AUG/2006
    -------------------------------------------------------------------*/
	function signup_validate()
	{
    	//first name
    	if(document.frm_register.txt_firstname.value=='')
        {
        	alert("Please enter your first name");
            document.frm_register.txt_firstname.focus();
            return false;
        }

		//username
    	if(document.frm_register.txt_lastname.value=='')
        {
        	alert("Please enter your Last name");
            document.frm_register.txt_lastname.focus();
            return false;
        }

		//email id
    	if(document.frm_register.txt_emailid.value=='')
        {
        	alert("Please enter your emailid");
            document.frm_register.txt_emailid.focus();
            return false;
        }

        //validate the email
        if(isBadEmail(document.frm_register.txt_emailid.value))
        {
        	alert("Invalid Email Id");
            document.frm_register.txt_emailid.focus();
            return false;
        }

        //password
    	if(document.frm_register.txt_password.value=='')
        {
        	alert("Please enter your password");
            document.frm_register.txt_password.focus();
            return false;
        }

		//retype password
    	if(document.frm_register.txt_repassword.value=='')
        {
        	alert("Please re-type your password");
            document.frm_register.txt_repassword.focus();
            return false;
        }

        //confirm password
        if(document.frm_register.txt_password.value!=document.frm_register.txt_repassword.value)
        {
			alert("Please confirm your password");
            document.frm_register.txt_repassword.focus();
            return false;
        }
        return true;

		//city
    	if(document.frm_register.txt_city.value=='')
        {
        	alert("Please enter the city");
            document.frm_register.txt_city.focus();
            return false;
        }
		//state
    	if(document.frm_register.txt_state.value=='')
        {
        	alert("Please select your state");
            document.frm_register.txt_state.focus();
            return false;
        }
        return true;
    }
	
	/*----------------------------------------------------------------
    Description   :- function to agree the terms
    Programmer    :- SDYA
    Last Modified :- 25/SEP/2008
    -------------------------------------------------------------------*/
	function agree_me()
	{
		//var txt_code	= document.frm_signup_terms.txt_code.value;
		alert("A");
		document.frm_signup_terms.action	= "signup_terms_validate.php";
		document.frm_signup_terms.submit();
	}
	
	/*----------------------------------------------------------------
    Description   :- function to dis agree the terms
    Programmer    :- SDYA
    Last Modified :- 25/SEP/2008
    -------------------------------------------------------------------*/
	function disagree_me()
	{
		window.location = "index.php";
	}
