// JavaScript Document

// BrowserFunctions

function GetinnerText(obj)
{
	if(document.all){
    return obj.innerText ;
	} else{ 
			return obj.textContent ;
	}
}
function SetInnerText(obj,val)
{
	if(document.all){
     obj.innerText = val ;
	} else{
			 obj.textContent = val ;
	}
}
		
// Const Array
var guogeToMillimeter = new Array(39);
	guogeToMillimeter[1] = 7.348;
	guogeToMillimeter[2] = 6.543;
	guogeToMillimeter[3] = 5.827;
	guogeToMillimeter[4] = 5.189;
	guogeToMillimeter[5] = 4.621;
	guogeToMillimeter[6] = 4.115;
	guogeToMillimeter[7] = 3.664;
	guogeToMillimeter[8] = 3.263;
	guogeToMillimeter[9] = 2.906;
	guogeToMillimeter[10] = 2.588;
	guogeToMillimeter[11] = 2.304;
	guogeToMillimeter[12] = 2.052;
	guogeToMillimeter[13] = 1.828;
	guogeToMillimeter[14] = 1.628;
	guogeToMillimeter[15] = 1.449;
	guogeToMillimeter[16] = 1.291;
	guogeToMillimeter[17] = 1.149;
	guogeToMillimeter[18] = 1.024;
	guogeToMillimeter[19] = 0.912;
	guogeToMillimeter[20] = 0.812;
	guogeToMillimeter[21] = 0.723;
	guogeToMillimeter[22] = 0.644;
	guogeToMillimeter[23] = 0.573;
	guogeToMillimeter[24] = 0.511;
	guogeToMillimeter[25] = 0.455;
	guogeToMillimeter[26] = 0.405;
	guogeToMillimeter[27] = 0.36;
	guogeToMillimeter[28] = 0.321;
	guogeToMillimeter[29] = 0.286;
	guogeToMillimeter[30] = 0.255;
	guogeToMillimeter[31] = 0.226;
	guogeToMillimeter[32] = 0.2;
	guogeToMillimeter[33] = 0.18;
	guogeToMillimeter[34] = 0.16;
	guogeToMillimeter[35] = 0.142;
	guogeToMillimeter[36] = 0.13;
	guogeToMillimeter[37] = 0.114;
	guogeToMillimeter[38] = 0.1;
	var guogeToInch = new Array(39)
	guogeToInch[1] = 0.289;
	guogeToInch[2] = 0.258;
	guogeToInch[3] = 0.229;
	guogeToInch[4] = 0.204;
	guogeToInch[5] = 0.182;
	guogeToInch[6] = 0.162;
	guogeToInch[7] = 0.144;
	guogeToInch[8] = 0.128;
	guogeToInch[9] = 0.114;
	guogeToInch[10] = 0.102;
	guogeToInch[11] = 0.091;
	guogeToInch[12] = 0.081;
	guogeToInch[13] = 0.072;
	guogeToInch[14] = 0.064;
	guogeToInch[15] = 0.057;
	guogeToInch[16] = 0.051;
	guogeToInch[17] = 0.045;
	guogeToInch[18] = 0.04;
	guogeToInch[19] = 0.036;
	guogeToInch[20] = 0.032;
	guogeToInch[21] = 0.028;
	guogeToInch[22] = 0.025;
	guogeToInch[23] = 0.023;
	guogeToInch[24] = 0.02;
	guogeToInch[25] = 0.018;
	guogeToInch[26] = 0.016;
	guogeToInch[27] = 0.014;
	guogeToInch[28] = 0.013;
	guogeToInch[29] = 0.011;
	guogeToInch[30] = 0.01;
	guogeToInch[31] = 0.0089;
	guogeToInch[32] = 0.008;
	guogeToInch[33] = 0.0071;
	guogeToInch[34] = 0.0063;
	guogeToInch[35] = 0.0056;
	guogeToInch[36] = 0.005;
	guogeToInch[37] = 0.0045;
	guogeToInch[38] = 0.004;
		
		/// *********** CLASS PRICESS
		function Prices(id)
		{
			
			// CONSTRUCTORS
			


			this.itemID =  GetinnerText(document.getElementById("itmeGUID_"+id));
			this.Qtn = document.getElementById("cart_item_qtn_"+id);
			this.Weight = GetinnerText(document.getElementById("Weight_gr_"+id));
			this.lowQtn =  GetinnerText(document.getElementById("lowQtn_"+id));
			this.highQtn =  GetinnerText(document.getElementById("highQtn_"+id));
			this.Unit = GetinnerText(document.getElementById("Unit_"+id));
			this.AidUnit = GetinnerText(document.getElementById("AidUnit_"+id));
			this.priceSale =  cleanPrice(GetinnerText(document.getElementById("PriceSale_"+id)));
			this.price1 =  GetinnerText(document.getElementById("price1_"+id));
			this.price2 =  GetinnerText(document.getElementById("price2_"+id));
			//this.price1 =  GetinnerText(document.getElementById("price1_"+id));
			this.price3 =  GetinnerText(document.getElementById("price3_"+id));
			this.agent =  GetinnerText(document.getElementById("agent_"+id));
			this.price = document.getElementById("price_"+id);
			this.ItemType = isObject(document.getElementById("ItemType_"+id)) ? GetinnerText(document.getElementById("ItemType_"+id)) : '';
			this.Calculated_Weight = document.getElementById("Calculated_Weight_"+id);
			this.itemGlodColor = GetinnerText(document.getElementById("GlodColor_"+id));
			this.GlodColorSelect = document.getElementById("GlodColorSelect_"+id);
			this.Metal = GetinnerText(document.getElementById("Metal_"+id));
			this.itemKarat = GetinnerText(document.getElementById("Karat_"+id));
			this.ThicknessSelect = document.getElementById("Thickness_Select_"+id);
			this.HardnessSelect = document.getElementById("Hardness_"+id);
			
			
			this.diam = document.getElementById("diam_"+id);
			this.widthMM = GetinnerText(document.getElementById("widthMM_"+id));
			this.widthMM_Select = document.getElementById("widthMM_Select_"+id); 
			this.width_view = document.getElementById("width_view_"+id);
			this.thicknessMM = GetinnerText(document.getElementById("thicknessMM_"+id));
			this.SolidCream = GetinnerText(document.getElementById("SolidCream_"+id));
			this.ConvertingFactor = GetinnerText(document.getElementById("ConvertingFactor_"+id));
			this.itemSpecifications = GetinnerText(document.getElementById("Specifications_"+id));
			this.itemQuantity =  document.getElementById("cart_item_qtn_"+id); 
			this.ItemName = GetinnerText(document.getElementById("ItemName_"+id));
			this.ItemNo = GetinnerText(document.getElementById("ItemNo_"+id));
			this.tmpWeight = 0;
			this.fldAttr = null;
			this.tmpPrice = 0;
			this.rv = 0;
			this.volume = 1;
			this.pi=3.1415926535897932384626433832795;
			this.setTmpPrice = setTmpPrice;
			this.priceFactor = parseInt(this.Qtn.value);
			
			this.debug = document.getElementById("debug_"+id);
			this.debugmode = true;
			this.trace = tracedebug;
			this.CalcObj = document.getElementById("CalcMode_"+id);
			this.CalcMode = GetinnerText(document.getElementById("CalcMode_"+id));
			
	
			
			/******** LENGTH CONVERTORS ******************/
			this.Length_mm =  isObject(document.getElementById("Length_mm_"+id)) ? document.getElementById("Length_mm_"+id) : null;
			this.Length_Unit = document.getElementById("Length_Unit_"+id);
			this.FromLengthVal = this.Length_Unit[this.Length_Unit.selectedIndex].value;
			this.FromLengthName =  this.Length_Unit.options[this.Length_Unit.selectedIndex].text;
			this.ToLengthVal = 0.01;
			this.ToLengthName = 'Centimeter';
			this.LengthFactor = eval("(" + this.FromLengthVal + ")/(" + this.ToLengthVal + ")");
			this.convertedLength = 1
			/*********** LENGTH CONVERTORS END ************/

			/******** WEIGHT CONVERTORS ******************/
			this.Weight_Unit = document.getElementById("Weight_Unit"+id);
			
			
			this.SelectedWeightVal = this.Weight_Unit[this.Weight_Unit.selectedIndex].value;
			this.FixFromWeightVal = 1; // allwes start from grams
			this.ToWeightVal = 1;// allwes finish with grams
			this.ToWeightName = 'Gram';
			this.WeightFactor = eval("(" + this.FixFromWeightVal + ")/(" + this.ToWeightVal + ")");
			this.convertedWeight = 1
			this.ctype = 1;
			if(this.ItemType == 'h')
			{
				this.ctype = 2;
			}
			
			/*********** WEIGHT CONVERTORS END ************/
			
			this.totalPrice = 0
			this.setPrice = CalcPrice//setItemPrice;
			this.addCart = newCart
			this.addCalc = newCalc
			
			if(this.AidUnit=='')this.AidUnit='pcs';
			this.lengthCalc = false;
			this.lengthCalcList = new Array('p','c','w','h','s','f','t','q');
			this.wiresCalc = false;
			this.wiresCalcList = new Array('c','w','h');
			this.stripCalc = false;
			this.stripCalcList = new Array('s','f','t','q'); 
			this.hardnens =  false;
			this.hardnensList = new Array('w','h','s'); 
			
			Array.prototype.inArray = function (value)
			// Returns true if the passed value is found in the
			// array.  Returns false if it is not.
			{
					var i;
					for (i=0; i < this.length; i++) {
							// Matches identical (===), not just similar (==).
							if (this[i] === value) {
									return true;
							}
					}
					return false;
			};
			
			if (this.lengthCalcList.inArray(this.ItemType)) {
    		this.lengthCalc = true;
			}
			if (this.wiresCalcList.inArray(this.ItemType)) {
						this.wiresCalc = true;
			}
			if (this.hardnensList.inArray(this.ItemType)) {
						this.hardnens = true;
			}
			/*if (this.Metal.toLowerCase() =='gol' && this.ItemType ='p')
			{
				//this.hardnens = true;
			}*/
			if (this.stripCalcList.inArray(this.ItemType)) {
						this.stripCalc = true;
			}
}

