var productListWidth=60;

requiredUserInfo=new Array(
"Username","name",
"Company","company name",
"Street","street address",
"City","city",
"State","state",
"Zip","zip code",
"Country","country",
"Telephone","phone number",
"Email","e-mail address");



requiredUserInfo=new Array(
"Username","name",
"Company","company name",
"Street","street address",
"City","city",
"State","state",
"Zip","zip code",
"Country","country",
"Telephone","phone number",
"Email","e-mail address");

allPagesNames = new Array(
	"index.html",
	"products.html",
	"specials.html",
	"order.html",
	"order_old.html",
	"contact.html",
	"thebest.html",
	"features.html",
	"compar.html",
	"regalia.html",
	"nobilia.html",
	"lotus.html",
	"stoptav.html",
	"jwlshine.html",
	"stmjwlac.html",
	"clguide.html",
	"overtech.html",
	"selectionGuide.html",	
	"jewelryIndustry.html",
	"dentalIndustry.html",
	"maintenance.html"

);

function getIndex()
{
var tr = location.pathname;
var fn="";

len = tr.length;
if(len<2)
 return(1);

rs = 0;
for (i = len-1; i >= 0; i--) 
{ 
	vb = tr.substring(i,i+1);


	if ((vb == "/" || vb=="\\" || i==0 )&& rs == 0) 
	{ 
		fn= tr.substring(i+1,len);
		rs = 1;
	
	} 
} 

for(j=0;j<allPagesNames.length;j++)
{
	
	if(allPagesNames[j] == fn)
	{
		return(j+1);
	}
}
return(j+1);

}

function highLight(index)
{

  if(index>24)
	index =5;

  if (index==1)
    {
      document.images.IMG1.src="mi_home_s.gif";
    }

  if (index==2)
    {
      document.images.IMG2.src="mi_products_s.gif";
    }

  if (index==3)
    {
      document.images.IMG3.src="mi_specials_s.gif";

    }

  if (index==4 || index==5)
    {
      document.images.IMG4.src="mi_order_s.gif";
    }

  if (index==6)
    {

      document.images.IMG5.src="mi_contact_s.gif";
    }

  if (index > 6)
    {
      index = index + 3;
      document.images.IMG2.src="mi_products_s.gif";
      document.getElementById("anchor"+index ).style.color="yellow";
    }


}

function selectMenu(index)
{
   if(index>9)
	index = index - 3;
      location.href = allPagesNames[index-1];
}


function validateUserInfo(form)
{
	for (i=0;i<requiredUserInfo.length;i+=2)
		if (form[requiredUserInfo[i]].value=="") {
		alert("Please enter your "+requiredUserInfo[i+1]+" in the specified field.");
		form[requiredUserInfo[i]].focus();
		return false;
	}

	if (form.order.value=="") {
		alert("You have not ordered anything !\nIf you have trouble ordering, please contact us.");
		form.order.focus();
		return false;
	}
	return true;
}


function validateForm(form)
{

	if(form.amount.value == "")
	{
		alert("You have not ordered anything !\nIf you have trouble ordering, please contact us.");
		return false;
	}
	else
		return true;
}


function round2d(x)
{
	return Math.ceil(100*x)/100;
}

function arangeRightStr(s,k)
{
	var sr=s;
	if (sr.length<k)
		{
			var l=sr.length;
			for(var i=0;i<k-l;i++)
				sr=' '+sr;
			return sr;
		}
	else
		return sr;
}

function arangeLeftStr(s,k)
{
	var sr=s;
	if (sr.length<k)
		{
			var l=sr.length;
			for(var i=0;i<k-l;i++)
				sr+=' ';
			return sr;
		}
	else
		return sr;
}


function alignVirgula(x,s,k)
{
	var f1=0.0;
	f1=Math.ceil(100*x)/100;
	var i1=0;
	i1=Math.ceil(100*x)%100;
	var i2=0;
	if (i1==0)
		i2=3;
	else
		if ((i1%10)==0)
			i2=1; 
	if (i2==3)
		s=s+'.00';
	if (i2==1)
		s=s+'0';
	return arangeRightStr(s,k);
}

var steamshineOptionList=new Array(
		'Option ShinemasterTM',299,
		'Option Turbo',299,
		'Option Deluxe',299,
		'Option Plus',299,
		'AutoFill System w/ Pump',999,
		'Autofill Passive',599,
		'FLEXIBLE HOSE, HANDLE  & NOZZLE:',199);

