//************** removing white space *****************

function trimWhitespace(string) {

	var newString  = '';
	var substring  = '';
	beginningFound = false;
	
	// copy characters over to a new string
	// retain whitespace characters if they are between other characters
	for (var i = 0; i < string.length; i++) {
		
		// copy non-whitespace characters
		if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {
			
			// if the temporary string contains some whitespace characters, copy them first
			if (substring != '') {
				newString += substring;
				substring = '';
			}
			newString += string.charAt(i);
			if (beginningFound == false) beginningFound = true;			
		}
		
		// hold whitespace characters in a temporary string if they follow a non-whitespace character
		else if (beginningFound == true) substring += string.charAt(i);
	}
	return newString;
}


//************** Price validation *****************

function Price(numval)
{
 itPr = 1;

 //alert("sss"); 
  
  num = numval;
  
  PRLen = num.length;
  Len  = num.lastIndexOf(".");
  Len1  = num.lastIndexOf("-");
  extVal = num.substring(Len,PRLen);  
  
  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  newprice = (num + '.' + cents);
  //alert (newprice);
  //alert(Len1);
  if(newprice == "0.00")
  {  
  itPr = 0;
  }    
  
 if((Len != -1)&&(extVal.length > 3))
 {	            	              
  itPr  = 0;
 }       
 
 if(Len1 >= 0)
  {	            	               
    itPr = 0;
  }       
 
  return itPr;  
}


function validate_paymentDt(doc)
{      
       str ="";
       Namestring = trimWhitespace(doc.frmname.value);      
       Emailstring = trimWhitespace(doc.frmemail.value);
       Addstring = trimWhitespace(doc.frmaddress.value); 
       Currencystring = trimWhitespace(doc.frmcurrency.value);
       Amountstring = trimWhitespace(doc.frmamount.value);
       Descstring = trimWhitespace(doc.frmorderdesc.value);       
       
 	if(Namestring == "")
 	{
 	   str += "Please enter your Name \n";
 	}
 	

	fsign = Emailstring.indexOf("@");
	ssign = Emailstring.indexOf("."); 	
 	
 	if((Emailstring == "") || fsign <= 0 || ssign <= 0) 
 	{
 	   str += "Please enter valid Email Id \n";
 	}	       
 	if(Addstring == "")
 	{
 	   str += "Please enter your Address \n";
 	}	        	
 	if(Amountstring == "")
 	{
 	   str += "Please enter valid Amount \n";
 	}
 	else
 	{
 	 validateprice = Price(doc.frmamount.value);
 	   if(validateprice == 0)
 	    {
 	      str += "Please enter valid Amount \n";
 	    }
 	}  
 	if(doc.frmorderdesc.value != "")
 	{
 	  if(Descstring == "")
 	  {
 	    str += "Please enter valid Order Description \n";
 	  }
 	}   	
 	if(str)
 	{
 	   alert(str);
 	   return false;
 	}
 	else
 	{
 	  return true;	
 	}      
}