function tracedebug(str)
{
	
	if(this.debugmode)
	{
		if(this.debug!==null && this.debug.innerHTML.indexOf(str)!=-1)
		{
			this.debug.style.display = '';
			//this.debug.innerHTML  += '<br />' + str  ;
		}
	}
	
}

function cleanPrice(sPrice)
{
	return sPrice.replace(/,/g,"");
}

function setTmpPrice()
{
	if(this.lengthCalc ||this.wiresCalc || this.stripCalc)
			{
				this.priceFactor =  this.convertedWeight;
			}
				this.rv = Convert2Float(this.priceSale); 
				if(parseInt(this.priceFactor)>=parseInt(this.lowQtn)&&parseInt(this.priceFactor)<=parseInt(this.highQtn))
				{
					this.rv = Convert2Float(this.price1); 
				}
				else 
				{
					if(parseInt(this.priceFactor)>=parseInt(this.highQtn))
					{
						this.rv = Convert2Float(this.price2); 
					}
				}
				if(this.agent == 1)
				{
					this.rv =  Convert2Float(this.price3); 
				}
				return  Convert2Float(this.priceFactor) * Convert2Float(this.rv);
}  
function Convert2Float(s)
{
		s = s.toString()
		while(s.indexOf(",") != -1)
		{
			 s = s.replace(',', '')
		}	 
		return parseFloat(s);
}
function CalcPrice()
		{
			if(!justnumPoint(this.Qtn))
			{
				//this.Qtn.value = 1;
				this.Qtn.focus();
				//this.Qtn.select();
			}
			
			this.tmpPrice = this.setTmpPrice();
				
			
			if( this.lengthCalc)
			{
				
				
					if (isNaN(this.Length_mm.value)) this.Length_mm.value = 1;
  				this.Length_mm.value = stripBad(this.Length_mm.value)
					this.convertedLength = get_result(this.Length_mm.value, this.LengthFactor) ;
					
					if( (this.ItemType!= 'p') && (this.ItemType !='') )
					{
									
									if (this.stripCalc)//plate 
									{									
										
										if(trim(this.widthMM).length ==0 && ( (this.ItemType =='s') || (this.ItemType =='f') ) ) this.widthMM = (70);
										if(this.itemKarat==999 && this.Metal.toLowerCase() =='sil')this.itemKarat = 999;//change from 909 prev version
										if(this.ItemType =='t') this.widthMM = parseFloat(this.widthMM_Select.value) ; //strips *10
										if(this.ItemType =='q' )
										{
											this.widthMM = parseFloat(this.ThicknessSelect.value)* 10; //strips squre calcutaed width
											SetInnerText(this.width_view,this.ThicknessSelect.options[this.ThicknessSelect.selectedIndex].text );//+ ' mm'
										}
										this.volume=(this.ThicknessSelect.value/10)*(this.widthMM/10)*(this.convertedLength/1);
											if (this.itemKarat==999 && this.Metal.toLowerCase() !='sil'){this.tmpWeight  = this.volume*19.30;}//24K
											if (this.itemKarat==909 || (this.itemKarat==999 && this.Metal.toLowerCase() =='sil')){this.tmpWeight  = this.volume*10.5;}//24K
											if (this.itemKarat==925){this.tmpWeight  = this.volume*10.37;}//sikverK
											if (this.itemKarat==917){this.tmpWeight  = this.volume*17.82;}//22K
											if (this.itemKarat==875){this.tmpWeight  = this.volume*17.10;}	//21K
											if (this.itemKarat==750){this.tmpWeight  = this.volume*15.54;}		//18K
											if (this.itemKarat==585){this.tmpWeight  = this.volume*13.04;}			//14K
											if (this.itemKarat==417){this.tmpWeight  = this.volume*11.70;}		//10K
											if (this.itemKarat==375){this.tmpWeight  = this.volume*10.82;}		//9K
											if (this.itemKarat<303){this.tmpWeight  = this.volume*10.75;}		//9K
										this.tmpWeight=Math.round(this.tmpWeight*10000)/10000;
									}
									else if(this.wiresCalc)//wires
									{
										this.volume=(this.pi*(this.diam.value/20)*(this.diam.value/20)*(this.convertedLength/1))/this.ctype; 
										this.tmpWeight=karat2gram(parseFloat(this.itemKarat),parseFloat(this.volume));
											if (this.itemKarat==999 && this.Metal.toLowerCase() !='sil'){this.tmpWeight  = this.volume*19.30;}//24K
											if (this.itemKarat==909 || (this.itemKarat==999 && this.Metal.toLowerCase() =='sil')){this.tmpWeight  = this.volume*10.5;}//24K
											if (this.itemKarat==925){this.tmpWeight  = this.volume*10.37;}//sikverK
											if (this.itemKarat==917){this.tmpWeight  = this.volume*17.82;}//22K
											if (this.itemKarat==875){this.tmpWeight  = this.volume*17.10;}	//21K
											if (this.itemKarat==750){this.tmpWeight  = this.volume*15.54;}		//18K
											if (this.itemKarat==585){this.tmpWeight  = this.volume*13.04;}			//14K
											if (this.itemKarat==417){this.tmpWeight  = this.volume*11.70;}		//10K
											if (this.itemKarat==375){this.tmpWeight  = this.volume*10.82;}		//9K
											if (this.itemKarat<303){this.tmpWeight  = this.volume*10.75;}		//9K
										this.tmpWeight =Math.round(this.tmpWeight*10000)/10000;
									}
									if((this.ItemType =='q'))
									{
											this.convertedWeight = (parseFloat(this.tmpWeight)/10);///10
									}
									else
									{
											this.convertedWeight = (parseFloat(this.tmpWeight));///10
									}
						
					}
					else
					{
							this.convertedWeight =  (this.convertedLength)*(parseFloat(this.Weight/100));
					}
					
							
					//this.convertedWeight = parseFloat(this.Weight/100)* (this.Qtn.value);
					this.WeightFactor = eval("(" + this.FixFromWeightVal + ")/(" + this.SelectedWeightVal + ")");
					this.Calculated_Weight.value = get_result(this.convertedWeight , this.WeightFactor) ;
					this.tmpPrice = this.setTmpPrice();
					this.totalPrice = this.tmpPrice;// this.convertedWeight  *  this.tmpPrice
					
			}
			else
			{
				
				//this.convertedWeight = this.Calculated_Weight.value;
				//this.FromWeightVal = (this.FromWeightVal==1  ) ?  1.555174  : 1 ;
				//this.ToWeightVal = (this.FromWeightVal==1.555174  ) ?  1 : 1.555174 ;
				
				//this.WeightFactor = eval("(" + this.FromWeightVal + ")/(" + this.ToWeightVal + ")"); 
				//this.Calculated_Weight.value = get_result(this.LastWeight.value , this.WeightFactor) ;
				//this.LastWeight.value = this.Calculated_Weight.value ;
				
				
				this.totalPrice = this.tmpPrice ;  
			}
			
			this.price.value = this.totalPrice.toFixed(2);
			this.trace(this.price.value);
			return this.rv;
			
		
		}
		
		
		
		function setItemPrice()
		{
			this.price.value =  parseFloat(this.totalPrice);
		}
		
		function chkPrice(id)
		{
				var newPrice = new Prices(id);
				newPrice.setPrice() 
		}

