/*
PROJECT      Broyce Control Ltd
OWNERSHIP    Optimised Web Design, Philip Kay
ADDRESS      Duken House, Wootton, Bridgnorth, WV15 6EA, UK
TEL          +44 (0) 1746 781 653
MOBILE       +44 (0) 7711 317 681
EMAIL        kay@osltd.co.uk
RIGHTS       The contents and design of these pages are the property of
             the author who grants no rights for copying, distribution
             or reselling without prior written agreement.
COPYRIGHT    Copyright (c) 2009 Optimised Web Design
*/


function quote_change(Index){
	if((typeof Broyce) != "undefined"){
  	switch(Index){
  		case 1: Broyce.realname = document.quoteform.elements["realname"].value; break;
  		case 2: Broyce.company = document.quoteform.elements["company"].value; break;
  		case 3: Broyce.email = document.quoteform.elements["email"].value; break;
  		case 4: Broyce.address = document.quoteform.elements["address"].value; break;
  		case 5: Broyce.phone = document.quoteform.elements["phone"].value; break;
  		case 6: Broyce.fax = document.quoteform.elements["fax"].value; break;
  		case 7:
  			for(var i=0; i < document.quoteform.elements["industry"].options.length; i++){
  				if(document.quoteform.elements["industry"].options[i].selected){
  					Broyce.industry = document.quoteform.elements["industry"].selectedIndex;
  					break;
  				}
  			}
  		case 8:
  			for(var i=0; i < document.quoteform.elements["cd"].options.length; i++){
  				if(document.quoteform.elements["cd"].options[i].selected){
  					Broyce.cd = document.quoteform.elements["cd"].selectedIndex;
  					break;
  				}
  			}
  			break;
  	}
  	Broyce.store();
	}
}


function quote_load(){
	if((typeof Broyce) != "undefined"){
  	if(Broyce.realname) document.quoteform.elements['realname'].value = Broyce.realname;
  	if(Broyce.company) document.quoteform.elements['company'].value = Broyce.company;
  	if(Broyce.address) document.quoteform.elements['address'].value = Broyce.address;
  	if(Broyce.email) document.quoteform.elements['email'].value = Broyce.email;
  	if(Broyce.phone) document.quoteform.elements['phone'].value = Broyce.phone;
  	if(Broyce.fax) document.quoteform.elements['fax'].value = Broyce.fax;
  	if(Broyce.industry) document.quoteform.elements['industry'].selectedIndex = Broyce.industry;
  	if(Broyce.cd) document.quoteform.elements['cd'].selectedIndex = Broyce.cd;
	}
}


function fill_basket(){
	if((typeof Broyce) != "undefined"){
    document.writeln('<tr><td>&nbsp;</td></tr><tr><td colspan=4 valign=top>Use this table to Add/Change/Delete products for which you would like a quotation (optional).</td></tr>');
    document.writeln('<tr><td colspan=4 valign=top>');
    document.writeln('<table border=1 cellpadding=2 cellspacing=0 width="100%"><tr>');
    document.writeln('<td bgcolor="#809FE9" align=left valign=top>Broyce<br>Type N&ordm;</td>');
    document.writeln('<td bgcolor="#809FE9" align=right valign=top>Qty</td>');
    document.writeln('<td bgcolor="#809FE9" align=left valign=top>Competitor<br>Name</td>');
    document.writeln('<td bgcolor="#809FE9" align=left valign=top>Competitor<br>Type N&ordm;</td>');
    document.writeln('<td bgcolor="#809FE9" align=right valign=top>Qty</td>');
    document.writeln('<td bgcolor="#809FE9" align=right valign=top>Competitor<br>Price</td>');
    document.writeln('<td bgcolor="#809FE9" align=right valign=top>Edit</td></tr>');

  	var Basket = Broyce.basket;
  	if(Basket != '.'){
  		var Args = new Array();
  		Args = Basket.split('#');
  		for(var i=0; Args[i]; i++){
  			var I1 = Args[i].slice(1, Args[i].length-1);
  			Opt = I1.split(',');
  			for(var j=0; j < 6; j++) if(Opt[j] == '') Opt[j] = '&nbsp;';
  			document.writeln('<input type=hidden name=query'+i+' value="['+Opt[0]+', '+Opt[1]+', '+Opt[2]+', '+Opt[3]+', '+Opt[4]+', '+Opt[5]+', '+Opt[6]+']">');
  			document.writeln('<tr><td align=left>'+Opt[0]+'</td>');
  			document.writeln('<td align=right>'+Opt[1]+'</td>');
  			document.writeln('<td align=left>'+Opt[2]+'</td>');
  			document.writeln('<td align=left>'+Opt[3]+'</td>');
  			document.writeln('<td align=right>'+Opt[4]+'</td>');
  			if(Opt[6] != '&nbsp;') document.writeln('<td align=right>'+Opt[5]+Opt[6]+'</td>');
  			else document.writeln('<td align=right>'+Opt[6]+'</td>');
  			document.writeln('<td align=right><a href="javascript:delete_item('+i+')">Delete</a></td></tr>');
  		}
  	}
			document.writeln('<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>');
			document.writeln('<td align=right><a href="ADD.PHP">Add</a></td></tr>');
			document.writeln('</table></td></tr>');
	}
}


function delete_item(Val){
	var Basket = Broyce.basket;
	var Args = new Array();
	Args = Basket.split('#');
	var Cookie = '';
	var Cookie1 = '';
	for(var i=0; Args[i]; i++){
		if(i == Val) continue;
		if(Cookie == '') Cookie1 = Args[i];
		else Cookie1 = Cookie+'#'+Args[i];
		Cookie = Cookie1;
	}
	if(Cookie == '') Broyce.basket = '.';
	else Broyce.basket = Cookie;
	Broyce.store();
	window.location = "QUOTE.PHP";
}


function add_quote(){
	var Prod_type = addform.elements['prod_type'].value;
	var Prod_qty = addform.elements['prod_qty'].value;
	var Comp_name = addform.elements['comp_name'].value;
	var Comp_type = addform.elements['comp_type'].value;
	var Comp_qty = addform.elements['comp_qty'].value;
	var Comp_price = addform.elements['comp_price'].value;

	for(var i=0; i < addform.elements["comp_currency"].options.length; i++){
		if(addform.elements["comp_currency"].options[i].selected){
			var Comp_currency = addform.elements["comp_currency"].options[i].text;
			break;
		}
	}

	var Basket = Broyce.basket;
	var Cookie = '['+Prod_type+','+Prod_qty+','+Comp_name+','+Comp_type+','+Comp_qty+','+Comp_currency+','+Comp_price+']';

	if(Basket == '.') Broyce.basket = Cookie;
	else Broyce.basket = Basket+'#'+Cookie;
	Broyce.store();
	window.alert('Selection added to quotation');
}


