﻿function progress(mycheckID,myrowID,myStatus,myColor){this.checkID=mycheckID;this.rowID=myrowID;this.status=myStatus;this.color=myColor;}
progress.prototype.setID=function(myID){this.checkID=this.checkID + myID;this.rowID=this.rowID + myID;}
progress.prototype.checked=function(myID){document.getElementById(this.checkID).checked=this.status;}
progress.prototype.setbackground=function(){document.getElementById(this.rowID).style.backgroundColor=this.color;}
function checkAll(checkAllControlID,checkItemControlID,rowID,hiddenControlID)
{
	var item = document.getElementById(hiddenControlID).value;
	var status=document.getElementById(checkAllControlID).checked;

	
	if(item>0)
	{
		var obj;	
		switch(status)
		{
			case true:
			{	
				obj = new progress(checkItemControlID,rowID,true,'#FF8888');
				for(i=1;i<=item;i++)
				{	
					obj.checkID=checkItemControlID;
					obj.rowID=rowID;
					obj.setID(i);
					obj.checked();
					obj.setbackground();									
				}	
				break;
			} 
			case false :
			{
				for(i=1;i<=item;i++)
				{	
					var colorset;
					if(i%2==0)
					{
						colorset="#FFC2C2";
					}
					else
					{
						colorset="#FFD9D9";
					}
					obj = new progress(checkItemControlID,rowID,false,colorset);				
					obj.checkID=checkItemControlID;
					obj.rowID=rowID;
					obj.setID(i);
					obj.checked();
					obj.setbackground();									
				}	
				
				break;
			}
		}
		
	
	}
}
function CartSearch(myId,myRe,mySr,myCurPage,myProID)
{
	this.re=myRe;
	this.sr=mySr;
	this.quan=document.getElementById(myId).value;	
	this.page=myCurPage;
	this.proid=myProID;
}
CartSearch.prototype.addsearch = function()
{
	window.location.href ='addtocart.aspx?sr='+ this.sr +'&re=' + this.re + '&page=' + this.page + '&proid= '+ this.proid + '&quan=' + this.quan ;
}
function Cart(myId,myRe,myCurPage,myProID)
{
	this.re=myRe;
	this.quan=document.getElementById(myId).value;	
	this.page=myCurPage;
	this.proid=myProID;
}
Cart.prototype.add = function()
{
	window.location.href ='addtocart.aspx?re=' + this.re + '&page=' + this.page + '&proid= '+ this.proid + '&quan=' + this.quan ;
}
function checkItem(checkItemControlID,rowID,currentColor)
{
	var status=document.getElementById(checkItemControlID).checked;
	var obj;
	switch(status)
	{
		case true:
		{
			obj = new progress("nothing",rowID,status,"#FF8888");						
			break;
		} 
		case false :
		{
			obj = new progress("nothing",rowID,status,currentColor);
			break;
		}
	}	
	obj.setbackground();
}
function mousehover(checkItemControlID,rowID,currentColor)
{
	var obj;
	obj = new progress("nothing",rowID,status,'#FF8888');
	obj.setbackground();
}

function mouseout(checkItemControlID,rowID,currentColor)
{
	var obj;
	obj = new progress("nothing",rowID,status,currentColor);
	obj.setbackground();
}
function Numeric(myid,Value)
{
  this.id=document.getElementById(myid);
  this.currentValue=Value;	
  this.changeValue=this.id.value;	
  this.re= new RegExp('^[0-9]*$'); 
}
Numeric.prototype.checkNumeric=function()
{
	if (this.changeValue !='' && this.changeValue > 0 && this.changeValue.match(this.re)) 
	{
		var a;
	} 
	else 
	{
		this.id.value=this.currentValue;
		alert('Giá trị nhập vào phải là số nguyên và > 0');
		this.id.focus();
	}  
}
function isNumeric(myid,Value)
{
	var obj = new Numeric(myid,Value);
	obj.checkNumeric();
}