function LTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1) {
            var d=0, e = s.length;
            while (d < e && whitespace.indexOf(s.charAt(d)) != -1)
                d++;
            s = s.substring(d, e);
        }
        return s;
}
function RTrim(str)
{
        var whitespace = new String(" \t\n\r ");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
           var e = s.length - 1;    
		   while (e >= 0 && whitespace.indexOf(s.charAt(e)) != -1)
                e--;
            s = s.substring(0, e+1);
        }
        return s;
}
function Trim(str)
{
		return RTrim(LTrim(str));
}

function checkCost(enterdCost)
{
	
	var nan ="!~@#$%^&*()+=-[]\\\';,/{}|\":<>?`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
	var cost= enterdCost.value;

	for (var i = 0; i < cost.length; i++) 
	{
		if (nan.indexOf(cost.charAt(i)) != -1) 
		{
			alert ("\"cost\" field is invalid");
			enterdCost.value="";
			enterdCost.focus();
			return false;
		}
	}
	
}
function IsValidNumber(Txtcontrol,txtName)
{
	var nan ="!~@#$%^&*()+=-[]\\\';,/.{}|\":<>?`ABCDEFGHIJKLMNOPQ.RSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
	var objcontrol=eval(Txtcontrol);
	var strData= objcontrol.value;
	//var enteredQuantity= Txtcontrol.value;
	//alert("in");
	//if((strData.trim()=="") ||(strData<1))
	if(strData=="0")
	{
		alert ("\"" + txtName + "\" field contains invalid number");
		return false;
	}
	for (var i = 0; i < strData.length; i++) 
	{
		if (nan.indexOf(strData.charAt(i)) != -1) 
		{
			alert ("\"" + txtName + "\" field contains invalid number");
			objcontrol.value="";
			objcontrol.focus();
			return false;
		}
	}
	return true;	
}
//IsValidDecimal
function IsValidDecimal(Txtcontrol,txtName)
{	
	var nan ="!~@#$%^&*()+=-[]\\\';,/{}|\":<>?`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	//alert(Txtcontrol.name);
	var objcontrol=eval(Txtcontrol);
	var strData= objcontrol.value;
	//var enteredQuantity= Txtcontrol.value;
	//alert("in");
	//alert(strData);
	//if(strData.trim()=".")
	//return false;
	//if((strData.trim()=="") ||(strData<1) ||(strData.trim()=="."))
	
	
	if((strData=="0") ||(strData.trim()=="."))
	{
		////alert("start");
		alert ("\"" + txtName + "\" field contains invalid number");
		objcontrol.value="";
		objcontrol.focus();
		return false;
	}
		
	for (var i = 0; i < strData.length; i++) 
	{
		if (nan.indexOf(strData.charAt(i)) != -1) 
		{
			//alert("middel");
			alert ("\"" + txtName + "\" field contains invalid number");
			objcontrol.value="";
			objcontrol.focus();
			return false;
		}
	}
	return true;	
}
function IsQuantityEmpty(count)
{
	var ctrlObj;

	for(var index=0;index<count;index++)
	{
		if(IsEmpty('document.formshop.TxtQuantity'+index,'Quantity')==false)
		{
		ctrlObj=document.getElementById("TxtQuantity"+index);
		ctrlObj.focus();
		
		 return false;		 
		 
		}
		else if(IsValidNumber('document.formshop.TxtQuantity'+index,'Quantity')==false)
		{
			return false;
		}		
		
	}
	
	
}
function IsEmpty(Txtcontrol,txtName)
{

	var objcontrol=eval(Txtcontrol);
	var strData= objcontrol.value;
	if(strData.trim()=="")
	{
		alert ("\"" + txtName + "\" cannot be empty");
		objcontrol.focus();
		return false;
	}
	
	return true;
}

function IsValidLength(Txtcontrol,iLength,txtName)
{
	var objcontrol=eval(Txtcontrol);
	var strData= objcontrol.value;
	//alert(strData.length);
	//alert(iLength);
	if(strData.length>iLength)
	{
		//alert("in");
		alert ("\" Maximum Length for " + txtName + " only " + iLength + " characters\"");
		objcontrol.focus();
		return false;
	}
	return true;
}

function timespecialcheck()
{
	
	var nan ="!~@#$%^&*()+=-[]\\\';,/{}|\"<>?`";	
	var space=" ";	
	for (var i = 0; i < document.Form1.txt_time.value.length ; i++) {
	if (nan.indexOf(document.Form1.txt_time.value.charAt(i)) != -1) {
		alert ("Special characters and Alphabets are not allowed in the time field.");
		document.Form1.txt_time.value="";
		document.Form1.txt_time.focus();
		return false;
		}		
		}
		for (var i = 0; i < document.Form1.txt_time.value.length ; i++) {
	if (space.indexOf(document.Form1.txt_time.value.charAt(i)) != -1) {
		alert ("Spaces are not allowed in the time field.");
		document.Form1.txt_time.value="";
		document.Form1.txt_time.focus();
		return false;
		}		
		}
}
function textCounter(field, maxlimit) 
		{
					
			var countfield=maxlimit;			
			if (field.value.length > maxlimit) // if too long...trim it!
			{
				
				field.value = field.value.substring(0, maxlimit);				
				alert("Entered text has reached its maximam character ("+maxlimit+") limit");
				field.focus();
			}
			// otherwise, update 'characters left' counter
			else
			{ 				
				countfield.value = maxlimit - field.value.length;
			}
		}
		
		String.prototype.trim = function () {return this.replace(/^\s*/, '').replace(/\s*$/, '');}
