//Created By Sunita Upadhyayula as part of Email for Reliable - Phase II

/*
*	This function displays a modal window and sets focus on it
*	NOTE: The modal option is undocumented one for Netscape though it seems to work
*/
function displayShopCartMsg()
{
    var win1

    //alert('atabstemp parent.fbody.location='+this.parent.fbody.location);

    win1 = window.open("/reliable/modaldialog.html","win1","resizable=no,left=300,screenX=300,top=300,screenY=300,width=450,height=130,titlebar=no,alwaysRaised=yes,toolbar=no,scrollbars=no");
    win1.focus(); 
}

//,modal=yes
/*
*	This function takes action on the parent window depending upon what the user clicked on the 
*	modal window and closes this window.
*	If "Yes" - display the appropriate no selected tab and Customer Login body with this info
*	If "No" - display the appropriate no selected tab and Customer Login body with this info
*	If "Cancel" - do nothing
*/

function processShopCartMsg(answer)
{

/*
alert('answer='+ answer);
alert('modaldialog.location='+ window.location);
alert('modaldialog window.opener.location='+ window.opener.location);
alert('window.opener.parent.fbody.location='+ window.opener.parent.fbody.location);
*/

if (answer == "Yes")
{
	//alert('YES');

	window.opener.parent.ftabs.location.href='/reliable/ltabs.html';
	window.opener.parent.fbody.location.href='/NASApp/Reliable/LoginAsDiffUser?keepItems=Y';
	//window.opener.parent.fbody.location.href='/reliable/loginbody.html';
	
}
else
{
	if (answer == 'No')
	{
		//alert('NO');
		window.opener.parent.ftabs.location.href='../reliable/ltabs.html';
		window.opener.parent.fbody.location.href='/NASApp/Reliable/LoginAsDiffUser?keepItems=N';
		//window.opener.parent.fbody.location.href='/reliable/loginbody.html';
		
	}

}


/*
	if (confirm('All items in your shopping cart will be retained when you login as a different user.'))
	{
		parent.ftabs.location.href='../jsp/webstore/ltabs.jsp?keepItems="Y"';
	}
	else
	{
		//parent.ftabs.location.href='../jsp/webstore/ltabs.jsp?keepItems="N"';
	}
*/
self.close();
}

/*
*	This function validates the Customer Login form for proper customer number, user name
*	and password.
*/
function validateForm()
{
    //var nCustNumber = document.logindiffuser.CUSTOMER_NUM.value.toUpperCase();
    var username = document.logindiffuser.username.value;
    var password = document.logindiffuser.password.value;
       
    // Customer ID Verification
    /*
    if (!isvalidCustNumber(nCustNumber))
    {
        document.logindiffuser.CUSTOMER_NUM.select();
    }
    else 
    */
      // User name Verification
    if (isWhitespace(username))
    {
        alert('The user name field cannot be blank');
        document.logindiffuser.username.value = "";
        document.logindiffuser.username.focus();
        return false;
    }
      // Password Verification
    else if(isWhitespace(password))
    {
        alert('The password field cannot be blank');
        document.logindiffuser.password.value= "";
        document.logindiffuser.password.focus();
        return false;
    }
    else
    {
    	UrlLookup(2, document.logindiffuser, "/NASApp/Reliable/Authenticate");
    	return true;
        //document.logindiffuser.submit();
    }
}

/*
*	This function checks if the customer number is a valid one
*/
function isvalidCustNumber (s)
{   

    if (isWhitespace(s))
    {
    	alert('The customer number cannot be blank');
	return false;
    }
         
    if(isInt(s))        // int value, this must be a customer entry to be a int
    {
            if (s.length > 8 || s.length < 1)
            {
        	alert('Please enter valid customer number');            
                return false;
            }
    
            return true;
    }
    
    //Alphanumeric customer number - check if it has valid characters
    
    var i;

    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);

        if (! (isDigit(c) || (c=='N') || (c=='n') || (c=='#') || (c=='-')) ) 
        {
        	alert('Please enter valid customer number');
               	return false;
	}
    }

    return true;
}

/*
*	This function checks if the paramater is a digit
*/
function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"));
}

/*
*	This function checks if the paramater is a whitespace
*/
function isWhitespace(s)
{
    var whitespace = " \t\n\r";
    var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {
	var c = s.charAt(i);
	//-1 means this character is not a whitespace character
	if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

/*
*	This function checks if the paramater is an integer
*/
function isInt(s)
{
    for (i = 0; i < s.length; i++)
    {
	var c = s.charAt(i);
	if (!isDigit(c))
	{
		return false;
	}
    }
    return true;
}

/*
*	This function checks if the paramater is empty
*/
function isEmpty(s)

{   
	return ((s == null) || (s.length == 0)) ;
}

