//Open popup windows
function url(FileType, sFileName)
	{
		
		if (FileType=='HTML')
			{
				window.open(sFileName,"","width=400,height=380,status=no,scrollbars=yes,resizable=no,location=no,menubar=no,toolbar=no,top=75,left=200");
			}
		else
			{
				window.open(sFileName,"","width=333,height=520,status=no,scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no,top=20,left=425");
			}

	}


//Check viewcart items for checkout
function CheckCart(cartcount)

	{
		if (cartcount<=0)
			{
				alert('Your cart is empty');
				return true;
			}
			
		else
			{
			return false;
			}
	}

//Check for empty values
function CheckEmpty(obj,sFieldName,objtype)
	{
	var inputData,i,co=0,dot,at,ati;
	inputData=obj.value; 	
		
	if (objtype=='text')
		{
		for (i=0;i<=inputData.length-1;i++)
			{
				if (inputData.substr(i,1)==' ')
				{
					co=co+1;
				}
			}
		if ((inputData=='')||(inputData.length==co))
			{
				alert("The " + sFieldName + " must be filled out");
				obj.focus(); 
				return true;
			}
		else
			{
				return false;
			}
		}
	else
		{
		if (inputData==0)
			{
				alert("Select the " + sFieldName);
				obj.focus(); 
				return true;
			}
		else
			{
				return false;
			}
		}
	}
		
//Email check
function CheckEmail(obj)	
		{
		var inputData,i,co=0,dot,at,ati;
		co=0,ati=0;
		inputData=obj.value; 
		for (i=0;i<=inputData.length-1;i++)
			{
				if ((inputData.substr(i,1)==' ') || (inputData.substr(i,1)=="'") )
					{
					co=co+1;
					}
				if (inputData.substr(i,1)=='@')
					{
					ati=i;
					at='True';
					}
				if ((inputData.substr(i,1)=='.') && (at=='True') && (i>ati))
					{
					dot='True';
					}
			}

		if( dot!='True' || at!='True' || (inputData.substr(0,1)!=' ' && co>0))//dot,@ and space checking in email id
			{
				alert('Please enter valid email address');
				obj.focus(); 
				return true;
			}
		else
			{
				return false;
			}
		
		}

//Single quote check
function CheckSinglequote(obj)
	{
		var i,inputData,sqfound;
		sqfound=false;
		inputData=obj.value;
		for (i=0;i<=inputData.length-1;i++)
			{
				if (inputData.substr(i,1)=="'")	
					{
						sqfound=true;
						alert('Please remove single quotes');
						obj.focus(); 
						return true;
					}			
			}		
		if (!sqfound)
			{
				return false;
			}
		
	}

//Special Character check (<,>,|)
function CheckSpecialCharacter(obj)
	{
		var i,inputData,sqfound;
		sqfound=false;
		inputData=obj.value;	
		for (i=0;i<=inputData.length-1;i++)
			{
				if ((inputData.substr(i,1)=="<") || (inputData.substr(i,1)==">") || (inputData.substr(i,1)=="|"))	
					{
						sqfound=true;
						alert('Please remove special character(s)');
						obj.focus(); 
						return true;
					}			
			}		
		if (!sqfound)
			{
				return false;
			}
		
	}

//Check for <script>
function CheckScriptContent(obj)
	{
		var i,inputData,sqfound;
		sqfound=false;
		inputData=obj.value;	
		re = /(script>)/i; 
		found = inputData.match(re); 
		if (found+1!='1')		
			{
				sqfound=true;
				alert('Please remove special words/characters');
				obj.focus(); 
				return true;
			}			
		if (!sqfound)
			{
				return false;
			}
	}

//Check Data Validity
function CheckDataValidity(obj,rule)
	{

	var Data;
	Data=obj.value;
	if (rule=="Man")
		{
		if ((isNaN(Data)==true) || (Data<1) || (Data.indexOf('.')!=-1) || (Data.length==0) )
			{
				alert('Enter valid data');
				obj.focus();
				return true;
			}
		}
	if (rule=="NotMan")
		{
		if ((isNaN(Data)==true) || (Data<0) || (Data.indexOf('.')!=-1))
			{
				alert('Enter valid data');
				obj.focus();
				return true;
			}
		}
	if (rule=="ManNeg")
		{
		if ((isNaN(Data)==true) || (Data.indexOf('.')!=-1) || (Data.length==0) )
			{
				alert('Enter valid data');
				obj.focus();
				return true;
			}
		}
	if (rule=="money")
		{
		if ((isNaN(Data)==true) || (Data.length==0) || (Data<=0) )
			{
				alert('Enter valid data');
				obj.focus();
				return true;
			}
		}
		
	}