var compucraftOptionList=new Array(
	'----------- For option prices please contact us ! ----------',-1,
	'3D Scanner',0,
	'3D Scanner Adaptor Cable',0,
	'Rotary Table 3" with Automatic Centering',0,
	'EM Controlled Engraving Pen',0,
	'500 W Cutting Spindle,diameter=1/8" & 1/4"',0,
	'Automatic Switch for Spindle',0);

var allOptionsIncludedList=new Array(
	'------------------- Includes all options ! -----------------',-1);


var emptyOptionList=new Array('None',-1);

var productOptionsListsList=new Array(emptyOptionList,steamshineOptionList,compucraftOptionList,allOptionsIncludedList);


var productList=new Array(
		'------------------------ STEAMSHINE[TM] ------------------------',-1,0,
		'CL2020 Lotus    1/2 Gallon SteamshineTM' ,648,1,
		'CL2010 Lotus    1.4 Gallon SteamshineTM' ,899,1,
		'CL2010 Nobilia  1.4 Gallon SteamshineTM',1199,1,
		'CL2005 Lotus    2.2 Gallon SteamshineTM' ,1099,1,
		'CL2005 Nobilia  2.2 Gallon SteamshineTM',1499,1,
		'CL2005 Regalia  2.2 Gallon SteamshineTM',2488,1,
		'CL2000 Lotus    4.4 Gallon SteamshineTM', 1599,1,
		'CL2000 Nobilia  4.4 Gallon SteamshineTM',1899,1,
		'CL2000 Regalia  4.4 Gallon SteamshineTM',3588,1,
		'CL9001 Lotus    6.0 Gallon SteamshineTM', 2199,1,
		'CL9001 Nobilia  6.0 Gallon ShinemasterTM',2599,1,
		'CL9001 Regalia  6 Gallon SteamshineTM',4488,1,
		'CL2010 Regalia  1.4 Gallon SteamshineTM',1588,1,
		'------------------------ ULTRASONIC ------------------------',-1,0,
		'US300 MH          3 Quarts/Liters  300 W', 499,0,
		'US500 MH          5 Quarts/Liters  450 W', 899,0,
		'US700 MH          7 Quarts/Liters  600 W', 1299,0,
		'US1000 MH         10 Quarts/Liters  680 W', 1499,0,
		'US2000 MH         20 Quarts/Liters  920 W', 1699,0,
		'US3000 MH         30 Quarts/Liters 1220 W', 1999,0,
		'------------------------ ACCESSORIES -----------------------',-1,0,
		'J88-.4',						             10,0,
		'J88-1',						             33,0,
		'RGP57-.4',						             51,0,
		'RGP57-1',						             149,0,
		'706 Jewelshine[TM] Stone Saver',             3,0,
		'806 Jewelshine[TM] 6" SpringAction[TM] Tweezer',4,0,
		'808 Jewelshine[TM] 8" SpringAction[TM] Tweezer',5,0,
		'908 Jewelshine[TM] 8" Steamshine[TM] Tweezer',  4,0,
		'910 Jewelshine[TM] 10" Steamshine[TM] Tweezer',  5,0,
		'912 Jewelshine[TM] 12" Steamshine[TM] Tweezer',  6,0,
		'116 Jewelshine[TM] Racks',	             6,0,
		'SP 25             Small SplashPan',         14,0,
		'SP 100            Medium SplashPan',        20,0,
		'SP 200            Large SplashPan',         22,0,
		'SP 600            SplashPan',	         44,0
	
		);

function replaceStrWithStr(sSP, sWhat, sWith)
{
	var srNBSP=sSP;

	while (srNBSP.search(sWhat)!=-1) {
		srNBSP=srNBSP.replace(sWhat,sWith);
	}

	return srNBSP;
}

function formProductName(listObject, nameWidth, i)
{
	var price;
	if (listObject[i+1]==-1)
		price='';
	else
		price=alignVirgula(parseFloat(listObject[i+1]),'$'+listObject[i+1],2);

	return arangeLeftStr(listObject[i],nameWidth-price.length)+price;
}

function addSelectOption(selectObject,text,value,dynamicUpdate)
{
	if (dynamicUpdate)  {
			var optionObject = new Option(text, value, false, false)
			selectObject.options[selectObject.options.length]=optionObject;
	}
	else
			document.write('<OPTION VALUE="',value,'">',text,'</OPTION>');
}

