// JavaScript Document

//*********************************

function dotandspace(txtboxvalue)
{
 var flag=0;
 var strText = txtboxvalue;
 if (strText!="")
 {
 var strArr = new Array();
 strArr = strText.split(" ");
 for(var i = 0; i < strArr.length ; i++)
 {
 if(strArr[i] == "")
 {
  flag=1;              
  break;
 }
 } 
 if (flag==1)
 {
 return true;
  }
 }        
}

   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }


   function isSignedInteger (s)

   {   
   		if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }

   function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }

void function cal_total(){
	
	var total = document.getElementById('total').value;
	var qty = document.getElementById('qty').value;
	if(isPositiveInteger(qty))
	{
		document.getElementById('total').value = qty * 3999;
	}
	else
	{
		
		alert("Quantity is not Correct");
		document.getElementById('qty').focus();
		document.getElementById('qty').select();
	}
}

function Check(theform){
if(theform.company.value=="" || dotandspace(theform.company.value)){
    
	alert("Company name can not be empty")
	theform.company.focus();
	return false;
	}
else if(theform.name.value=="" || dotandspace(theform.name.value)){
   
	alert("Name can not be empty");
	theform.name.focus();	
	return false;
	}

else if(theform.city.value=="" || dotandspace(theform.city.value)){
    
	alert("City can not be empty")
	theform.city.focus();
	return false;
	}
else if(theform.country.value=="" || dotandspace(theform.city.value)){
    
	alert("Country can not be empty")
	theform.country.focus();
	return false;
	}	
	
else if(theform.phone.value==""){
    
	alert("Phone can not be empty")
	theform.phone.focus();
	return false;
	}	
else if(theform.email.value==""){
    
	alert("Email can not be empty")
	theform.email.focus();
	return false;
	}
else if(((theform.email.value.indexOf('@')=="-1")||(theform.email.value.indexOf('.')=="-1")))
  {    
    alert("Please enter your EMail ID In Correct Format");
    theform.email.focus();
    return false;
  }

else
	return true;
}	

function AdminCheck(theform){
if(theform.admin.value=="" || dotandspace(theform.admin.value)){
   
	alert("Admin ID can not be empty");
	theform.admin.focus();	
	return false;
	}
else if(theform.pwd.value=="" || dotandspace(theform.pwd.value)){
    
	alert("Password can not be empty")
	theform.pwd.focus();
	return false;
	}

else
	return true;
}	

function OrderCheck(theform){
if(theform.qty.value=="" || dotandspace(theform.qty.value)){
   
	alert("Quantity can not be empty");
	theform.qty.focus();	
	return false;
	}
else if(theform.name.value==""){
    
	alert("Name can not be empty")
	theform.name.focus();
	return false;
	}
	
else if(theform.address.value==""){
    
	alert("Address name can not be empty")
	theform.address.focus();
	return false;
	}
else if(theform.city.value==""){
    
	alert("City can not be empty")
	theform.city.focus();
	return false;
	}
else if(theform.phone.value=="" || dotandspace(theform.phone.value)){
    
	alert("Phone can not be empty")
	theform.phone.focus();
	return false;
	}
else if(theform.email.value==""){
    
	alert("Email can not be empty")
	theform.email.focus();
	return false;
	}
else if(((theform.email.value.indexOf('@')=="-1")||(theform.email.value.indexOf('.')=="-1")))
  {    
    alert("Please enter your EMail ID In Correct Format");
    theform.email.focus();
    return false;
  }
	
else
	return true;
}	

function pwdCheck(theform){
if(theform.current.value=="" ){
   
	alert("Current Password not be empty");
	theform.current.focus();	
	return false;
	}
else if(theform.newpwd.value==""){
    
	alert("New Password can not be empty")
	theform.newpwd.focus();
	return false;
	}
else if(theform.reenter.value!=theform.newpwd.value){
    
	alert("New and Re-entered Passwords are not same")
	theform.reenter.focus();
	return false;
	}

else
	return true;
}	