// Cart 
	function AddToCart(id)
	{
		var setCart = new Prices(id);
				setCart.setPrice();
				setCart.addCart();
	}
	
	function AddToCalc(id)
	{
		var setCalc = new Prices(id);
		setCalc.addCalc();
		setCalc.setPrice();
		setCalc.addCart();
	}
	
	function newCalc()
	{
		SetInnerText(this.CalcObj,1);
		this.CalcMode = GetinnerText(this.CalcObj);
	}
	
	function newCart()
	{ 
		if(parseFloat(this.Length_mm.value)==0)
		{
			alert('Length Value is not valid');
			return false
		}
		if(parseFloat(this.itemQuantity.value)==0)
		{
			alert('Quantity Value is not valid');
			return false
		}
		if(this.price.value<1)
		{
				alert('The minimum sale per item is 1 Dolar!');
				return false
		}
		if(this.ItemNo.length!=0)
			this.fldAttr = 'Cat No:' + this.ItemNo + '. |';
		
			if(this.GlodColorSelect.value.length!=0)
			{
				if(this.GlodColorSelect.value.length!=0)
				this.fldAttr += ' ' + ' Color:' + this.GlodColorSelect.value + '. |';
			}
			else
			{
				if(this.itemGlodColor.length!=0)
					this.fldAttr += ' ' + ' Color:' + this.itemGlodColor + '. |';
			}
		
		/*if(this.Metal =='gol')
		{
				if(this.GlodColorSelect.value.length!=0)
				this.fldAttr += ' ' + ' Color:' + this.GlodColorSelect.value + '. |';
		}
		else
		{
			
				if(this.itemGlodColor.length!=0)
					this.fldAttr += ' ' + ' Color:' + this.itemGlodColor + '. |';
			
		}*/
		if(this.itemKarat.length!=0)
			this.fldAttr += ' ' + ' Karat:' + this.itemKarat + '. |';
		if(this.itemSpecifications.length!=0)
			this.fldAttr += ' ' + ' Specifications:' + this.itemSpecifications + '. |';
		if( (this.lengthCalc) || (this.stripCalc) || (this.wiresCalc) ) 
		{
			if( (this.lengthCalc))
			{
				
				this.fldAttr += ' ' + ' Length:' + this.Length_mm.value + ' '+ this.Length_Unit[this.Length_Unit.selectedIndex].text  + '[' +this.convertedLength+ ' cm ]. |' ;
			}
			if((this.stripCalc))
				{
					this.fldAttr += ' ' + ' Thickness: (' + this.ThicknessSelect.value + ') ' + this.ThicknessSelect[this.ThicknessSelect.selectedIndex].text + '. | '; 
					if(this.ItemType =='q' )
  					{
						this.fldAttr += ' ' + ' Width: (' + this.ThicknessSelect.value + ') ' + this.ThicknessSelect[this.ThicknessSelect.selectedIndex].text + '. | '; 
					}
					else
					{
						this.fldAttr += ' ' + ' Width: (' + this.widthMM + ')  mm. | '; 
					}
				}
			if((this.wiresCalc)) 
				{
					this.fldAttr += ' ' + ' Diam:' + this.diam.value + '. |' ;
				}
			if((this.hardnens)) 
				{
					this.fldAttr += ' ' + ' Hardness:' + this.HardnessSelect.value + ', | ';
				}
				
			this.fldAttr += ' ' + ' Calculated Weight:' + this.Calculated_Weight.value + ' ' + this.Weight_Unit[this.Weight_Unit.selectedIndex].text +  '[' + this.convertedWeight + ' grams ].'; 
		}
		if(this.CalcMode==0)
		{
			document.location = '/ws3engine/manage_cart.asp?mode=additem&prodId='+this.itemID+'&SpeicalPrice='+this.price.value+'&fldAttr='+this.fldAttr+'&fldQtn='+this.itemQuantity.value+'&addType='+this.AidUnit
		}
		else
		{
			alert('Calc mode')
			document.location = '/ws3engine/manage_calc.asp?mode=additem&prodId='+this.itemID+'&SpeicalPrice='+this.price.value+'&fldAttr='+this.fldAttr+'&fldQtn='+this.itemQuantity.value+'&addType='+this.AidUnit
		}
		//alert(this.fldAttr) 
	}