function checkDate(DayObj,MonthObj,YearObj) 
{
 
  	var myDayStr = DayObj.value;
	var myMonthStr = MonthObj.value;
	var myYearStr = YearObj.value;
	var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;

/* Using form values, create a new date object
which looks like "Wed Jan 1 00:00:00 EST 1975". */
var myDate = new Date( myDateStr );

// Convert the date to a string so we can parse it.
var myDate_string = myDate.toGMTString();

/* Split the string at every space and put the values into an array so,
using the previous example, the first element in the array is "Wed", the
second element is "Jan", the third element is "1", etc. */
var myDate_array = myDate_string.split( ' ' );

/* If we entered "Feb 31, 1975" in the form, the "new Date()" function
converts the value to "Mar 3, 1975". Therefore, we compare the month
in the array with the month we entered into the form. If they match,
then the date is valid, otherwise, the date is NOT valid. */
	if ( myDate_array[2] != myMonthStr ) 
		{
  		alert( myDateStr + ' is NOT a valid date.' );
		DayObj.focus();
		return true;
		} 	
		else 
		{
			 return false;
		}
 
}
 

//Function to restrict the number of input in Text Area
		function MaxTextArea(obj,limit)
		{
			var input,CharCount;
			input=obj.value;
			CharCount=input.length;
			
			if (document.layers)
				{
					var ltempV = event.which;
				}
			if (document.all)
				{
				var ltempV = event.keyCode;
				}
			if 	((ltempV==46))
					{
						if (CharCount>0)
							{
								CharCount=CharCount-1;
							}
					}
			else
				{
					CharCount=CharCount+1;
				}
			if (CharCount>limit)
				{
					event.keyCode=0;
					return true;
				}
		}	
//Check if numeric or not
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) != -1) 
         {
         IsNumber = true;
         alert('enter only characters');
         return false;
         }
      }
      return true;
   //return IsNumber;
   
   }


//Function to check the entered date for not biggerthan the current date
			function CompareDate(Date1,Date2) 
			{ 
				var Day1,Month1,Year1,Date1Data,Date2Data;
				var Day2,Month2,Year2;
				DateData1=Date1;
				DateData2=Date2;

				
				var myDate_array1 = DateData1.split( '/' );
				Day1=myDate_array1[0];
				Month1=myDate_array1[1];
				Year1=myDate_array1[2];
				
				
				var myDate_array2 = DateData2.split( '/' );
				Day2=myDate_array2[0];
				Month2=myDate_array2[1];
				Year2=myDate_array2[2];

				//Get integer Values of Date1
				if(Day1.length==2)
					{
						if(Day1.substr(0,1)==0)
							{
								Day1=Day1.substr(1,1);
							}
					}
				if(Month1.length==2)
					{
						if(Month1.substr(0,1)==0)
							{
								Month1=Month1.substr(1,1);
							}
					}
				Day1=parseInt(Day1);
				Month1=parseInt(Month1);
				Year1=parseInt(Year1);
				
				//Get integer Values of Date2
				if(Day2.length==2)
					{
						if(Day2.substr(0,1)==0)
							{
								Day2=Day2.substr(1,1);
							}
					}
				if(Month2.length==2)
					{
						if(Month2.substr(0,1)==0)
							{
								Month2=Month2.substr(1,1);
							}
					}
				Day2=parseInt(Day2);
				Month2=parseInt(Month2);
				Year2=parseInt(Year2);				

				if(Year2==Year1)
					{
						if(Month2==Month1)
							{
								if(Day2<Day1)	
									{
										//alert('Enter valid Date');
										return false;
									}
							}
						else
							if(Month2<Month1)
								{
									//alert('Enter valid Date');
									return false;
								}
					}
				else
					{
						if(Year2<Year1)					

						{
							//alert('Enter valid Date');
							return false;
						}
					}
			}


		function getMonthValue(MonthObj)
		{	
		
			var getMonthValue;
			switch (MonthObj.value.toUpperCase())
			{
				
				case "JAN":
				{
					getMonthValue="1";
					break;
				}
				case "FEB":
				{
					getMonthValue="2";
					break;
				}
				case "MAR":
				{
					getMonthValue="3";
					break;
				}
				case "APR":
				{
					getMonthValue="4";
					break;
				}
				case "MAY":
				{
					getMonthValue="5";
					break;
				}
				case "JUN":
				{
					getMonthValue="6";
					break;
				}
				case "JUL":
				{
					getMonthValue="7";
					break;
				}
				case "AUG":
				{
					getMonthValue="8";
					break;
				}
				case "SEP":
				{
					getMonthValue="9";
					break;
				}
				case "OCT":
				{
					getMonthValue="10";
					break;
				}
				case "NOV":
				{
					getMonthValue="11";
					break;
				}
				case "DEC":
				{
					getMonthValue="12";
					break;
				}
			}
			return getMonthValue;
		}

//*******************************************************************************************
//Number format Function
 var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }
  //*******************************************************************************************
  


//*******************************************************************************************
 function Right(str, n)
        /***
                IN: str - the string we are RIGHTing
                    n - the number of characters we want to return

                RETVAL: n characters from the right side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                   return "";
                else if (n > String(str).length)   // Invalid bound, return
                   return str;                     // entire string
                else { // Valid bound, return appropriate substring
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                }
        }

 function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                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;
        }

function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }



function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // 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;
        }

function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
                return RTrim(LTrim(str));
        }

 function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }


