
function oCheckMainTrade(optMainTrade,oSells,noSells,obOpt,boolSell)
{
var obSell = document.getElementById(oSells);
var obNSell = document.getElementById(noSells);
var obOSell = document.getElementById(obOpt);

	if(boolSell == 'y')
	{
		if(obSell.checked == true)
			{
			obOSell.value = 'y';
			obNSell.checked = false; 
			}
			else
			{
			obOSell.value = "";
			}
	}
	if(boolSell == 'n')
	{	
		if(obNSell.checked == true)
			{
			obOSell.value = 'n';
			obSell.checked = false;
			}
		else
			{
			obOSell.value = "";
			}			
	}
	if(document.frmCust.MainOutlet[optMainTrade].checked)
	{
	resetOutletOpts();
	obSell.checked = false;
	obNSell.checked = false;
	obOSell.value = 'z';
	}
//sendOpts();
//alert(obOpt + ' - ' + boolSell + ' - '+ obOSell.value)
//alert(document.frmCust.OptsDetails.value);
}

function resetOutletOpts()
{
		if(document.frmCust.ownsite.value == 'z')
		{
			document.frmCust.ownsite.value = "";
		}
		if(document.frmCust.abebooks.value == 'z')
		{
			document.frmCust.abebooks.value = "";
		}				
		if(document.frmCust.amazon.value == 'z')
		{
			document.frmCust.amazon.value = "";
		}		
		if(document.frmCust.ebay.value == 'z')
		{
			document.frmCust.ebay.value = "";
		}		
		if(document.frmCust.oor.value == 'z')
		{
			document.frmCust.oor.value = "";
		}
		if(document.frmCust.ooa.value == 'z')
		{
			document.frmCust.ooa.value = "";
		}
}
function resetOptCells()
{
		styleObj=document.getElementById('BookCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('txtBookSeller').style;
 		styleObj.backgroundColor="#ad88d8";
		styleObj=document.getElementById('MainTradeCell').style;
 		styleObj.backgroundColor="#e2dff4";
		styleObj=document.getElementById('ownsiteCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('abebooksCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('amazonCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('ebayCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('oorCell').style;
 		styleObj.backgroundColor="#ad88d8";
 		styleObj=document.getElementById('ooaCell').style;
 		styleObj.backgroundColor="#ad88d8";	
}

function selBizType(frmCust)
{
resetOptCells();
var OptBookSeller  = -1;

	for (i=0;i<frmCust.IsBookSeller.length;i++)
	{
		if(frmCust.IsBookSeller[i].checked)
		{
		OptBookSeller = i
		}	
	}
	if(OptBookSeller  != -1)
	{
		var BizType = frmCust.IsBookSeller[OptBookSeller].value;
		
		if(BizType == "true")
		{
		ShopBookSeller.style.display='block';
		OnlineBookSeller.style.display='block';
		}
		if(BizType == "false")
		{
		OnlineBookSeller.style.display='none';
		ShopBookSeller.style.display='block';
		}
	}
	else
	{
	OnlineBookSeller.style.display='none';
	ShopBookSeller.style.display='none';
	}
return;
}

function cal(frmCust)
{
var choice = frmCust.selTitle.selectedIndex;
var title =(frmCust.selTitle.options[choice].value);
frmCust.Other.value = "";
frmCust.Title.value = title;
return;
}
function cal1(frmCust)
{
var title = frmCust.Other.value;
frmCust.selTitle.selectedIndex= 0;
frmCust.Title.value = title;
return;
}
function selCty(frmCust)
{
var choice = frmCust.CountryCode.selectedIndex;
var ctry =(frmCust.CountryCode.options[choice].text);
frmCust.Country.value = ctry;
return;
}
function Validate(frmCust)
{
		if(frmCust.Address1.value == "")
	{
		alert("Please enter your company / business name.");
		frmCust.Address1.focus();
		return false;
	}
	if(frmCust.Title.value == "" || frmCust.Title.value.length < 2)
	{
		alert("Please enter your title.");
		frmCust.selTitle.focus();
		return false;
	}
	if(frmCust.Name.value == "")
	{
		alert("Please enter your name.");
		frmCust.Name.focus();
		return false;
	}
		if(frmCust.Address2.value == "")
	{
		alert("Please enter street & door number");
		frmCust.Address2.focus();
		return false;
	}

		if(frmCust.Address3.value == "")
	{
		alert("Please enter your town/city");
		frmCust.Address3.focus();
		return false;
	}
	var i;
	i = frmCust.CountryCode.selectedIndex;		
	
	if(i == 0 || frmCust.CountryCode.options[i].text == "")
	{
		alert("Please select your Country");
		frmCust.CountryCode.focus();
		return false;
	}

	if(frmCust.CountryCode.options[i].text == "United Kingdom" && frmCust.Postcode.value == "")

	//UK Customer has not put postcode
	{
		alert("Please enter your post code.");
		frmCust.Postcode.focus();
		return false;
	}
	if(frmCust.CountryCode.options[i].text == "USA" && frmCust.Address5.value == "")

	//USA Customer has not put zip code
	{
		alert("Please enter your zip code.");
		frmCust.Address5.focus();
		return false;
	}
	
	
//	//Bookseller details
	resetOptCells();
	var OptBookSeller  = -1;

	for (i=0;i<frmCust.IsBookSeller.length;i++)
	{
		if(frmCust.IsBookSeller[i].checked)
		{
		OptBookSeller = i
		}	
	}
	if (OptBookSeller == -1)
	{
	alert("Please tell us whether you sell books online.");
	styleObj=document.getElementById('BookCell').style;
 	styleObj.backgroundColor="red";
 	styleObj=document.getElementById('txtBookSeller').style;
 	styleObj.backgroundColor="red";
 	frmCust.txtBookSeller.focus();
	return false;
	}
	
	var IsBookSeller = frmCust.IsBookSeller[OptBookSeller].value;
	var OptMainOutlet  = -1;
	
	if (IsBookSeller == "true")
	//An online bookseller
	{
		var OptMainTrade  = -1;
		

		for (i=0;i<frmCust.MainOutlet.length;i++)
		{
			if(frmCust.MainOutlet[i].checked)
			{
			OptMainTrade = i
			}	
		}
		if (OptMainTrade == -1)
		{
		alert("Please tell us your main \"online \"outlet as a bookseller.");
		styleObj=document.getElementById('MainTradeCell').style;
 		styleObj.backgroundColor="yellow";
 		frmCust.txtMainTrade.focus();
		return false;
		}
		//Check outlets
		if(document.frmCust.ownsite.value == "")
		{
			alert("Do you sell books on your own website? Please select Yes or No.");
			styleObj=document.getElementById('ownsiteCell').style;
 			styleObj.backgroundColor="red";
			return false;
		}
		if(document.frmCust.abebooks.value == "")
		{
			alert("Do you sell books on www.abebooks.com? Please select Yes or No.");
			styleObj=document.getElementById('abebooksCell').style;
 			styleObj.backgroundColor="red";
			return false;
		}				
		if(document.frmCust.amazon.value == "")
		{
			alert("Do you sell books on www.amazon.co.uk (UK website)? Please select Yes or No.");
			styleObj=document.getElementById('amazonCell').style;
 			styleObj.backgroundColor="red";
			return false;
		}		
		if(document.frmCust.ebay.value == "")
		{
			alert("Do you sell books on www.ebay.co.uk (UK website)? Please select Yes or No.");
			styleObj=document.getElementById('ebayCell').style;
 			styleObj.backgroundColor="red";
			return false;
		}		
		if(document.frmCust.oor.value == "")
		{
			alert("Do you sell books on any other book website? Please select Yes or No.");
			styleObj=document.getElementById('oorCell').style;
 			styleObj.backgroundColor="red";
			return false;
		}
		if(document.frmCust.ooa.value == "")
		{
			alert("Do you sell books on any other auction website? Please select Yes or No.");
			styleObj=document.getElementById('ooaCell').style;
 			styleObj.backgroundColor="red";	
			return false;
		}	
		
		for (i=0;i<frmCust.MainOutlet1.length;i++)
		{
			if(frmCust.MainOutlet1[i].checked)
			{
			OptMainOutlet = i
			}	
		}
		if (OptMainOutlet == -1)
		{
		alert("Please tell us your main outlet as a bookseller.");
		styleObj=document.getElementById('MainOutletCell').style;
 		styleObj.backgroundColor="yellow";
 		frmCust.txtMainOutlet.focus();
		return false;
		}
		var sBookShop = frmCust.MainOutlet1[OptMainOutlet].value;
		if (sBookShop == "Other" && frmCust.other.value == "")
		{
		alert("Please tell us your main outlet as a bookseller.");
		frmCust.other.focus();
		return false;
		}
	}
	//else
	if (IsBookSeller == "false")
	{
		for (i=0;i<frmCust.MainOutlet1.length;i++)
		{
			if(frmCust.MainOutlet1[i].checked)
			{
			OptMainOutlet = i
			}	
		}
		if (OptMainOutlet == -1)
		{
		alert("Please tell us your main outlet as a bookseller.");
		styleObj=document.getElementById('MainOutletCell').style;
 		styleObj.backgroundColor="yellow";
 		frmCust.txtMainOutlet.focus();
		return false;
		}
		var sBookShop = frmCust.MainOutlet1[OptMainOutlet].value;
		if (sBookShop == "None")
		{
		alert("If you do not sell online and do not have a main outlet you are not eligible to register with Sandpiper.");
		styleObj=document.getElementById('MainOutletCell').style;
 		styleObj.backgroundColor="yellow";
 		frmCust.txtMainOutlet.focus();
		return false;
		}		
		if (sBookShop == "Other" && frmCust.other.value == "")
		{
		alert("Please tell us your main outlet as a bookseller.");
		frmCust.other.focus();
		return false;
		}
	}
	
//Login Details
	if(frmCust.EMail.value == "")
	//Not entered email address
	{
		alert("Please enter your e-mail address.");
		frmCust.EMail.focus();
		return false;
	}
	var r, re, sp, spc;
	var s = frmCust.EMail.value;
	
	if(s.length < 6)
	{
		alert("Please enter a valid e-mail address.");
		frmCust.EMail.focus();
		return false;
	}
	re = /@/i;
	r = s.search(re);
	if (r<0)
	{
		//No @ character present
		alert("Please enter a valid e-mail address which must contain an '@' sign.");
		frmCust.EMail.focus();
		return false;
	}
	sp = new String(s);
	spc = sp.indexOf(" ");
	if (spc > 0)
	{
		//A\ space is present
		alert("Please enter a valid e-mail address which must not contains blank spaces.");
		frmCust.EMail.focus();
		return false;
	}
	p = frmCust.Password.value
	if(p.length<4)
	{
		alert("Your password must be a minimum of 4 characters long.");
		frmCust.Password.focus();
		return false;
	}
	if(frmCust.Password.value != frmCust.Confirm.value)
	{
		alert("Your confirmation password does not match your password.");
		frmCust.Confirm.focus();
		return false;
	}
	if(frmCust.strVerify.value == "")
	{
		alert("Please answer the anti-spam question.");
		frmCust.strVerify.focus();
		return false;
	}
	if (frmCust.Terms.checked == true)
	{
	sendOpts();
	return true;
	}
	else
	{
	alert("You must agree to the Sandpiper Terms & Conditions.");
	styleObj=document.getElementById('TCs').style;
 	styleObj.backgroundColor="yellow";
 	frmCust.Terms.focus();
	return false;
	}	
}


function sendOpts() 
{
  var dropline = "<br>";
var OptBookSeller  = -1;

	for (i=0;i<document.frmCust.IsBookSeller.length;i++)
	{
		if(document.frmCust.IsBookSeller[i].checked)
		{
		OptBookSeller = i
		}	
	}
	
	var SellMainTrade = '<b>Main Online Outlet:</b> ';
	var SellMainOutlet = '<b>Non-Online Outlet(s):</b> ';
	var SellOpts = '<b>Other Online Outlets:</b>' + dropline;
	var BizType = document.frmCust.IsBookSeller[OptBookSeller].value;
	var OptMainOutlet  = -1;	
	
		SellOpts = SellOpts + 'Own website: ' + document.frmCust.ownsite.value.toUpperCase() + dropline;
		SellOpts = SellOpts + 'Abebooks.com: ' + document.frmCust.abebooks.value.toUpperCase() + dropline;
		SellOpts = SellOpts + 'Amazon.co.uk: ' + document.frmCust.amazon.value.toUpperCase() + dropline;
		SellOpts = SellOpts + 'Ebay.co.uk: ' + document.frmCust.ebay.value.toUpperCase() + dropline;
		SellOpts = SellOpts + 'Other online retailer: ' + document.frmCust.oor.value.toUpperCase() + dropline;
		SellOpts = SellOpts + 'Other online auction: ' + document.frmCust.ooa.value.toUpperCase() + dropline;



		for (i=0;i<document.frmCust.MainOutlet1.length;i++)
		{
			if(document.frmCust.MainOutlet1[i].checked)
			{
			OptMainOutlet = i
			}	
		}		
		switch (OptMainOutlet)
		{
		case 0:
		SellMainOutlet = SellMainOutlet + dropline + 'Single Retail';
		break;
		case 1:
		SellMainOutlet = SellMainOutlet + dropline + 'Multiple Retail';
		break;
		case 2:
		SellMainOutlet = SellMainOutlet + dropline + 'Wholesale';
		break;
		case 3:
		SellMainOutlet = SellMainOutlet + dropline + 'Mail Order';
		break;
		case 4:
		SellMainOutlet = SellMainOutlet + dropline + 'Direct sales';
		break;
		case 5:
		SellMainOutlet = SellMainOutlet + dropline + 'Other: ' + frmCust.other.value;
		break;
		case 6:
		SellMainOutlet = SellMainOutlet + dropline + 'None: online only ';
		break;
		}

//This is an online bookseller; capture Bookeller online outlet info	
	if(BizType == "true")
	{
	var OptMainTrade  = -1;
	
	
		for (i=0;i<document.frmCust.MainOutlet.length;i++)
		{
			if(document.frmCust.MainOutlet[i].checked)
			{
			OptMainTrade = i
			}	
		}
		switch (OptMainTrade)
		{
		case 0:
		SellMainTrade = SellMainTrade + dropline + 'Own website';
		break;
		case 1:
		SellMainTrade = SellMainTrade + dropline + 'Abebooks.com';
		break;
		case 2:
		SellMainTrade = SellMainTrade + dropline + 'Amazon.co.uk';
		break;
		case 3:
		SellMainTrade = SellMainTrade + dropline + 'Ebay.co.uk';
		break;
		case 4:
		SellMainTrade = SellMainTrade + dropline + 'Other Online Retailer';
		break;
		case 5:
		SellMainTrade = SellMainTrade + dropline + 'Other Online Auction';
		break;
		}

		document.frmCust.OptsDetails.value = (
	  dropline + dropline
	  + '----- Online Bookseller Info---START------ ' + dropline + dropline
	  + SellMainTrade + dropline + dropline  
	  + SellOpts + dropline
	  + SellMainOutlet + dropline + dropline
	  + '----- Online Bookseller Info---END------ '
		);
	}
//This is NOT an online bookseller; capture relevant info		
	if(BizType == "false")
	{
	document.frmCust.OptsDetails.value = (
  		dropline + dropline
	  + dropline  + dropline
	  + '----- Non-Online Bookseller Outlet Info---START----- ' + dropline
	  + SellMainOutlet + dropline
	  + '----- Non-Online Bookseller Info---END------ '
	);
	}

}