/***************** GOLD UTILS ******************/
function karat2gram(k,cm3)
// this rutine recives karat from db value base on the following table 
// k22=17.82,K21=17.10,K18=15.54,K14=13.04,K10=11.70,K9=10.82,K8=10.75
{
	
	var nw=cm3;
	{
	if (k==999){nw = cm3*19.30;}//24K
	if (k==909){nw = cm3*10.5;}//24K
	if (k==925){nw = cm3*10.37;}//sikverK
	if (k==917){nw = cm3*17.82;}//22K
	if (k==875){nw = cm3*17.10;}	//21K
	if (k==750){nw = cm3*15.54;}		//18K
	if (k==585){nw = cm3*13.04;}			//14K
	if (k==417){nw = cm3*11.70;}		//10K
	if (k==375){nw = cm3*10.82;}		//9K
	if (k<303){nw = cm3*10.75;}		//9K
	}

	return nw;
}

function googToMilimeter(val)
{


}




//****************** UTILS ***************/
		function justnumPoint(obj)
		{
			//nodeName = "form_" + nodeId ;
			var g=obj.value ;
			has_point = false;
			var has_minus = false;
			if(g=='' || g==0 || parseInt(g).toString()=='NaN')
			{
				return false;
			}
			if(parseInt(g).toString()!='NaN' && parseInt(g)<1)
			{
				return false;
			}
			for(var gi=0;gi<g.length;gi++)
			{	
				num = g.charCodeAt(gi);
				if(num > 47 && num < 58 || num == 46 || num == 45 )
				{
					if(has_point == false && num == 46)has_point = true;
					else if(has_point == true && num == 46)
					{
						alert('only  one point');
						return false;
					}
					if(has_minus == false && num == 45 && gi == 0)has_minus = true;
					else if(has_minus == false && num == 45 && gi > 0)
					{
						alert('minus first');
						return false;
					}
					else if(has_minus == true && num == 45)
					{
						alert('only one minus');
						return false;
					}
				}
				else 
				{	
					alert('number or point only');
					return false;
				}
			}
			return true;
		}
		function isObject(obj)
		{
			if(obj==null)
			{	
				return false;
				
			}
			else
			{
				return true;
			}
			
		}
		function stripBad(string) {
    for (var i=0, output='', valid="eE-0123456789."; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
} 

function get_result(ff,factor){
 ff *= factor;

 if (Number.prototype.toFixed) {
   ff = ff.toFixed(7);
   ff = parseFloat(ff);
 }
 else {
   var leftSide = Math.floor(ff);
   var rightSide = ff - leftSide;
   ff = leftSide + Math.round(rightSide *10000000)/10000000;
 }

 return ff;//comma(ff);
}	

function trim(str)
{
	str.replace(/^\s*|\s*$/g,"");
	return str;
}
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var GlodItems = new Array();
function joinItems(itemID,karat)
{
	GlodItems.push();  
	GlodItems[GlodItems.length] = new Array(itemID,karat);
	addKaratOptions(karat);
}
function sortByElement(val,ind)
{
	for(i=0;i<GlodItems.length;i++)
	{
		document.getElementById("tblItem_"+GlodItems[i][0]).style.display ='';
		if(val.toString().toLowerCase()!='all')
		{
			if(val.toString()!=GlodItems[i][ind].toString())
			{
				document.getElementById("tblItem_"+GlodItems[i][0]).style.display = 'none';
			}
		}
	}
}
function addKaratOptions(karat) 
{
	var FilterKaratSelect = document.getElementById("FilterKaratSelect");
	var DontAddSelect = false;
	if(FilterKaratSelect!=null)
	{
		for(x=0;x<FilterKaratSelect.options.length;x++)
		{
			if(FilterKaratSelect.options[x].value==karat)
			{
				DontAddSelect = true;
			}
		}
		var karatText = Math.round(karat/1000*24)+'K';
		if(karat==999 || karat==925)
		{
			karatText = karat+'Sliver';
		}
		
		/*if(karat==999)
		{
				karatText = 'SilverKarat';
		}*/
		
		if(!DontAddSelect)
		{
			if(karat!='')
			{
				FilterKaratSelect.options[FilterKaratSelect.length] = new Option(karatText,karat);
			}
		}
		DontAddSelect = false;
		if(FilterKaratSelect.options.length>1)
		{
			showFilterKaratSelect();
		}
	}
}
function showFilterKaratSelect()
{
	document.getElementById("FilterKaratTD").style.display='';
}
function VaildSearch(objForm)
{
	if(objForm.strSearch.value.length<3)
			{
				alert('Search Word is Too short');
				return false;
			}
			return true;
}
//########################## Cost Calcutator start ########################### //

function addPrivteItem(id,nItemType,addType)
{
	var fldAttr = document.getElementById('fldAttr_'+id);
	var Qtn = document.getElementById('Qtn_'+id);
	var SpeicalPrice = document.getElementById('SpeicalPrice_'+id);
	document.location = '/ws3engine/manage_calc.asp?mode=additem&prodId=newItem&SpeicalPrice='+SpeicalPrice.value+'&fldAttr='+fldAttr.value+'&fldQtn='+Qtn.value+'&ItemType='+nItemType+'&addType='+addType
}
function OepnObj(id)
{
	document.getElementById('tr_'+id).style.display = 'block';
}

function CloseObj(id)
{
	document.getElementById('tr_'+id).style.display = 'none';
}

function calcArr(arr,ItemType)
{
	var sums = 0
	//alert(arr.length)
	for(var i=0;i<arr.length;i++)
	{
		var id = arr[i][0];
		var typ = arr[i][1];
		if(ItemType==typ)
		{
			var fldAttr = document.getElementById('fldAttr_'+id);
			var Qtn = document.getElementById('Qtn_'+id);
			var Price = document.getElementById('Price_'+id);
			var TotalObj = document.getElementById('Total_'+id);
			if(Qtn.value=='')Qtn.value=1;
			if(Price.value=='')Price.value=1;
			if(ItemType!=5)
			{
			TotalObj.value =  parseFloat(parseFloat(Qtn.value)*parseFloat(Price.value));
			
			}
			if(isNaN(TotalObj.value))TotalObj.value=0;
			sums += parseFloat(TotalObj.value);
			if(document.getElementById('sum_'+typ)!=null)
			{
				SetInnerText(document.getElementById('sum_'+typ),sums.toFixed(2));
			}
		}
	}
	
	return sums;
}
function getAttQnt(arr)
{
var SumQnt = 0
for(var t=0;t<arr.length;t++)
	{
	var id = arr[t][0];
	var Qtn = document.getElementById('Qtn_'+id);
	var Price = document.getElementById('Price_'+id);
		if(isNaN(Qtn.value))Qtn.value=0;
		if(isNaN(Price.value))Price.value=0;
		if(parseInt(Qtn.value)*parseInt(Price.value)!=0)
			SumQnt += parseInt(Qtn.value);
	}
	return SumQnt;
}
function calcCost()
{
	var TotalItemPrice = 0;
	var sumsItmes = calcArr(Items,1);
	var sumsDesignTimes = calcArr(Times,2);
	var sumsCraftingTimes = calcArr(Times,4);
	var sumsWorks = calcArr(Works,3);
	var sumsOverheads = calcArr(Overheads,5);
	var num_of_workers = document.getElementById('Workers_number');
	if(isNaN(num_of_workers.value))num_of_workers.value=1;
	var TotalTimes = getAttQnt(Times);
	if(TotalTimes==0)TotalTimes=1;
	var TotalPotentialWorkersTime = 185*parseInt(num_of_workers.value);
	TotalItemPrice = sumsItmes+sumsDesignTimes+sumsCraftingTimes+sumsWorks+sumsOverheads;
	
	
	var TotalOverheadsPerItem =	(TotalItemPrice*TotalTimes)/TotalPotentialWorkersTime
	if(document.getElementById('sum_total')!=null)SetInnerText(document.getElementById('sum_total'),(TotalItemPrice+TotalOverheadsPerItem).toFixed(2));
	if(document.getElementById('sum_calc_overhead')!=null)SetInnerText(document.getElementById('sum_calc_overhead'),TotalOverheadsPerItem.toFixed(2));
}
function OpenPanel(id)
{
	var panel = document.getElementById('Panel_'+id);
	var img = document.getElementById('IMG_'+id);
	panel.style.display =(panel.style.display=='none') ? 'block': 'none';
	img.src = (panel.style.display=='block') ? 'template/images/minus.gif' : 'template/images/plus.gif';
}
//########################## Cost Calcutator end ########################### //