/***************************************************************************/
/*     PROGRAMMER     :  ASW                                               */
/*     SCRIPT NAME    :  js.js                                          */
/*     Java Script Functions For the user area                            */
/***************************************************************************/
/*----------------------------------------------------------------
Description   :- function to validate an email id
Programmer    :- ASW
-------------------------------------------------------------------*/
  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;
  }
	function isPhone(str)
	{
		 // Check for correct phone code
		 reNo = new RegExp(/(^\\d{3}\-\d{3}-\d{4}$)/);

		 //if (!reNo.test(str))
		 if (/^[0-9]{3}\-[0-9]{3}\-[0-9]{4}$/.test(str) || str == "") {
			 return true;
		 }
		 else
		 {
			 alert("Please enter a valid Phone No; \n\n eg: 111-111-1111");
				  return false;
		 }
		 return true;

	}

	/*----------------------------------------------------------------
	Description   :- function to format phone
	Programmer    :- ASW
	Last Modified :- 18/NOV/2006
	-------------------------------------------------------------------*/

	function mask(str,textbox,loc,delim){
		var locs = loc.split(',');
		for (var i = 0; i <= locs.length; i++){
				for (var k = 0; k <= str.length; k++){
						if (k == locs[i]){
								if (str.substring(k, k+1) != delim){
										str = str.substring(0,k) + delim + str.substring(k,str.length)
								}
						}
				}
		}
		textbox.value = str;
		if(str.length == 4 || str.length == 8) {
				SetEnd (textbox);
		}
	}
	/*----------------------------------------------------------------
	Description   :- function to format phone
	Programmer    :- ASW
	Last Modified :- 18/NOV/2006
	-------------------------------------------------------------------*/

	function SetEnd (TB)
	{
			if (TB.createTextRange)
			{
					var FieldRange = TB.createTextRange();
					FieldRange.moveStart('character', TB.value.length);
					FieldRange.collapse();
					FieldRange.select();
			}
	}
	/*----------------------------------------------------------------
	Description   :- function to check phone
	Programmer    :- ASW
	Last Modified :- 18/NOV/2006
	-------------------------------------------------------------------*/
	function CheckPhone()
	{
		//phone checking
		if(document.frm_userinfo.txt_buss_phone.value){
				var temp = isPhone(document.frm_userinfo.txt_buss_phone.value);
				if(temp == false){
				document.frm_userinfo.txt_buss_phone.focus();
				return false;
				}
		}
		return true;
	}
    /*----------------------------------------------------------------
    Description   :- function to validate login section
    Programmer    :- ASW
    Last Modified :- 19/OCT/2006
    -------------------------------------------------------------------*/
		function login_validate()
		{
				//user name
				if(document.frm_login.text_userid.value=="")
				{
						alert("Please enter the user name");
						document.frm_login.text_userid.focus();
						return false;
				}
				//password
				if(document.frm_login.text_password.value=="")
				{
						alert("Please enter password");
						document.frm_login.text_password.focus();
						return false;
				}
				return true;
		}
		
	/*----------------------------------------------------------------
	Description		:- Function to validate restaurant deletion
	Programmer		:-	Aj
	Last Modified	:- 25/Nov/2006	
	------------------------------------------------------------------*/
	
	function deleteconfirm(page,name,id,mode)
    {
        if(confirm("Are you sure you want to delete this Restaurant? \nIf 'OK' all the information associated with this Restaurant will be removed from the system.\n You cannot UNDO this process."))
                        window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode;
    }
		
	
	function deleteconfirm1(page,name,id,mode)
    {
        if(confirm("Are you sure you want to delete this " + name + "?\nIf 'OK' all the information associated with this " + name + " will be removed from the system.\nYou cannot UNDO this process."))
                        window.location = page + "?id=" + id + "&name=" + name +"&mode=" +mode;
    }
	
	
/*----------------------------------------------------------------
    Description   :- function to confirm the status updation
     Programmer    :- AJ
     -------------------------------------------------------------------*/
    function updatestatusconfirm1(page,name,id,status,restid)
    {
        if(confirm("Are you sure to modify the " + status +" status of this " + name + "?"))
                        window.location = page + "?name=" + name + "&id=" + id + "&restid=" + restid + "&page=" + page ;
    }	
	
/*-----------------------------------------------------------------------------*/
        function changepass_validate()
		{
				//current password
				if(document.frm_change.text_password1.value=="")
				{
						alert("Please enter current password");
						document.frm_change.text_password1.focus();
						return false;
				}
				//new password
				if(document.frm_change.text_password2.value=="")
				{
						alert("Please enter New password");
						document.frm_change.text_password2.focus();
						return false;
				}
				//confirm password
                  if(document.frm_change.text_password3.value=="")
				{
						alert("Please enter confirm password");
						document.frm_change.text_password3.focus();
						return false;
				}
				return true;
		}