function fillProductList(listObject, listIncrement, selectObject, nameWidth, dynamicUpdate)
{
	if (dynamicUpdate) {
		for (var i = selectObject.length;i > 0;i--) {
			selectObject.options[0] = null;
		}
	}

	for (var i=0;i<listObject.length;i+=listIncrement) {
		var text=formProductName(listObject,nameWidth,i);
		if (!dynamicUpdate)
			text=replaceStrWithStr(text,' ','&nbsp;');
		else
			text=replaceStrWithStr(text,' ',String.fromCharCode(160));

		addSelectOption(selectObject,text,i,dynamicUpdate);
	}
}

function getCurrentAccessoriesList()
{
	var selected=document.Form1.products.selectedIndex;
	if (selected>=0) {
		var index=parseInt(document.Form1.products.options[selected].value,10);
		
		if (index>=0) {
			var optionsListIndex=parseInt(productList[index+2],10);
			var priceVal=parseInt(productList[index+1],10);
			var itemName=productList[index];
			
			if(priceVal>0)
			{
			document.Form1.item_name.value=itemName;
			document.Form1.amount.value=priceVal;

			}
			else
			{
			document.Form1.item_name.value="";
			document.Form1.amount.value="";
			}
		
			if (optionsListIndex>=0) {
				return productOptionsListsList[optionsListIndex];
			}
		}
		else
		{
				document.Form1.item_name.value="";
				document.Form1.amount.value="";
		}
	}
	return null;
}

function updateForm()
{
	var sel=document.Form2.options_available.selectedIndex;
	var ind=parseInt(document.Form2.options_available.options[sel].value,10);
	var priceVal=parseInt(steamshineOptionList[ind+1]);
	var itemName=steamshineOptionList[ind];
	
	if(priceVal>1 && document.Form2.options_available.options.length>1)
	{
			
			document.Form2.item_name.value=itemName;
			document.Form2.amount.value=priceVal;	
	}
	else
	{
	
			document.Form2.item_name.value="";
			document.Form2.amount.value="";
			
	}	
	
}

function fillOptionsList(dynamicUpdate)
{
	var optionsList=getCurrentAccessoriesList();
	if (optionsList!=null)
		fillProductList(optionsList,2,document.Form2.options_available,productListWidth,dynamicUpdate);
	updateForm();

}


function addProduct()
{
	var selectIndex=document.Form1.products.selectedIndex;
	var productIndex=parseInt(document.Form1.products.options[selectIndex].value,10);

	var productPrice=parseFloat(productList[productIndex+1]);

	if (productPrice<0)
		return;


	var quant=parseInt(document.Form1.quant.value,10);
	if ((isNaN(quant))||(quant<=0)) {
		alert('The quantity value must be a positive integer !');
		return;
	}

	totprice=round2d(productPrice*quant);
	document.Form1.order.value=document.Form1.order.value+formProductName(productList,productListWidth,productIndex)+arangeRightStr(String(quant),8);
	document.Form1.order.value=document.Form1.order.value+alignVirgula(totprice,'$'+totprice,17)+'\n'
	document.Form1.total.value=round2d(parseFloat(document.Form1.total.value)+totprice);
}

function addAccessories()
{
	var optionsList=getCurrentAccessoriesList();
	if (optionsList==null)
		return;

	var selectIndex=document.Form1.options_available.selectedIndex;
	var productIndex=parseInt(document.Form1.options_available.options[selectIndex].value,10);
	var productPrice=parseFloat(optionsList[productIndex+1]);

	if (productPrice<0)
		return;

	var quant=parseInt(document.Form1.quantAccess.value,10);
	if ((isNaN(quant))||(quant<=0)) {
		alert('The quantity value must be a positive integer !');
		return;
	}
	totprice=round2d(productPrice*quant);
	document.Form1.order.value=document.Form1.order.value+formProductName(optionsList,productListWidth,productIndex)+arangeRightStr(String(quant),8);
	document.Form1.order.value=document.Form1.order.value+alignVirgula(totprice,'$'+totprice,17)+'\n'
	document.Form1.total.value=round2d(parseFloat(document.Form1.total.value)+totprice);
}


function clearOrder()
{
	document.Form1.total.value=0;
	document.Form1.quant.value=1;
	document.Form1.order.value="";
}

function loadData(index)
{

	var priceVal=parseFloat(productList[index+1]);
	var itemName=productList[index];
//	var f=document.getElementsByName("Form3");


	document.Form3.item_name.value=itemName;
	document.Form3.amount.value=priceVal;

	return true;	
}
