// Create new main array. 
var reseller_country_list = new Array();
reseller_country_list = [
//Format of Array is -		Country name, Country Value/Code, Disti1 name, Disti1 email, Disti2 name, Disti2 email, Disti3 name, Disti3 email .... 
['Austria','Austria','Azlan GmbH','SR_AT_AZLAN@3com.com','INGRAM Micro','SR_AT_INGRAM@3com.com','Tech Data Europe GmbH','SR_AT_TECHDATA@3com.com','Westcon Group','SR_AT_WESTCON@3com.com'],
['Bahrain','Bahrain','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['Belgium','Belgium','Azlan Belgium','SR_BE_AZLAN@3com.com','Ingram Micro NV','SR_BE_INGRAM@3com.com','TechData NV/SA','SR_BE_TECHDATA@3com.com','Westcon Group','SR_BE_WESTCON@3com.com'],
['Bulgaria','Bulgaria','Solytron','SR_BG_SOLYTRON@3com.com','CHS Bulgaria','SR_BG_CHS@3com.com'],
['Croatia','Croatia','Comtel Corp','SR_HR_COMTEL@3com.com','Senso Mikro D.O.O','SR_HR_SENSO@3com.com','Megatrend','SR_HR_MEGATREND@3com.com'],
['Cyprus','Cyprus','Tech-U Ltd','SR_CY_TECHU@3com.com'],
['Czech Republic','Czech Republic','ED System','SR_CZ_EDSYSTEM@3com.com','RRC','SR_CZ_RRC@3com.com','Techdata CZ(formally Expert & Partner C2000)','SR_CZ_TECHDATA@3com.com'],
['Denmark','Denmark','Komplett Denmark','SR_DK_KOMPLETT@3com.com'],
['Estonia','Estonia','GNT Finland','SR_FI_GNT@3com.com'],
['Egypt','Egypt','Aptec Egypt','SR_EG_APTEC@3com.com','Mantrac','SR_EG_MANTRAC@3com.com','Raya Distribution','SR_EG_RAYA@3com.com'],
['Finland','Finland','GNT Finland Ltd','SR_FI_GNT@3com.com','Ingram Micro Finland','SR_FI_INGRAM@3com.com','AZLAN Finland','SR_FI_AZLAN@3com.com'],
['France','France','Azlan SA','SR_FR_AZLAN@3com.com','IPVista SAS','SR_FR_IPVISTA@3com.com','Tech Data France','SR_FR_TECHDATA@3com.com','Ingram Micro SARL','SR_FR_INGRAM@3com.com','Westcon Group','SR_FR_WESTCON@3com.com','ETC Metrologie','SR_FR_ETC@3com.com'],
['Germany','Germany','Algol Deutschland GmbH','SR_DE_ALGOLDEUTSCH@3com.com','Azlan GmbH','SR_DE_AZLAN@3com.com','Ingram Micro Distribution GmbH','SR_DE_INGRAM@3com.com','Tech Data Germany Holding GmbH','SR_DE_TECHDATA@3com.com','Westcon Group','SR_DE_WESTCON@3com.com'],
['Greece','Greece','Altec SA','SR_GR_ALTEC@3com.com','OKTABIT','SR_GR_OKTABIT@3com.com','Pouliadis','SR_GR_POULIADIS@3com.com','INFOQUEST','SR_GR_INFOQ@3com.com'],
['Hungary','Hungary','HRP Hungary Kft','SR_HU_HRP@3com.com','Ingram Micro - Hungary (Walton Networking Kft)','SR_HU_INGRAM@3com.com','RRC Hungary','SR_HU_RRC@3com.com'],
['Iceland','Iceland','EJS','SR_IS_EJS@3com.com'],
['Ireland','Ireland','Sharptext','SR_IE_SHARPTEXT@3com.com'],
['Israel','Israel','C Data','SR_IL_CDATA@3com.com'],
['Italy','Italy','Esprinet S.p.a.','SR_IT_ESPRINET@3com.com','Ingram Micro S.p.A.','SR_IT_INGRAM@3com.com','Computergross Italia SPA','SR_IT_COMPUT@3com.com'],
['Jordan','Jordan','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['Kuwait','Kuwait','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['Latvia','Latvia','GNT Finland','SR_FI_GNT@3com.com'],
['Lebanon','Lebanon','APTEC Lebanon','SR_LB_APTEC@3com.com'],
['Libya','Libya','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com'],
['Lithuania','Lithuania','GNT Finland','SR_FI_GNT@3com.com'],
['Netherlands','Netherlands','Azlan Network Distribution B.V.','SR_NL_AZLAN@3com.com','Ingram Micro B.V.','SR_NL_INGRAM@3com.com','TechData','SR_NL_TECHDATA@3com.com','Westcon Group','SR_NL_WESTCON@3com.com'],
['North Africa','North Africa','Algerian Business Multimedia (ABM) - Algeria','SR_DZ_ALGERIANBUS','Network City - Morocco','SR_MA_NETWORK@3com.com'],
['Norway','Norway','Komplett Norway','SR_NO_KOMPLETT@3com.com'],
['Oman','Oman','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['Poland','Poland','RRC Poland','SR_PL_RRC@3com.com','Tech Data Polska Sp. Zo.o.','SR_PL_TECHDATA@3com.com','Veracomp','SR_PL_VERACOMP@3com.com','ABC Data Sp. Zo.o','SR_PL_ABCDATA@3com.com'],
['Portugal','Portugal','Ingram Micro Portugal','SR_PT_INGRAM@3com.com','Investronica, SA.','SR_PT_INVESTRON@3com.com','Techdata (Computer 2000 Portuguesa, LDA.)','SR_PT_TECHDATA@3com.com'],
['Qatar','Qatar','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['Romania','Romania','SCOP Computers','SR_RO_SCOP@3com.com'],
['Russia','Russia','OCS','SR_RU_OCS@3com.com','RRC Telecommunications','SR_RU_RRC@3com.com','Soft-tronik Moscow','SR_RU_SOFTTRONIK@3com.com','LANIT','SR_RU_LANIT@3com.com','Verysell S.A','SR_RU_VERYSELL@3com.com','Muvicom','SR_RU_MUVICOM@3com.com','Merlion','SR_RU_MERLION@3com.com'],
['Saudi Arabia','Saudi Arabia','Aptec (Arabian Applied Technology)','SR_SA_APTEC@3com.com'],
['Serbia and Montenegro','Serbia and Montenegro','SR BG SOLYTRON','SR_BG_SOLYTRON@3com.com','NETIKS D.O.O','SR_RS_NETIKS@3com.com'],
['Slovakia','Slovakia','BGS Distribution','SR_SK_BGS@3com.com'],
['Slovenia','Slovenia','Acord 92 D.o.o.','SR_SI_ACORD@3com.com','CHS D.O.O.','SR_SI_CHS@3com.com'],
['South Africa','South Africa','Comztek','SR_ZA_COMZTEK@3com.com','Duxbury Networking','SR_ZA_DUXBURY@3com.com','Westcon','SR_ZA_WESTCON@3com.com'],
['Spain','Spain','Aryan','SR_ES_ARYAN@3com.com','Ingram Micro','SR_ES_INGRAM@3com.com','Investronica, S.A.','SR_ES_INVESTRON@3com.com','Techdata Spain','SR_ES_TECHDATA@3com.com','DIASA','SR_ES_DIASA@3com.com'],
['Sweden','Sweden','Ingram Micro AB','SR_SE_INGRAM@3com.com','Tech Data Europe GmbH','SR_SE_TECHDATA@3com.com','Westcon Group','SR_SE_WESTCON@3com.com','Komplett Sweden','SR_SE_KOMPLETT@3com.com'],
['Switzerland','Switzerland','ALSO Schweiz AG','SR_CH_ALSOABC@3com.com','Azlan Switzerland','SR_CH_AZLAN@3com.com','Ingram Micro AG','SR_CH_INGRAM@3com.com','Techdata (Switzerland)','SR_CH_TECHDATA@3com.com'],
['Turkey','Turkey','Armada Bilg. A.S.','SR_TR_ARMADA@3com.com','Netex.','SR_TR_NETEX@3com.com'],
['United Arab Emirates','United Arab Emirates','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Peripherals Gulf Ltd.','SR_AE_PERIPH@3com.com','Techdata','SR_AE_TECHDATA@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['United Kingdom','United Kingdom','Azlan Group PLC','SR_GB_AZLAN@3com.com','Computer2000/Techdata UK','SR_GB_TECHDATA@3com.com','Ingram Micro (UK) Ltd','SR_GB_INGRAM@3com.com','Westcon','SR_GB_WESTCON@3com.com','Rocom Group Ltd','SR_GB_ROCOM@3com.com','Bell Micro','SR_GB_BELLMICRO@3com.com'],
['Yemen','Yemen','Aptec Gulf LLC','SR_AE_APTEC@3com.com','Online Distribution','SR_AE_ONLINE@3com.com','Redington Gulf FZE','SR_AE_REDINGTONGULF@3com.com'],
['3Com Demonstration','3Com Demonstration','3Com Demonstration','SR_GB_3COM@3com.com']
]

//Writes the options for the country list
function disti_country_options()
{		
	var selected;
	for (j=0; j < reseller_country_list.length; j++)
	{	
		if (arguments[0])
		{
			if (arguments[0] == reseller_country_list[j][0]){selected = 'SELECTED';} //if country name passed equals current item 
		}
		else
		{
			selected = '';
		}
			document.write('<option '+ selected +' value="'+ reseller_country_list[j][1] +'">' + reseller_country_list[j][0] +'</option>')
		
			selected = ''; //reset selected

	}		
	
}

//Writes the options for the country list
function disti_country_options_sso()
{		
	var selected;
	for (j=0; j < reseller_country_list.length; j++)
	{	
		if (arguments[0])
		{
			if (arguments[0] == reseller_country_list[j][0]){selected = 'SELECTED';} //if country name passed equals current item 
		}
		else
		{
			selected = '';
		}
		document.write('<option '+ selected +' value="'+ reseller_country_list[j][1] +'">' + reseller_country_list[j][0] +'</option>')
	}		
	
}


//Writes the dists name/email list for selected parsed country
function disti_options(country)
{
	var initial_length = document.form1.submit_disti.options.length;
	//delete old options if any BUT not the first option which is "please select"			
	//alert("options array length = " + document.form1.submit_disti.options.length)  	
	 for (options_count=1; options_count <= initial_length; options_count++)
	 {
	 	document.form1.submit_disti.options[1] = null;	//delete row 1 because all other rows move up to take deleted rows' space
	 }

	 if(document.form1.submit_country.value !="")
	 {		 
		//find country
		for (j=0; j < reseller_country_list.length; j++)	//scroll through all records
		{	
			if (reseller_country_list[j][0]== country)	//check first item in record for a match
			{	 	
			//debug line
			//alert('match')
				//for the matched record
				var count=0;	//counter for adding the options	
				for (k=2; k < reseller_country_list[j].length-1; k = k+2) //scroll through the current record, jumping from disti name to disti name, until the end of record
				{	
					count++;	//start at value 1 because the first option is "please select"
					//debug	lines
					//document.write("<br>name= "+reseller_country_list[j][k])	//Get disti names
					//document.write("<br>mail= "+reseller_country_list[j][k+1])	//Get disti mails						
					//														new Option('display text','value')																	
					eval("document.form1.submit_disti.options[count]=" + "new Option('"+ reseller_country_list[j][k] +"','"+ reseller_country_list[j][k+1] +"')");	//add each option				
				}	
			}			
		}
	}
}


//Object dynamicGroup - represensts a group of radio buttons that can be turned on or off
//Accepts radio buttons e.g. document.form1.radioName[0],document.form1.radioName[1]
function dynamicGroup()
{	
	this.radios = arguments;		//Set array of radio buttons
	this.on=dynamicGroup_On;	//Set Method
	this.off=dynamicGroup_Off;
}

//Method of dynamicGroup - Turns radios on
function dynamicGroup_On()
{	for (count=0; count < this.radios.length; count++)	{this.radios[count].disabled = false}	}

//Method of dynamicGroup - Turns radios off
function dynamicGroup_Off()
{	for (count=0; count < this.radios.length;  count++)	{this.radios[count].disabled=true; this.radios[count].checked = false;}	}





//ENABLES or DISABLES the dynamic textbox and star - Auto Checks which form type
function disableTextBox()
{
	if (document.form1.order_type.value=='maintenance')
	{		
		//Set up dynamic textbox and star
		if (document.form1.s1_prod_renewservice[0].checked)		//if YES is checked 
		{	document.form1.s1_prod_contractnum.disabled = false;	//enable text box
		 	changeText_color('red','s1_prod_contractnum_star');			
		}	
		else
		{	document.form1.s1_prod_contractnum.value="";		//any other case, disable the text box.
			document.form1.s1_prod_contractnum.disabled = true;
			changeText_color('white','s1_prod_contractnum_star');
		}
//		if (document.form1.s1_prod_renewservice){alert();enable_required_object(document.form1.s1_prod_renewservice[0].checked,'true','s1_prod_contractnum_star','red','white',document.form1.s1_prod_contractnum);}		
	}
}


function GuardianExpress_on()			{guardian_service_all.on();	express_service_not_avail.off(); 	express_service_all.on();		express_service_24_7_NBD.off(); express_service_24_7_NBD2.off(); }
function express_service_all_on()		{guardian_service_all.off();express_service_not_avail.off();	express_service_all.on(); 		express_service_24_7_NBD.off(); express_service_24_7_NBD2.off();}
function express_service_8_5_NBD_on() 	{guardian_service_all.off();express_service_not_avail.off();	express_service_all.off();		express_service_24_7_NBD.off();	express_service_8_5_NBD.on(); express_service_24_7_NBD2.off();}
function express_service_24_8_5_NBD_on() 	{guardian_service_all.off();express_service_not_avail.off();	express_service_all.on();		express_service_24_7_NBD.off();	express_service_8_5_NBD.on(); express_service_24_7_NBD2.off();}
function express_service_24_7_NBD_on()	{guardian_service_all.off();express_service_not_avail.off();	express_service_all.off(); 		express_service_24_7_NBD.on(); express_service_24_7_NBD2.off();}


//ENABLES or DISABLES the Service Orders Radio Buttons - Auto Checks that it is being called on the maintenance form 
function disableFields()
{	
	//Section For Maintenance Orders Form
	if (document.form1.order_type.value=='maintenance')
	{			
	//Only Show the correct services radio buttons
	//This depends on the type of order and the country selected
		
		//disable all fields
//		guardian_service_all.off();		
//		express_service_not_avail.off(); //two allways off radios 
//		express_service_all.off(); 
//		express_service_24_7_NBD.off();	


		
		//turn on the required fields
		switch(document.form1.s1_equip_country.value)
		{
			//Demo - all on
			case '3Com Demonstration': 				guardian_service_all.on();express_service_not_avail.off(); express_service_all.on(); express_service_24_7_NBD.on(); break;
			//Guardian and Express
			case 'Belgium': 						GuardianExpress_on(); break;
			case 'Ireland': 						GuardianExpress_on(); break;
			case 'France': 							GuardianExpress_on(); break;
			case 'Germany': 						GuardianExpress_on(); break;
			case 'Netherlands': 					GuardianExpress_on(); break;
			case 'United Kingdom': 					GuardianExpress_on(); break;
			//Express 8*5*NBD - SHIP only
			case 'Austria': 						express_service_24_8_5_NBD_on(); break;
			case 'Czech Republic': 					express_service_24_8_5_NBD_on(); break;
			case 'Denmark': 						express_service_24_8_5_NBD_on(); break;
			case 'Egypt': 							express_service_24_8_5_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Finland': 						express_service_8_5_NBD_on(); break;
			case 'Greece': 							express_service_24_8_5_NBD_on(); break;
			case 'Hungary': 						express_service_8_5_NBD_on(); break;
			case 'Italy': 							express_service_24_8_5_NBD_on(); break;
			case 'Norway': 							express_service_24_8_5_NBD_on(); break;
			case 'Poland': 							express_service_24_8_5_NBD_on(); break;
			//case 'Portugal': 						guardian_service_all.on();express_service_24_8_5_NBD_on(); break;
			case 'Portugal':						GuardianExpress_on(); break;
			case 'South Africa': 					express_service_24_8_5_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Spain':	 						express_service_24_8_5_NBD_on(); guardian_service_all.on();  break;
			//case 'Spain':							GuardianExpress_on(); break;
			case 'Sweden': 							express_service_24_8_5_NBD_on(); break;
			case 'Switzerland':						express_service_24_8_5_NBD_on(); break;
			case 'Turkey': 							express_service_24_8_5_NBD_on(); break;
			case 'United Arab Emirates': 			express_service_24_8_5_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Israel':				 			express_service_24_8_5_NBD_on(); break;
			//Middle East - Express 24*7*NBD - SHIP only
			case 'Bulgaria': 						express_service_24_7_NBD_on(); break;
			case 'Croatia': 						express_service_24_7_NBD_on(); break;
			case 'Cyprus': 							express_service_24_7_NBD_on(); break;
			case 'Estonia': 						express_service_24_7_NBD_on(); break;
			case 'Iceland': 						express_service_24_7_NBD_on(); break;
			case 'Latvia': 							express_service_24_7_NBD_on(); break;
			case 'Lebanon': 						express_service_24_7_NBD_on(); break;
			case 'Lithuania': 						express_service_24_7_NBD_on(); break;
			case 'North Africa': 					express_service_24_7_NBD_on(); break;
			case 'Romania': 						express_service_24_7_NBD_on(); break;
			case 'Russia': 							express_service_24_7_NBD_on(); break;
			case 'Saudi Arabia': 					express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Serbia & Montenegro': 			express_service_24_7_NBD_on(); break;
			case 'Slovakia': 						express_service_24_7_NBD_on(); break;
			case 'Slovenia': 						express_service_24_7_NBD_on(); break;
			case 'Oman': 							express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Qatar': 							express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Kuwait': 							express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Jordan': 							express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			case 'Yemen': 							express_service_24_7_NBD_on(); express_service_24_7_NBD2.on();  break;
			case 'Bahrain': 						express_service_24_7_NBD_on(); express_service_24_7_NBD2.on(); break;
			//Express Only
			default: 									express_service_all_on();  break;	//All other Countries
	    }
	}
	
	//Section For Professional Orders Form
	//if (document.form1.order_type.value=='Professional')
	//{			
	//}
	
}
//END disableFields()


//adds the distis to the distis select box according to the country selected
//Called from objects in the form and when document loads
function fill_distis()
{
	disti_options(document.form1.submit_country.value);
	//disti_options() is in the translation doc
}


//Initilization of form.
//Create Public dynamic radio buttons groups
var guardian_service_all
var express_service_all
var express_service_not_avail
var express_service_24_7_NBD 
var express_service_8_5_NBD
var switch_professional_service


//Runs "onLoad" when user Comes to the page or when they Pess Reload or Back from the fail/success page
function formSetup()
{
		
		//Set up Pointers to dynamic radio button groups
		//Mantainence Sets
		guardian_service_all		= new dynamicGroup(document.form1.guardian_2474,document.form1.guardian_854,document.form1.guardian_85NBD);
		express_service_not_avail	= new dynamicGroup(document.form1.express_852,document.form1.express_2472);
		express_service_all			= new dynamicGroup(document.form1.express_2474,document.form1.express_854,document.form1.express_85NBD);
		express_service_8_5_NBD		= new dynamicGroup(document.form1.express_85NBD);
		express_service_24_7_NBD 	= new dynamicGroup(document.form1.express_247NBDship);
		express_service_24_7_NBD2	= new dynamicGroup(document.form1.express_247NBD);

		//Professional Sets
		switch_professional_service = new dynamicGroup(document.form1.prof_serv_radio1,document.form1.prof_serv_radio2);
		
		//Disable other dynamic fields.

		 //if(	> -1)		//!document.form1.s1_equip_country.value) 
		 //{
		disableFields();		 
		// }
		 		 
		 disableTextBox();
		 
	 	//Activate / fill dynamic fields
	 	fill_distis(document.form1.submit_country.value);
		checkCookies();
}




//Check all rows of prod table to see that each row has all nessasary data
//Called on submit
function checkProds()
{	
	maxNumberOfProds = 15;
	//Check that the product table exists
	if(document.form1.s1_prod_renewservice)
	{
		var	found_data;
		//Check that the user has entered the correct amount of product data	
		//Scroll through the products table
		 for (product_row_number=1; product_row_number <= maxNumberOfProds;  product_row_number++)	//while the product_row_number is smaller than or equal to maxNumberOfProds DO
		 {
		 		var number = product_row_number;
				//if any data exists for current product row 
				//Then check that all data for that row is present				
								
				//Create names of fields
				var prod 	= 's1_hardware_prod' + number;
				var serial 	= 's1_hardware_serial' + number;
				var desc 	= 'desc' + number;
				var csnum 	= 's1_service_part_number_' + number;
				
				//if any data entered for current line then check that the correct fields are present
				if ((eval(document.form1[prod]).value) || (eval(document.form1[serial]).value) || (eval(document.form1[desc]).value) || (eval(document.form1[csnum]).value))
				{
					//Must have "3CS Service Part Number" and ("3C Product Part Number" or "Serial Number"")
					if ((eval(document.form1[csnum]).value) && (eval(document.form1[prod]).value && eval(document.form1[serial]).value))
					{ 	//Data Present No Action needed
						found_data = true;
					}
					else{
						//Data Missing - Give Error
						alert(field["hardware_txt3"]);
						found_data = false;
						return false; //end
						}
				}				
		 }
		 
		//Table is Error free. But was there any data in the table?
		if (found_data==true)
		{
			//Give all clear response to calling function		
			return true;
		}
		else
		{
			//All Data Missing - Give Error
			alert(field["hardware_error"]);
			return false; //end		
		}
	}	
	else
	{	//No product table exists
		//Give all clear response to calling function
		return true;
	}	
}



//Final Checks on the form
function formFinalCheck(maxNumberOfProds)
{
	updateCookie();
	
	//1) Set company abriviation for forms unique reference - final result must be 6 chars plus a dash
	//use Endusers company name
	
	var ref = document.form1.s1_equip_company.value.substring(0,6);	
	//alert(document.form1.resell_company_abv.value)
	//alert(unescape(document.form1.resell_company_abv.value))
	//return;
	
	//Get length of abv
	count = ref.length; 

	//Add X's if needed
	if (ref.length < 6)
	{
		 for (count; count < 6;  count++)	//If needed Add the letter X to the abv to make it 6 letters long
		 {		 	
			ref = ref + 'X'
		 }
	}
	//add a dash
	ref = ref + "-"
	//alert(document.form1.resell_company_abv.value)	
		
//2) Get Dateand set reference
	//Get current Date
	var dateGetter = new Date();
	var month = dateGetter.getUTCMonth() + 1;	//Add 1 because date is 0 for jan,1 for feb etc.
	var day = dateGetter.getUTCDate();
	
	//Ensure the length of the string
	//change the numbers into strings
	month += '';
	day += '';
	//append day or month to a zero if not 2 chars long .i.e makes feb = 02 not 2
	if (month.length==1)	
		month = '0'+month;
	if (day.length==1)	 	
		day = '0'+day;
	
	rannum = Math.random() * 999;
	rannum = Math.round(rannum);
		
	document.form1.resell_company_abv.value = ref + month +''+ day +'-'+ rannum

	//alert(document.form1.resell_company_abv.value);

	
	
	
//3) Check that the user has entered some / the correct amount of product data 
		if (checkProds(maxNumberOfProds))
		{
			document.form1.submit()
		}
	
}


//------------------------------------------------------------------------------------

//Bernhard Speyer 08/10/2003

var cookie_resell = new Array(); // setup an array to hold the output of the cookie value data
var resell_cookie = "RESELLER"
var debug = request["debug"] ? request["debug"] : false; // use debug 5 to get full info


function updateCookie()
{
	var cookieValue = "";
	cookieValue += "resell_company==" 	+ document.form1.resell_company.value + "&&";
	cookieValue += "resell_contact==" 	+ document.form1.resell_contact.value + "&&";	
	cookieValue += "resell_address==" 	+ document.form1.resell_address.value + "&&";	
	cookieValue += "resell_city==" 		+ document.form1.resell_city.value + "&&";
	cookieValue += "resell_zipcode==" 	+ document.form1.resell_zipcode.value + "&&";
	cookieValue += "resell_country==" 	+ document.form1.resell_country.value + "&&";
	cookieValue += "resell_telphone==" 	+ document.form1.resell_telphone.value + "&&";
	cookieValue += "resell_fax==" 		+ document.form1.resell_fax.value + "&&";
	cookieValue += "resell_email==" 	+ document.form1.resell_email.value + "&&";
	cookieValue += "resell_vat==" 		+ document.form1.resell_vat.value + "&&";
	cookieValue += "submit_disti==" 	+ document.form1.submit_disti.value + "&&";
	cookieValue += "mailto_email==" 	+ document.form1.mailto_email.value + "&&";


	
	setCookie(resell_cookie, cookieValue, "/", ""); 
}

function checkCookies()
{
	if(debug)alert("checking for cookie");

	if (getCookieValue(resell_cookie)) 
	{	// trInfoField(argInfo1,format1,align1,argInfo2,format2,align2) 
		// var formTxt = trInfoField('If you are not this person please click here:','normal','right','<input type="reset" value="delete me" onclick="deleteCookie(\''+ resell_cookie +'\')">');	
		// document.write(formTxt);
		fill_formfields(); // then fill fields with values
	}
	else
	{
		if(debug) alert("we do not have a cookie, please fill in your personal data now");
	}
}

/*
function remember_me()
{
	if(!getCookieValue(resell_cookie))
	{
		document.write(trInfoField('to remember or update your data please click here:','normal','right','<input type="button" value="save data" onClick="updateCookie();">','left','normal'));
	}
}
*/

function fill_formfields()
{
	document.form1.resell_company.value 	= cookie_resell["resell_company"];
	document.form1.resell_contact.value 	= cookie_resell["resell_contact"];
	document.form1.resell_address.value 	= cookie_resell["resell_address"];
	document.form1.resell_city.value 		= cookie_resell["resell_city"];
	document.form1.resell_zipcode.value		= cookie_resell["resell_zipcode"];
	document.form1.resell_country.value 	= cookie_resell["resell_country"];
	document.form1.resell_telphone.value 	= cookie_resell["resell_telphone"];
	document.form1.resell_fax.value 		= cookie_resell["resell_fax"];
	document.form1.resell_email.value 		= cookie_resell["resell_email"];
	document.form1.resell_vat.value 		= cookie_resell["resell_vat"];
	document.form1.submit_disti.value 		= cookie_resell["submit_disti"];
	document.form1.mailto_email.value 		= cookie_resell["mailto_email"];
}

function deleteCookie(cookieName)
{
	var cookieExpires = new Date("January 1, 2000");
	setCookie(cookieName,"","",cookieExpires);
}

function setCookie(cookieName, cookieValue, cookiePath, cookieExpires)
{
	cookieValue = escape(cookieValue);

	if (cookieExpires == "")
	{
	   var nowDate = new Date();
	   nowDate.setMonth(nowDate.getMonth() + 1);
	   cookieExpires = nowDate.toGMTString();
	}
  
	if (cookiePath != "")
	{
		cookiePath = ";Path=" + cookiePath;
	}
	 
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;

	if(debug > 2)alert("cookie is set: \n\n Cookie Name is: "+ cookieName + "\n Cookie Value is : " + unescape(cookieValue) + "\n Cookie Path is : " + cookiePath + "\n Cookie expiry date is : " + cookieExpires); 
 }


function getCookieValue(cookieName)
{
	if(debug > 3 ) alert("getCookieValue - checking cookie:  does a cookie called: " + cookieName + " exist?");
	var cookieValue = document.cookie;
	var cookieStartsAt = cookieValue.indexOf(" " + cookieName + "=");

	if (cookieStartsAt == -1)
	{
		cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	}

	if (cookieStartsAt == -1)
	{
		cookieValue = null;
		if(debug > 3)alert("no cookie called " + cookieName + " found - sorry!");
		return cookieValue;
	}
	
	else
	{
		if(debug > 3)alert("found a cookie called: " + cookieName + "");
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
				
		if (cookieEndsAt == -1)
		{
			cookieEndsAt = cookieValue.length;
		}
		
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));

		if(debug > 4)alert("So you want to enter the 'cookie crumble machine' ! - staring to crumble the cookie" );
		if(debug > 4)alert("crumbling the cookie with value of: " + unescape(cookieValue));
		/*
			the cooie value list should look something like this:
			contactdata=title::Mr&&fname::Bernhard&&lname::Speyer&&job::DeV&&...
		*/
					
		var value_pairs_array = cookieValue.split("&&");
		/* 
			this creates an array that contains all the value_pairs:  
			i.e. 
			fname::Bernhard
			lname::Speyer
			...
		*/
		
		var fieldname_fieldvalue = "";  // eg. fname::Bernhard
		
		for (var i=0 ; i < value_pairs_array.length; i++)
		{
			fieldname_fieldvalue = value_pairs_array[i];
			var separated_fieldname_fieldvalue_array = fieldname_fieldvalue.split("==");
			var fieldname  = separated_fieldname_fieldvalue_array[0];	
			var fieldvalue = separated_fieldname_fieldvalue_array[1];
			// create an associative array to hold the contact_data read out from the cookie
			cookie_resell[fieldname] = fieldvalue;
			if(debug > 4)alert("Looping through the cookie data: \n\n Fieldname with value: \n\n " + fieldname + " = " + fieldvalue );
		}
		return true;
	}
}

