var ns4=document.layers?true:false;
var ie4=document.all?true:false;
var ns6=document.getElementById&&!document.all?true:false;

function invalidChars(testie) {
	var invalid = /[<>"'|_!@#$%^&*:()+~`,.]/  
	return invalid.test(testie);
};

function validEmail(testie) {
	var invalid = new RegExp("^[-0-9a-z_][-0-9a-z_.]*[^.]@[0-9a-z_][-0-9a-z.]*[0-9a-z_]\.[0-9a-z_]{2,3}$", "i");
	return !(invalid.test(testie));
};

function isNumber(testie,canBeEmpty) {
	if (canBeEmpty) {
		var valid = /^[0-9-]*$/
	} else {
		var valid = /^[0-9-]+$/
	};
	return valid.test(testie);
};

function showError(msg) {
	if (ns4){
		alert(msg);
	} else {
		document.getElementById('errorimage').innerHTML='<img src="/images/error.gif" border="0">';
		document.getElementById('errormsg').innerHTML=msg;
	};
};

function ClearSpaces(str) 
	{
		while (str.indexOf(" ") != -1) 
			{
				str = str.replace(" ","");
			}
		return str;
	}


function IsHebrewChar(c){

		return (((c.charAt(0) >= "à") && (c.charAt(0) <= "ú")) || ((escape(c.charAt(0)) >= "%u05D0") && (escape(c.charAt(0)) <= "%u05EA")))
		}
			function isNotHebrew(field_value){
				
				for (i=0;i< field_value.length;i++){
				var c = field_value.charAt(i);
					if (IsHebrewChar(c)) {
					return true
				}
			}
		return false;
	}


function isURL(testie) {

  if (testie.indexOf(" ") != -1)
    return false;
  else if (testie.indexOf("http://") == -1)
    return false;
  else if (testie == "http://")
    return false;
  else if (testie.indexOf("http://") > 0)
    return false;

  testie = testie.substring(7, testie.length);
  if (testie.indexOf(".") == -1)
    return false;
  else if (testie.indexOf(".") == 0)
    return false;
  else if (testie.charAt(testie.length - 1) == ".")
    return false;

  if (testie.indexOf("/") != -1) {
    testie = testie.substring(0, testie.indexOf("/"));
    if (testie.charAt(testie.length - 1) == ".")
      return false;
  }

  if (testie.indexOf(":") != -1) {
    if (testie.indexOf(":") == (testie.length - 1))
      return false;
    else if (testie.charAt(testie.indexOf(":") + 1) == ".")
      return false;
    testie = testie.substring(0, testie.indexOf(":"));
    if (testie.charAt(testie.length - 1) == ".")
      return false;
  }

return true;

}



/* Start Quantity Functions */

function plus(field_name,form_name)
{
	
	num=eval('(document.'+form_name+'[field_name].value);');
	
		if((parseInt(num)!= parseInt(num)) || (parseInt(num)>98))     
			{
				numof=eval('(document.'+form_name+'[field_name].value=1);');
				eval('document.'+form_name+'[field_name].value=numof;');
				return true;
			}
		else
			{
			numof=eval('((document.'+form_name+'[field_name].value)*1)+1;');
			eval('document.'+form_name+'[field_name].value=numof;');
			return true;
			}
			
}

function minus(field_name,form_name)
{
tmp = eval('document.'+form_name+'[field_name].value;');
		if(parseInt(tmp)!= parseInt(tmp))
			{
				numof=eval('(document.'+form_name+'[field_name].value=1);');
				eval('document.'+form_name+'[field_name].value=numof;');
				return true;
			}
		else
			{
				if(tmp == "1")
					{
					}
					else
					{
						numof=eval('((document.'+form_name+'[field_name].value)*1)-1;');
						eval('document.'+form_name+'[field_name].value=numof;');
					}
			}	
			
  return true;
}


function checkInputValid(qty,form_name)
{

Quan = eval('document.'+form_name+'.qty.value;');

for (var i = 0; i<Quan.length ; i++) 
		{
			 if (Quan.charAt(i)!= parseInt(Quan.charAt(i)) || Quan==0 )
					{	
					alert("Please enter a valid number between 1 to 99"); 
					eval('document.'+form_name+'.qty.select();');
					eval('document.'+form_name+'.qty.focus();');
					return false;
					}
		}
		
if(Quan=='')
	{
		alert("Please enter a valid number between 1 to 99"); 
		eval('document.'+form_name+'.qty.select();');
		eval('document.'+form_name+'.qty.focus();');
		return false;
	}

	//alert(form_name)
	tmp = eval('document.'+form_name+'[field_name].value;');
	if(tmp=='')
	{
		alert("Please enter a valid value")
		eval('document.'+form_name+'.qty.focus();');
		return False;
	}
}

/* End Quantity Functions */



function openwindow(){
	window.open("index.html","Help","toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=790,height=600");
};


// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}



// Returns true if character c is a letter or digit.

function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}


// isAlphanumeric (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.

function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