//function trim(data)
 //{
// alert("ok");
//  return data.replace(/^\s*/, '').replace(/\s*$/, '');
// }

function emailvalid(data)
{
	var k=0;
	for (var i = 0; i < data.length; i++){

		if ("@"==(data.charAt(i)) )
		{
			k=k+1;
		}
		if(k>1)
		{
			return false;
		}
	}
	

	if (/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/.test(data) )
	{
			return true;
	} 
	else
	{
			return false;
	}
}

function DeleteRecord()
{
  var bconfirm=confirm("Are you sure to delete record?");
  if(bconfirm==false)
   return false;
  return true;
  
}
function DeleteItem()
{
  var bconfirm=confirm("Are you sure to delete item?");
  if(bconfirm==false)
   return false;
  return true;
  
}
function RemoveItem()
{
  var bconfirm=confirm("Are you sure to Remove item?");
  if(bconfirm==false)
   return false;
  return true;
  
}
function addfavouriteItem()
{
var userid;
userid=document.getElementById('hiddenTxtbox').value;

if(userid<0)
{
  alert("You must login to add or view favorites");
  return false;
}
else
{
var Addfavourite=confirm("Would you like to save this as a favorite item?");
if(Addfavourite==false)
return false;
return true;
}
}	
function IsListBoxSelected(lstname,dispText)
{
	if(document.getElementById(lstname).options.selectedIndex==-1)
	{
		alert("Select " + dispText + " list");
		return false;
	}
	return true;
}
function checkFields() 
{
		Txt_Email = document.userlogin.Txt_Email.value;
		Txt_Password = document.userlogin.Txt_Password.value;

		var s ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		var iiChars = "!~#$%^&*()+=[]\\\';,/{}|\":<>?";
		var iChars = "!~@#$%^&*()+=-[]\\\';,./{}|\":<>?`0123456789";
		var diChars = " !~@#$%^&*()+=-[]\\\';,./{}|\":<>?_ ";
		var uChars = "_";
		var score="_0123456789 ";
		var k=0;

	if((document.userlogin.Txt_Email.value =="")){
			alert ("\"E-mail Address\" field is blank");
			document.userlogin.Txt_Email.focus();
			return false;
		}
	if (score.indexOf(document.userlogin.Txt_Email.value.charAt(0)) != -1){
			alert("Invalid E-mail Address! Please re-enter.");
			document.userlogin.Txt_Email.value="";
			document.userlogin.Txt_Email.focus();
			return false;
		}

		for (var i = 0; i < document.userlogin.Txt_Email.value.length; i++){
			if (iiChars.indexOf(document.userlogin.Txt_Email.value.charAt(i)) != -1){
				alert ("Invalid E-mail Address! Please re-enter.");
				document.userlogin.Txt_Email.value="";
				document.userlogin.Txt_Email.focus();
				return false;
			}
		}
		for (var i = 0; i < document.userlogin.Txt_Email.value.length; i++){
			if ("@"==(document.userlogin.Txt_Email.value.charAt(i)) ){
				k=k+1;
			}
			if(k>1)
			{
				alert ("Invalid E-mail Address! Please re-enter.");
				document.userlogin.Txt_Email.value="";
				document.userlogin.Txt_Email.focus();
				return false;
			}
		}

		if (/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/.test(Txt_Email)){
		} 
		else
			{
			alert("Invalid E-mail Address! Please re-enter.")
			document.userlogin.Txt_Email.value="";
			document.userlogin.Txt_Email.focus();
			return false;
		} 

	if (( document.userlogin.Txt_Password.value ==""))	{
		alert ("\"Password\" field is blank");
		document.userlogin.Txt_Password.focus();
		return false;
	} 
	/*for (var i = 0; i < document.userlogin.Txt_Password.value.length; i++) {
		if (iiChars.indexOf(document.userlogin.Txt_Password.value.charAt(i)) != -1) {
			alert ("Special characters are not allowed.");
			document.userlogin.Txt_Password.value="";
			document.userlogin.Txt_Password.focus();
			return false;
		}
	}*/
	
		
} 	

/*
This function will allow only valid image files to upload	
*/
function imgFormatCheck(file)
{
	extArray = new Array(".jpg", ".jpeg", ".png", ".bmp", ".gif");
	allowSubmit = false;
	while (file.indexOf("\\") != -1)
	file = file.slice(file.indexOf("\\") + 1);
	ext = file.slice(file.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		if (extArray[i] == ext) 
		{ 
			allowSubmit = true; 
			break; 
		}
	}
	return allowSubmit;
}


/*
This function will check for Duplicated entries in Textboxes in Edit-Attributes form and
Product-Attributes page.	
*/

function checkDuplicateData()
{
	var j;
	var m;
	var n;
	
	var boolValue=true;
	
	a = new Array(16);
	b =	new Array(16);
	var objcontrol;		
	var count=0;		 
	for(j=0;j<16;j++)
		{
		
			objcontrol=eval("document.Form1.TxtAttri"+(j+1));
			if(objcontrol.value!="")
			{	
				
				count=count+1;
				a[j]=objcontrol.value;	
				b[j]=objcontrol.value;
			}
			
		}
		
	for(m=0;m<count-1;m++)
		{
		
		for(n=m+1;n<count;n++)
			{
			if(a[m]==a[n])
				{
					boolValue = false;
				}
				
			}
		}					
	return boolValue;
}				


