var updateimage = false;
var ranOnload=false; // Flag to determine if we've ran the starting stack already.

if (document.addEventListener) 
{

   document.addEventListener("DOMContentLoaded", function()
	 {
		 if (!ranOnload) 
		 {
			 ranOnload=true; 
			 
			 domreadydo();
		 }
	 }, false);
}
else if (document.all && !window.opera) 
{
//   This is the IE style which exploits a property of the (standards defined) defer attribute

  document.write("<scr" + "ipt id='DOMReady' defer=true " + "src=//:><\/scr" + "ipt>");  
  document.getElementById("DOMReady").onreadystatechange=function()
  {
			
     if (this.readyState=="complete" && (!ranOnload))
     {
			 
       ranOnload=true;
			
       domreadydo();
     }
   }
}

// for Safari
if (/WebKit/i.test(navigator.userAgent)) { // sniff
window.__load_timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
if (!ranOnload) {
domreadydo(); 
      ranOnload=true;
}
}
}, 10);
}
// function removeModule(tarobj)
// {
// 	
// 	var removethis = tarobj.parentNode;
// 	removethis.parentNode.removeChild(removethis);
// 	if(!($$('.chosenmodules .moduleslist .eachmodule').length>0))
// 	{
// 		
// 		var addaftertitle = document.createElement('span');
// 		addaftertitle.setAttribute('class', 'default_text');
// 		addaftertitle.innerHTML = "You currently have no modules chosen";
// 		new Insertion.After($$('.chosenmoduletitle')[0], addaftertitle);
// 	}
// 	
// }

var durations = 0.7;

	function capitalizeMe(incomingString)
	{
	    return incomingString.charAt(0).toUpperCase() + incomingString.substring(1).toLowerCase();
	}

function domreadydo()
{
	
    if (Prototype.Browser.IE) durations=0.01;
    var sliders = $$('.formcover .sliderreplacement');
	
    for (var s=0;s<sliders.length;s++)
		{
			if(sliders[s].id)
			{
				var sliderid = sliders[s].id;
				if(readCookie(sliderid))
				{
					var slidernumber = readCookie(sliderid);
					for(var i=0; i<sliders[s].options.length; ++i)
					{
						if(parseInt(sliders[s].options[i].value)==parseInt(slidernumber))
						{
							sliders[s].options[i].selected = true;
							break;
						}
					}
				}
			}
			
			convertSelectToSlider(sliders[s],s);
			
		}
		new Autocompleter.SelectBox('sector');	
	
// 		var defautpackage0 = document.createElement('div');
// 		defautpackage0.setAttribute('class', "defautpackage0");
// 		defautpackage0.setAttribute('id', "defautpackage");
// 		defautpackage0.style.zIndex = '6';
// 		new Insertion.Before($$('.formblock .rightside .img')[0], defautpackage0);
// 		recalculatePackage();

		if(!readCookie('currentPackage') || (readCookie('currentPackage').toLowerCase() == "mypackage"))
		{
// 			alert("default package !!");

			createCookie('currentPackage',"mypackage");
			choosePackage('mypackage');
			
		}
		else
		{
			
			updateimage = true;
			var packagename = readCookie('currentPackage').toLowerCase();
			
			choosePackage(packagename);
		}
// 		alert("what package now ?"+readCookie('currentPackage'));
		if ($('sector_combo')!=null) $('sector_combo').value = $('sector').options[0].value;

// 		recalculatePackage();
		var objitem = $$('.rightside .chosenmodules .moduleslist')[0];
		
// 		alert(objitem);
		if (objitem) 
		{
			objitem.innerHTML=listModules();
			
// 			alert("update modules ");
		}
		
// 		addnumbering();
		
		addevent();
		var imgstoload = ['/images/package0_default.png','/images/professional_big.png', '/images/solo_big.png', '/images/team_big.png', '/images/enterprise_big.png'];
		
		var imgsholder = document.createElement('div');
		new Insertion.Top($$('body')[0], imgsholder);
		
		imgsholder.style.display = "none";
		
		for(var i=0; i<imgstoload.length; ++i)
		{
			var imgobj = document.createElement('img');
			imgobj.src = imgstoload[i];
			new Insertion.Top(imgsholder, imgobj);
		}
		var url = "/productsmodules/package-result.html";
		
		
// 		targetasiframe(url);
	targetasdiv();
// 		new Autocompleter.SelectBox('cr_whenbuy');	
// 		new Autocompleter.SelectBox('cr_howhear');	
	updatesetting();
	var cornersdiv = $$(".makethiscorner");
		
		for(var i=0; i<cornersdiv.length; ++i)
		{
			
			
				new Effect.Corner(cornersdiv[i], "16px"); 
		}
		var divs = $$('#submitbtn div');
		for(var i=0; i<divs.length; ++i)
			divs[i].style.borderColor='#f3f3f3';
  if (location.hash=='#configuratorresult') configurator_result_show();

}
function updatesetting()
{
	
	var setting = readCookie('setting');
	if(setting)
		setting = setting.split(",");
	else
		setting = new Array();
	
	for(var i=0; i<setting.length; ++i)
	{
		
		if($(setting[i]))
		{
			
			$(setting[i]).setAttribute('checked', true);
// 			$(setting[i]).checked = true;
		}
	}
	
	
	
	
}
function targetasdiv()
{	
	//#configurator_result .rightside
	var configurator_result = document.createElement('div');
	configurator_result.setAttribute('id', 'configurator_result');
	new Insertion.Top($('contentbox'), configurator_result);
	
	var leftsidediv = document.createElement('div');
	leftsidediv.setAttribute('class', 'leftside');
	new Insertion.Bottom(configurator_result, leftsidediv);
	leftsidediv.innerHTML = '<div class="crimg"><img alt="ef3 package" /><div class="package_description"></div></div><div class="crmoduleslist"><div class="chosenmodules"><span class="chosenmoduletitle">Your Additional Modules</span><ul class=\'moduleslist\'></ul> </div></div>';
	
	var rightside = document.createElement('div');
	rightside.setAttribute('class', "rightside");
	new Insertion.Top(configurator_result, rightside);
	var cr_formcover = document.createElement('div');
	cr_formcover.setAttribute('class', 'cr_formcover');
	new Insertion.Top(rightside, cr_formcover);
	
	var package_description = document.createElement('div');
	package_description.setAttribute('class', 'cr_package_description');
	
		var crtitle = document.createElement('div');
		crtitle.setAttribute('class', 'crtitle');
		var crdescription = document.createElement('div');
		crdescription.setAttribute('class', 'crdescription');
		crdescription.setAttribute('id', 'crdescription_id');
		new Insertion.Bottom(package_description, crtitle);
		new Insertion.Bottom(package_description, crdescription);
	
// 	package_description.innerHTML = "<div class='title'></div><div class='description'></div>";
	new Insertion.Before(cr_formcover, package_description);
	var orderform = document.createElement('form');
	orderform.setAttribute("id", 'orderform');
	orderform.setAttribute("name", 'orderform');
	new Insertion.Top(cr_formcover, orderform);
// 	new Ajax.Request("/mod/generalfuncts.php?ajax=0&getform=1&formtype=Configurator", {method:'GET', onComplete:function(transport)
// 		{
// 			alert(transport.responseText);
// 			$('orderform').innerHTML=transport.responseText;
// 		}
// 	});

// 	orderform.innerHTML = 
// 	"
// 	<div class=\"rleft\">
// 	</div>
// 	<div class=\"rwhitebutton\" onClick=\"window.location='/products/build-your-own.html'\">Modify My Package</div>
// 	<div class=\"rright\">
// 	</div>
// 	<div class='dashedline'></div>
		
	var btncover = document.createElement("DIV");
	btncover.setAttribute('class', 'btnwhite');
	btncover.setAttribute('id', 'btnwhite_id');
// 	new Insertion.Bottom(orderform, btncover);
	orderform.appendChild(btncover);
	btncover.style.position="relative";
	btncover.style.height="30px";
	btncover.style.width="175px";
// 	btncover.style.border="1px dashed";
// 	position:relative;
// 	height:30px;
// 	width:175px;
	
	var rleft = document.createElement("DIV");
	rleft.setAttribute("class", 'rleft');
// 	new Insertion.Bottom(btncover, rleft);
btncover.appendChild(rleft);
rleft.style.position="absolute";
rleft.style.height="30px";
rleft.style.width="13px";
rleft.style.background="url('/images/resultbutton-left.jpg') no-repeat left top";
rleft.style.left="0px";
rleft.style.top="0px";


// height:30px;
// width:13px;
// 
// background:url('/images/resultbutton-left.jpg') no-repeat left top;
// left:0px;

	
	var rwhitebtn = document.createElement("DIV");
	rwhitebtn.setAttribute('onClick', "location.href='/products/build-your-own.html'");
	rwhitebtn.setAttribute('class', "rwhitebutton");
	if(Prototype.Browser.IE)
	{
		rwhitebtn.innerHTML = "<a onClick=\"location.href='/products/build-your-own.html'; return false;\" href=\"javascript:history.go(-1);\" style=\"text-decoration:none;font-size:90%\">Modify My Package</a>";	
	}
	else
		rwhitebtn.innerHTML = "<a href=\"javascript:history.go(-1);\" style=\"text-decoration:none;font-size:90%\">Modify My Package</a>";	
// 	new Insertion.Bottom(btncover, rwhitebtn);
btncover.appendChild(rwhitebtn);

rwhitebtn.style.position="absolute";
rwhitebtn.style.left="12px";
rwhitebtn.style.top="0px";
rwhitebtn.style.padding="5px 1px 0 2px";
rwhitebtn.style.background="url('/images/resultbutton-center.jpg') repeat-x left top";
rwhitebtn.style.color="#02b6d9";
rwhitebtn.style.fontWeight="bold";
rwhitebtn.style.textDecoration="none";
rwhitebtn.style.fontSize="1.1em";
rwhitebtn.style.cursor="pointer";
rwhitebtn.style.borderBottom="1px solid #e3e3e3";
rwhitebtn.style.width="148px";
rwhitebtn.style.height="21px";


// left:12px;
// height:25px;
// padding:5px 1px 0 2px;
// background:url('/images/resultbutton-center.jpg') repeat-x left top;
// color:#02b6d9;
// font-weight:bold;
// text-decoration:none;
// font-size:1.1em;
// cursor:pointer;
// height:21px;
// border-bottom:1px solid #e3e3e3;
// width:148px;
	
	var rright = document.createElement("DIV");
	rright.setAttribute("class", 'rright');
// 	new Insertion.Bottom(btncover, rright);
btncover.appendChild(rright);
rright.style.position="absolute";
rright.style.top="0px";
rright.style.right="0px";
rright.style.background="url('/images/resultbutton-right.jpg') no-repeat right top";
rright.style.width="14px";
rright.style.height="30px";


// right:0px;
// height:30px;
// width:14px;
// background:url('/images/resultbutton-right.jpg') no-repeat right top;
	
	var dashedline = document.createElement("DIV");
	dashedline.setAttribute("class", 'dashedline');
	new Insertion.Bottom(orderform, dashedline);
	dashedline.style.clear="both";
	dashedline.style.borderTop="2px dotted #D5D5D7";
	dashedline.style.margin="10px 0px 20px 0px";
	
	
// 	clear:both;
// 	border-top:2px dotted #D5D5D7;
// 	margin-top:10px;
// 	margin-bottom:20px;
// 	width:590px;
	
	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
		
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "First Name";
	f1label.setAttribute("for", 'cr_firstname');
	new Insertion.Bottom(f1, f1label);
	f1label.style.width="175px";
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'text');
	f1input.setAttribute("name", 'cr_firstname');
	new Insertion.Bottom(f1, f1input);
	f1input.style.width="260px";

	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "Last Name";
	f1label.setAttribute("for", 'cr_lastname');
	new Insertion.Bottom(f1, f1label);f1label.style.width="175px";
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'text');
	f1input.setAttribute("name", 'cr_lastname');
	new Insertion.Bottom(f1, f1input);
	f1input.style.width="260px";
	
	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "Email";
	f1label.setAttribute("for", 'cr_email');
	new Insertion.Bottom(f1, f1label);f1label.style.width="175px";
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'text');
	f1input.setAttribute("name", 'cr_email');
	new Insertion.Bottom(f1, f1input);
	f1input.style.width="260px";
	
	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "Business Name";
	f1label.setAttribute("for", 'cr_businessname');
	new Insertion.Bottom(f1, f1label);f1label.style.width="175px";
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'text');
	f1input.setAttribute("name", 'cr_businessname');
	new Insertion.Bottom(f1, f1input);
	f1input.style.width="260px";
	
	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "Business Phone";
	f1label.setAttribute("for", 'cr_businesstel');
	new Insertion.Bottom(f1, f1label);f1label.style.width="175px";
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'text');
	f1input.setAttribute("name", 'cr_businesstel');
	new Insertion.Bottom(f1, f1input);
	f1input.style.width="260px";
	




	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.position="relative";
	f1.style.height="40px";
	f1.style.width="555px";
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "Country";
	f1label.setAttribute("for", 'country');
	new Insertion.Bottom(f1, f1label);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	
	var slctf = document.createElement('SELECT');
	slctf.setAttribute("name", 'country');
	slctf.setAttribute("id", 'country');
	new Insertion.Bottom(f1, slctf);
	slctf.style.width="260px";
	
	
// <option value=\"Next six months\">Next six months</option><option value=\"Next year\">Next year</option><option value=\"Not sure\">Not sure</option>
	var optarr = Array("United Kingdom","United States","Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia and Herzegovina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo; Democratic Republic","Cook Islands","Costa Rica","Cote d'Ivoire","Croatia","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","East Timor","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guinea","Guinea-Bissau","Guyana","Haiti","Heard and McDonald Islands","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iraq","Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montserrat","Morocco","Mozambique","Namibia","Nauru","Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Palestinian Territory","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saint Kitts and Nevis","Saint Lucia","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia and Montenegro","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and The South Sandwich Islands","South Korea","Spain","Sri Lanka","St. Helena","St. Pierre and Miquelon","Suriname","Svalbard and Jan Mayen Islands","Swaziland","Sweden","Switzerland","Taiwan","Tajikistan","Tanzania","Thailand","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","United States Minor Outlying Islands","Uruguay","Uzbekistan","Vanuatu","Vatican","Venezuela","Viet Nam","Virgin Islands (British)","Virgin Islands (U.S.)","Wallis and Futuna Islands","Western Sahara","Yemen","Zambia","Zimbabwe");
	for(var i=0; i<optarr.length; ++i)
	{
		var opt = document.createElement("OPTION");
		opt.setAttribute('value', optarr[i]);
		opt.innerHTML = optarr[i];
// 		new Insertion.Bottom(slctf, opt);
	slctf.appendChild(opt);
	}






	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "How did you hear about us?";
	f1label.setAttribute("for", 'cr_howhear');
	f1label.setAttribute("class", 'specialwidth');
	
	f1label.style.display = "block";
	f1label.style.width="150px";
// 	f1label.style.border="1px solid red";
	
	new Insertion.Bottom(f1, f1label);
	
	
	var slctf = document.createElement('SELECT');
	slctf.setAttribute("id", 'cr_howhear');
	slctf.setAttribute("name", 'cr_howhear');
	if(Prototype.Browser.IE)
	{
	slctf.style.position="absolute";
	slctf.style.top="0px"
	
	slctf.style.right="120px"
	}
	new Insertion.Bottom(f1, slctf);
	slctf.style.width="260px";
	
	var arrss = Array();
	var oform = document.getElementById('orderform');
	
	var childs = oform.childNodes;
	
	for(var i=0; i<childs.length; ++i)
	{
		
		var item_ = childs.item(i);
		if(((childs.item(i)).getAttribute('class')).toLowerCase()=="crformcotrol")
		{
			arrss.push(childs[i]);
		}
	}
	for(var i=0; i<arrss.length; ++i)
	{
		arrss[i].style.position="relative";
		arrss[i].style.height="40px";
		arrss[i].style.width="555px";
// 		alert("here");
	}
	
// 	<option value=\"Print advertising\">Print advertising</option><option value=\"Word of mouth\">Word of mouth</option><option value=\"Internet advertising\">Internet advertising</option><option value=\"Search engine\">Search engine</option>
	var optarr = Array("Google","Other Search Engine","Capterra","Direct Marketing - Email","Direct Marketing - By Post","Exhibition","Recommendation","Press","Advertisement");
	for(var i=0; i<optarr.length; ++i)
	{
		var opt = document.createElement("OPTION");
		opt.setAttribute('value', optarr[i]);
		opt.innerHTML = optarr[i];
// 		new Insertion.Bottom(slctf, opt);
		slctf.appendChild(opt);
	}
	
	var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol');
	new Insertion.Bottom(orderform, f1);
	f1.style.position="relative";
	f1.style.height="40px";
	f1.style.width="555px";
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	var f1label = document.createElement('LABEL');
	f1label.innerHTML = "When are you planning to introduce a new system?";
	f1label.setAttribute("for", 'cr_whenbuy');
	new Insertion.Bottom(f1, f1label);
	f1.style.backgroundImage = "url(/images/mandatory.png)";
	if(Prototype.Browser.IE)
		f1.style.backgroundPosition = "165px 5px";
	else
		f1.style.backgroundPosition = "184px 5px";
	f1.style.backgroundRepeat = "no-repeat";
	
	
	var slctf = document.createElement('SELECT');
	slctf.setAttribute("name", 'cr_whenbuy');
	slctf.setAttribute("id", 'cr_whenbuy');
	new Insertion.Bottom(f1, slctf);
	slctf.style.width="260px";
	
	
// <option value=\"Next six months\">Next six months</option><option value=\"Next year\">Next year</option><option value=\"Not sure\">Not sure</option>
	var optarr = Array("Immediately","3 months or less","3 to 6 months","6 to 12 months","No plans at this time","Currently on hold","Unknown");
	for(var i=0; i<optarr.length; ++i)
	{
		var opt = document.createElement("OPTION");
		opt.setAttribute('value', optarr[i]);
		opt.innerHTML = optarr[i];
// 		new Insertion.Bottom(slctf, opt);
	slctf.appendChild(opt);
	}
	
// 	<div class='crformcotrol'><input type='checkbox' name='cr_newsletter' id='cr_newsletter'><label for='cr_businessname' id='newsletterlabel'>Join Newsletter</label></div>

var f1 = document.createElement('DIV');
	f1.setAttribute("class", 'crformcotrol optional');
	new Insertion.Bottom(orderform, f1);
	f1.style.position="relative";
	f1.style.height="40px";
	f1.style.width="555px";
// 	f1.style.border="1px dashed red";
	
	
	
	var f1input = document.createElement('input');
	f1input.setAttribute("type", 'checkbox');
	f1input.setAttribute("id", 'cr_checkbox');
	f1input.setAttribute("name", 'cr_newsletter');
	new Insertion.Bottom(f1, f1input);
	f1input.style.margin="0px";
	
	f1input.style.width="15px";
	f1input.style.height="15px";
// 	f1input.style.border="1px solid green";
	
	
	if(Prototype.Browser.IE)
	{
		f1input.style.margin="10px 0px 0px 174px";
	}
	else
	{
		f1input.style.top="10px";
		f1input.style.position="absolute";
		f1input.style.left="194px";
	}
	
	
	
		
	
	
	
	
	var f1label = document.createElement('LABEL');
	f1label.setAttribute("for", 'cr_newsletter');
	f1label.innerHTML = "Would you like to receive our newsletter?";
	new Insertion.Bottom(f1, f1label);
	f1label.style.width="175px";
	f1label.style.position="absolute"
	f1label.style.top="0px"
	f1label.style.left="0px"
// 	f1label.style.border="1px solid red";
	
	var dashedline = document.createElement("DIV");
	dashedline.setAttribute("class", 'dashedline');
	new Insertion.Bottom(orderform, dashedline);
	dashedline.style.clear="both";
	dashedline.style.borderTop="2px dotted #D5D5D7";
	dashedline.style.margin="10px 0px 20px 0px";
// 	<div class='bigbtn'><div class='crbtnleft'></div><a id='crsubmit' href='#' onClick='sendpackagecookie(); return false;'>Send me my personalised brochure and proposal</a><div class='crbtnright'></div><br style='clear:both;'></div>

var bigbtn = document.createElement("DIV");
	bigbtn.setAttribute('class', 'bigbtn');
	new Insertion.Bottom(orderform, bigbtn);
	bigbtn.style.width="246px";
	bigbtn.style.height="51px";
	bigbtn.style.position="relative";
	
	var btnleft = document.createElement('DIV');
	btnleft.setAttribute("class", 'crbtnleft');
	new Insertion.Bottom(bigbtn, btnleft);
// 	btnleft.style.float="left";
	btnleft.style.backgroundImage="url(/images/personalized_left.png)";
	btnleft.style.height="51px";
	btnleft.style.width="20px";
	btnleft.style.position="absolute";
	btnleft.style.top="0px";
	btnleft.style.left="0px";
	
// 	float:left;
// 	left:0px;
// 	background-image:url('/images/cr_btnleft.png');
	
	var bigbtna = document.createElement('div');
	bigbtna.setAttribute('id', 'crsubmit');
// 	bigbtna.setAttribute('href', "www.eventsforce.com");

if(Prototype.Browser.IE)
{
	bigbtna.attachEvent('onclick', function(){sendpackagecookie('Configurator');});
}
else
	bigbtna.addEventListener('click', function(){sendpackagecookie('Configurator');}, false); /*('onClick', "sendpackagecookie('Configurator')");   //configurator*/
// 	IE:             !!window.attachEvent && !isOpera,
//       Opera:          isOpera,
//       WebKit:         ua.indexOf('AppleWebKit/') > -1,
//       Gecko:          ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') === -1,
//       MobileSafari:   /Apple.*Mobile.*Safari/.test(ua)
	
	if(Prototype.Browser.IE)
		bigbtna.innerText="Send my personalized information pack";
	else
		bigbtna.textContent="Send my personalized information pack";
	new Insertion.Bottom(bigbtn, bigbtna);
// 	bigbtna.style.float="left";
	bigbtna.style.borderTop="1px solid #e5e5e5";
	bigbtna.style.cursor = "hand";
	bigbtna.style.borderBottom="1px solid #e3e3e3"
	bigbtna.style.height="39px"
	bigbtna.style.width = "206px";
	bigbtna.style.display="block"
	bigbtna.style.paddingTop="10px"
	bigbtna.style.fontSize="1em"
	bigbtna.style.color="#ffffff"
	bigbtna.style.fontWeight="bold"
	bigbtna.style.textAlign="center"
	bigbtna.style.backgroundImage="url(/images/personalized_background.png)";
	bigbtna.style.position="absolute";bigbtna.style.top="0px";bigbtna.style.left="20px";
	
// 	float:left;
//     border:none;
//     width:206px;
// 		border-top:1px solid #e5e5e5 !important;
// 		border-bottom:1px solid #e3e3e3 !important;
//     height:39px;
// 		display:block;
// 		padding-top:10px;
//     text-decoration:none;
//     color:#00b9d8;
//     font-size:1em;
//     font-weight:bold;
//     text-align:center;
//     background-image:url('/images/cr_btnbg.png');
	
	
	var btnright = document.createElement('DIV');
	btnright.setAttribute("class", 'crbtnright');
	new Insertion.Bottom(bigbtn, btnright);
	btnright.style.backgroundImage="url(/images/personalized_right_cr.png)";
	btnright.style.backgroundPosition="top right";
// 	btnright.style.marginLeft="226px";
	btnright.style.height="51px";
	btnright.style.width="20px";
// 	btnright.style.float="left";
	btnright.style.position="absolute";
	btnright.style.top="0px";
	btnright.style.right="0px";
	
	
// 	<div class='crformcotrol'>
// 			<label for='cr_firstname'>First Name : </label>
// 			<input type='text' name='cr_firstname' id=''>
// 		</div>	
// 		<div class='crformcotrol'>
// 			<label for='cr_lastname'>Last Name</label>
// 			<input type='text' name='cr_lastname'></div>
// 			<div class='crformcotrol'>
// 				<label for='cr_email'>Email</label>
// 				<input type='text' name='cr_email' id='cr_email'>
// 			</div>
// 			<div class='crformcotrol'>
// 				<label for='cr_businessname'>Business Name</label>
// 				<input type='text' name='cr_businessname' id='cr_businessname'>
// 			</div>
// 			<div class='crformcotrol'><label for='cr_businesstel'>Business Phone</label><input type='text' name='cr_businesstel' id='cr_businesstel'></div><div class='crformcotrol'><label for='cr_howhear'>How did you hear about us </label><SELECT name=\"cr_howhear\" id=\"cr_howhear\"><option value=\"Print advertising\">Print advertising</option><option value=\"Word of mouth\">Word of mouth</option><option value=\"Internet advertising\">Internet advertising</option><option value=\"Search engine\">Search engine</option></SELECT></div><div class='crformcotrol'><label for='cr_whenbuy'>When are you planning to introduce a new system ?</label><SELECT name=\"cr_whenbuy\" id=\"cr_whenbuy\"><option value=\"Next six months\">Next six months</option><option value=\"Next year\">Next year</option><option value=\"Not sure\">Not sure</option></SELECT></div><div class='crformcotrol'><input type='checkbox' name='cr_newsletter' id='cr_newsletter'><label for='cr_businessname' id='newsletterlabel'>Join Newsletter</label></div><div class='crdashedline'></div><br><div class='bigbtn'><div class='crbtnleft'></div><a id='crsubmit' href='#' onClick='sendpackagecookie(); return false;'>Send me my personalised brochure and proposal</a><div class='crbtnright'></div><br style='clear:both;'></div></form>";
	
	
	var allslct = Array();
	allslct.push($('cr_howhear'));
	allslct.push($('cr_whenbuy'));
// 	var allslct = $$("SELECT")
	allslct.push($('country'));
	for(var i=0; i<allslct.length; ++i)
	{
		if(allslct[i].getAttribute('ID'))
			{
				new Autocompleter.SelectBox(allslct[i].getAttribute('ID'));	
// 				alert("got Autocompleter ?? "+allslct[i].getAttribute('ID'));
			}
	}
	
// 	configurator_result.style.position='absolute';
// 	configurator_result.style.top = '0px';
// 	configurator_result.style.right = '0px';
	configurator_result.style.height = "833px";
	configurator_result.style.width = "0px";
	configurator_result.style.cssFloat = "right";
	configurator_result.style.styleFloat = "right";
// 	configurator_result.style.backgroundColor = "red";
	configurator_result.style.backgroundImage = "url('/images/configurator_bg.png')";
	configurator_result.style.backgroundRepeat = "repeat-x";
	configurator_result.style.display='none';
	
	var nodes = document.getElementById('configurator_result');
	
	for(var i=0; i<nodes.childNodes.length; ++i)
	{
		if(nodes.childNodes[i].getAttribute('class').toLowerCase()=="leftside")
		{
			nodes.childNodes[i].style.position = "relative";
			nodes.childNodes[i].style.width = "243px";
			nodes.childNodes[i].style.height = "692px";
// 			nodes.childNodes[i].style.border = "1px dashed red";
			nodes.childNodes[i].style.margin = "0px 0px 0px 49px";
		}
		if(nodes.childNodes[i].getAttribute('class').toLowerCase()=="rightside")
		{
			nodes.childNodes[i].style.margin = "43px 34px 0px 0px";
			nodes.childNodes[i].style.width = "555px";
			nodes.childNodes[i].style.float="right"
// 			nodes.childNodes[i].style.border="1px dashed green";
			nodes.childNodes[i].style.position="absolute";
			nodes.childNodes[i].style.top="0px";
			nodes.childNodes[i].style.right="0px";
		}



// #configurator_result .rightside {
// margin-left:0 !important;
// margin-right:34px !important;
// margin-top:43px !important;
// width:555px !important;
// }
// front.css (line 2232)
// #configurator_result .rightside, .leftside {
// margin:48px 0 0;
// }
// front.css (line 1839)
// #contentbox .rightside {
// float:right;
// width:280px;
// }



	}
// 	var fdivarr = Array();
// 	var orderformchildnodes = document.getElementById('orderform').childNodes;
// 	for(var q=0; q<=orderformchildnodes.length; ++q)
// 	{
// 		if(orderformchildnodes[q].getAttribute('class') == "crformcotrol")
// 			fdivarr.push(orderformchildnodes[q]);
// 	}

// var fdivarr = new Array();
// 	var fdivarrcover = $$('#configurator_result #orderform')[0].childNodes;
// 	
// 	for(var q=0; q<=fdivarrcover.length; ++q)
// 	{
// 		
// 		if((fdivarrcover[q].getAttribute('class'))=="crformcotrol")
// 		{
// 
// 			fdivarr.push(fdivarrcover[q]);
// // 			alert("what class : "+fdivarrcover[q].getAttribute('class'));
// 		}
// 		
// 	}
// 	
// 	
// 	for(var q=0; q<fdivarr.length; ++q)
// 	{
// 		alert(fdivarr[q].getAttribute('class'))
// 		fdivarr[q].style.backgroundImage = "url(/images/mandatory.png)";
// 		fdivarr[q].style.backgroundPosition = "184px 5px"
// 		fdivarr[q].style.backgroundRepeat = "no-repeat";
// 		
// 	}
}

function sendpackagecookie(formtype)
{


	var form_ = $('orderform');
	
	var divs = $$('#orderform .pleasefill');
	if (divs!=null) for(var i=0; i<divs.length; ++i) divs[i].parentNode.removeChild(divs[i]);

	var form_eles = form_.elements;
	var formchecked = true;

	for(var i=0; i<form_eles.length; ++i)
	{
		var formid=form_eles[i].getAttribute('id');
		if(!(formid=="cr_whenbuy" || formid=="cr_howhear" || formid=="cr_attendees" || formid=="cr_events" || formid=="cr_businesstype" || formid=="cr_message" || formid=="formsubmit" || formid=="cr_newsletter"))
		{
			if(!((form_eles[i].nodeName).toLowerCase()=="select") || (form_eles[i].nodeName))
			{
			  if ((form_eles[i].value.length)<2) {
				var notation = document.createElement("span");
				notation.innerHTML = "require";
				Element.extend(notation);
				notation.addClassName("pleasefill");
				new Insertion.After(form_eles[i], notation);
				formchecked = false;
}
			}
			
		}
	}
	
	if(formchecked)
	{

		document.forms['orderform'].action="/mod/sendtosalesforce.php?type="+formtype;
		document.forms['orderform'].method="POST";
		document.forms['orderform'].submit();
	}

	
}



// function sendpackagecookie(formtype)
// {
// 	var form_ = $('orderform');
// 	var form_eles = form_.elements;
// 	var formchecked = true;
// 
// 	for(var i=0; i<form_eles.length; ++i)
// 	{
// 		var strobj = new String(form_eles[i].value);
// // 		alert("Debug : "+strobj.length);
// 		if(form_eles[i].name=="cr_newsletter")
// 		{
// 		}
// 		else if(form_eles[i].value=="" || form_eles[i].value==null || form_eles[i].value==undefined || ((strobj).length<2))
// 		{
// 			var notation = document.createElement("span");
// 			notation.innerHTML = "required";
// 			
// 			Element.extend(notation);
// 			notation.addClassName("pleasefill");
// 			new Insertion.After(form_eles[i], notation);
// 			if(Prototype.Browser.IE)
// 				notation.style.right = "62px";
// 			formchecked = false;
// 		}
// 		
// 	}
// 	if(formchecked)
// 	{
// 		document.forms[0].action="/mod/sendtosalesforce.php?type="+formtype;
// 		document.forms[0].method="POST";
// 		document.forms[0].submit();
// 	}
// }

function hashpolling(expect,evalstr)
{
  if (location.hash!=('#'+expect)) eval(evalstr);
  else setTimeout("hashpolling(\""+expect+"\",\""+evalstr+"\")",50);
}



function configurator_result_show()
{
	
	location.hash='configuratorresult';
	hashpolling('configuratorresult','window.location=\'/products/build-your-own.html\';');
	//disable screen
// 	var b = $$('body')[0];
// 	var odiv = document.createElement("div");
// 	odiv.addClassName("disablescreen");
// 	new Insertion.Top(b, odiv);
	
	//
// 	leftsidediv.innerHTML = '<h2 class="package_description">Professional...</h2><div class="crimg"><img alt="ef3 package" src="/images/professional_big.png" /><div class="package_description"></div></div><div class="crmoduleslist"><div class="chosenmodules"><span class="chosenmoduletitle">Your Chosen Modules</span><ul class=\'moduleslist\'></ul> </div></div>';
	
	var package = readCookie('currentPackage');
// 	alert(package);
	$$('.crimg img')[0].src='/images/'+package.toLowerCase()+'_big.png';
	$$('.crimg img')[0].style.height='0px';
	$$('.crimg img')[0].style.width='0px';
// 	$$('#configurator_result div')[0].childNodes[0].childNodes[0].innerHTML = "You have chosen <span>"+package+"</span>";
	new Ajax.Request('/mod/generalfuncts.php?ajax=1&option=1&package='+package, {method:'GET',asynchronous:false, onComplete:function(transport)
		{
			$$('html')[0].scrollTop = 0;
			
// 			$$('#configurator_result .crdescription')[0].innerHTML=transport.responseText;
			var ele = document.getElementById('crdescription_id');
			ele.style.color="#747474";
			ele.innerHTML = transport.responseText;
			
		}
	});
	
	
	var modules = $$('.crmoduleslist .chosenmodules .moduleslist')[0];
	/*
		modules.parentNode.style.position="relative";
		modules.style.position="absolute";
		modules.style.top = "0px";
		modules.style.left = "0px";*/
	if(Prototype.Browser.IE)
	{
// 		var allmodules = $$('.crmoduleslist .chosenmodules .moduleslist .eachmodule');
// 		for(var i=0; i<allmodules.length; ++i)
// 			allmodules.style.paddingLeft = "0px";
modules.style.marginLeft = "0px";
	}

// 	alert("Modules list Block : "+modules);
	modules.innerHTML = cr_listModules();
	var result_page = $('configurator_result');
	var parentnode = result_page.parentNode;
	var restore_later = parentnode.removeChild(result_page);
	while(parentnode.firstChild)
	{
		parentnode.removeChild(parentnode.firstChild);
	}
	new Insertion.Top(parentnode, restore_later);
// 	parentnode.style.position = 'relative';
// 	restore_later.style.position='absolute';
// 	restore_later.style.top = '0px';
// 	restore_later.style.right = '0px';
	restore_later.style.display = "block";
	new Effect.Morph('configurator_result', 
		{
		style: 'width:930px;',
		duration: 0.9 // Core Effect properties
		}
	);
	
	setTimeout("$$('.crimg img')[0].morph('width:300px;height:483px;')", 910);
}
// function targetasiframe(postto)
// {
// 	var addeventto = $$('.btncontrol .submitcover #submitbtn')[0];
// 	
// 	addeventto.observe('click', configurator_result_show);
// 	
// 	var packageresult = document.createElement('iframe');
// 	packageresult.setAttribute('name', 'configurator_result');
// 	packageresult.setAttribute('id', 'configurator_result');
// // 	http://eventsforce.b42.co.uk/productsmodules/modules.html
// 	packageresult.setAttribute('src', '/productsmodules/modules.html');
// 	packageresult.setAttribute('width', '0');
// 	packageresult.setAttribute('height', '0');
// 	packageresult.setAttribute('frameborder', 'no');
// 	packageresult.style.position = "absolute";
// 	packageresult.style.top = '0px';
// 	packageresult.style.right = '0px';
// 	new Insertion.Top($$('body')[0], packageresult);
// 	
// }
// function configurator_result_show()
// {
// 	var targetframe = $$("iframe[name=configurator_result]");
// 	
// 	new Effect.Morph('configurator_result', 
// 		{
// 		style: 'width:100%;height:100%;',
// 		duration: 0.8 // Core Effect properties
// 		}
// 	);
// 
// }
function clickleft()
{
	var eachmodules = $$('.sliderformodules .eachmodule');
	var lastone = eachmodules[(eachmodules.length)-1];
	lastone.style.width = "0px";
	lastone.style.marginLeft = "0px";
	lastone.style.marginRight = "0px";
	var addtohead = lastone.parentNode.removeChild(lastone);
	new Insertion.Before(eachmodules[0], addtohead);
	
	new Effect.Morph(addtohead.id, {style: 'width:161px;margin-left:16px;margin-right:16px;', duration: 0.8});
	
}
function clickright()
{
	var eachmodules = $$('.sliderformodules .eachmodule');
	var firstone = eachmodules[0];
	new Effect.Morph(firstone.id, {style: 'width:0px;margin-left:0px;margin-right:0px;',duration: 0.8});
	
	setTimeout("movetoend('"+firstone.id+"')",820);
}
function movetoend(id)
{
	
	var obj = $(id);
	
	var thisobj = obj.parentNode.removeChild(obj);
	var modules = $$('.sliderformodules .eachmodule');
	new Insertion.After(modules[parseInt(modules.length)-1], thisobj);
	var addwidthtothis = $(thisobj.id);
	addwidthtothis.style.width = '161px';
	addwidthtothis.style.marginLeft = "16px";
	addwidthtothis.style.marginRight = "16px";
	
}
function choosePackage(packagename)
{
	
// 	alert(packagename);
//this will not be executed if set package at domreadydo *********************
	if(!readCookie('currentPackage'))
	{
		createCookie('currentPackage', 'mypackage');
		$('defautpackage').style.display = "block";
// 		createCookie('currentPackage', 'solo');
// 		$$('#contentbox .rightside .c_package_description .title')[0].innerHTML = "You have chosen "+packagename;
// 		
// 		new Ajax.Request('/mod/generalfuncts.php?ajax=1&option=1&package='+packagename, {method:'GET',asynchronous:true, onComplete:function(transport)
// 			{
// 				
// 				$$('#contentbox .rightside .c_package_description .description')[0].innerHTML=transport.responseText;
// 			}
// 		});
	}
	var curpack = readCookie('currentPackage').toLowerCase();
	if(curpack.toLowerCase() != packagename.toLowerCase())
	{
		
				if($('defautpackage').style.display=="block")
					$('defautpackage').style.display = "none";
				var packageimg = $$('.rightside .img img')[0];	
				$$('.rightside .sliderdiv')[0].fade({duration:durations, from:1, to:0});
				packagename = packagename.toLowerCase();
				createCookie('currentPackage',packagename);
				var ucfpackagename =packagename.toLowerCase().replace(/\w/, function(first_letter){
    return first_letter.toUpperCase();
  });
				$$('#contentbox .rightside .c_package_description .title')[0].innerHTML = "You have chosen "+capitalizeMe(ucfpackagename);
				new Ajax.Request('/mod/generalfuncts.php?ajax=1&option=1&package='+packagename, {method:'GET',asynchronous:true, onComplete:function(transport)
					{
						$$('#contentbox .rightside .c_package_description .description')[0].innerHTML=transport.responseText;
					}
				});
				
				setTimeout("showNewPackage('"+packagename+"')", 700);
			
	}
	else
	{
		
		if(packagename == "mypackage")
		{
			$("defautpackage").style.display = "block";
		}
		if(updateimage)
		{
			
			var imgsrc = "/images/"+curpack+"_big.png";
			
			$$('.formblock .img .sliderdiv img')[0].src = imgsrc;
			
			$$('.formblock .sliderdiv h2')[0].innerHTML = curpack;
			updateimage = false;
		}
			$$('#contentbox .rightside .c_package_description .title')[0].innerHTML = "You have chosen "+capitalizeMe(packagename);
			new Ajax.Request('/mod/generalfuncts.php?ajax=1&option=1&package='+packagename, {method:'GET',asynchronous:true, onComplete:function(transport)
				{
					$$('#contentbox .rightside .c_package_description .description')[0].innerHTML=transport.responseText;
				}
			});
		
	}
	createCookie('currentPackage',packagename);
// 	$('defautpackage').style.display = "block";
}

function showNewPackage(packagename)
{
// 	alert($$('.sliderdiv .package_description')+" LENGTH : "+$$('.sliderdiv .package_description').length);
		packagename=packagename.toLowerCase().replace(/\w/, function(first_letter){
    return first_letter.toUpperCase();
  });

// 		while($$('.sliderdiv .package_description').length>0)
		while($$('.sliderdiv h2').length>0)
		{
			var elearr_ = $$('.sliderdiv h2');
			
			for(var k=0; k<elearr_.length;++k)
			{
			
				elearr_[k].parentNode.removeChild(elearr_[k]);
				//$$('.sliderdiv .package_description')[0]
			}
		}
		
// 		while($$('.sliderdiv .package_description').length>0)
// 		{
// 			var elearr_ = $$('.sliderdiv .package_description');
// 			
// 			for(var k=0; k<elearr_.length;++k)
// 			{
// 			
// 				elearr_[k].parentNode.removeChild(elearr_[k]);
// 				//$$('.sliderdiv .package_description')[0]
// 			}
// 		}
		
		var package = document.createElement('h2');
		package.setAttribute('class', 'package_description');
		package.setAttribute('id', 'package_description_id');
		package.style.textAlign="left";
		package.style.textTransform = "capitalize"
		package.style.padding = "0px 0px 30px 13px";
		package.style.color="#00B8DA";
		package.style.margin="0px";
		package.innerHTML = packagename+"...".toUpperCase();
		
	
	if(!readCookie('currentPackage'))
		createCookie('currentPackage', 'solo');
	var curpack = readCookie('currentPackage');
			var packageimg = $$('.rightside .img img')[0];
			new Insertion.Before(packageimg, package);
			$$('.rightside .sliderdiv')[0].appear({duration:durations})
		packageimg.setAttribute('src', '/images/'+curpack.toLowerCase()+'_big.png');
}

function addevent()
{
	
	
}
function addnumbering()
{
	
	var formcontrols = $$('.formcontrol');
	
	for(var i=0; i<(formcontrols.length)-1; ++i)
	{
		var span = document.createElement('div');
		Element.extend(span);
// 		span.setAttribute('class', 'numbering');
	span.addClassName('numbering');
		
		span.innerHTML = i+1;
formcontrols[i].appendChild(span);
	}
}
function selectonchange(srcobject, whichone)
{
	document.getElementById('showval_'+whichone).innerHTML=srcobject.options[srcobject.selectedIndex].text;

}

function recalculatePackage()
{

		var managers = $('managers').options[$('managers').selectedIndex].value;
	var events = $('events').options[$('events').selectedIndex].value;
	var delegates = $('delegates').options[$('delegates').selectedIndex].value;
	var country = $$('input[name=wheres]');
	
	country = getchecked(country);
	
// 	var sector = $('sector_combo');
// 	
// 	addSetting(sector.value);
	
// 	var opts = $("sector").options;
	
// 	for(var i=0; i<opts.length;++i)
// 	{
// 		if(opts[i].value == sector.value)
// 			continue;
// 		removeSetting(opts[i].value);
// 	}
	
	var charges = $$('input[name=charges]');
	charges = getchecked(charges);
// 	alert(country.getAttribute('value'));
	
// 	alert("to calculate : "+managers+":"+events+":"+delegates);
	managers = parseInt(managers);
	events = parseInt(events);
	delegates = parseInt(delegates);

createCookie('managers', managers);
createCookie('events', events);
createCookie('delegates', delegates);

createCookie('country', country.getAttribute('value'));
createCookie('charges', charges.getAttribute('value'));

// createCookie('sector', sector.value);

	var configform = $('configform');
	var formeles = configform.elements;
	var configtosave = Array();
	for(var i=0; i<formeles.length; ++i)
	{
// 		alert(formeles);
// 		try
// 		{
// 			if((formeles[i].getAttribute("name")).toLowerCase()=="sector")
// 			{
// 				
// 				var current_ = formeles[i].getAttribute("id");
// 				alert(current_);
// 				addSetting(current_);
// 				var ele_ = $('sector');
// 				for(var i=0; i<ele_.length; ++i)
// 				{
// 					if((ele_[i].getAttribute('id')).toLowerCase() == current_.toLowerCase())
// 						continue;
// 					removeSetting(ele_[i].getAttribute('id'));
// 				}
// 			}
// 		}
// 		catch(e)
// 		{
// 			alert(e);
// 		}
		
		if(formeles[i].getAttribute("name") && formeles[i].value)
		{
			var inputtype = formeles[i].type;
			if(inputtype.toLowerCase() == "radio")
			{
				if(formeles[i].checked)
				{
					configtosave.push(formeles[i].getAttribute("name")+":"+formeles[i].value);
				}
			}
			else
			{
// 				if((formeles[i].getAttribute("name")).toLowerCase() == "sector")
// 				{
// 					var cur_sector = formeles[i].value;
// 					
// 					addSetting(cur_sector);
// 					try
// 					{
// 						
// 						var _ele_ = $('sector').options;
// 						for(var j=0; j<=_ele_.length; ++j)
// 						{
// 							if((_ele_.value).toLowerCase() == cur_sector.toLowerCase())
// 								continue;
// 							removeSetting(_ele_.value);
// 							alert("Debug : have remove this "+_ele_.value);
// 						}
// 					}
// 					catch(e)
// 					{
// 						alert(e);
// 					}
// 				}
				configtosave.push(formeles[i].getAttribute("name")+":"+formeles[i].value);
			}
		}
	}
	var configcookie = configtosave.join(",");
// 	alert(configcookie);
	createCookie("remconfig", configcookie);
// 	alert(configcookie);
if(modulestoent())
{
	choosePackage('Enterprise');
}
else
{
if (managers==1) 
  {
// 		alert('manager == 1');
	// 	if value of [Events] < 14 and value of [Delegates] <  1700 then
	if ((events<14)&&(delegates<1700)) 
		{
		// select Package {Single}
		choosePackage('solo');
		}
	// if value of [Events] > = 14 or value of [Delegates] > = 1700 then
	else if ((events>=14)||(delegates>=1700))
		{
		// select Package {Professional}
		choosePackage('professional');
		// end if
		}
		
	}
 
// If value of [Event managers] > 1 and < =4 then
if ((managers>1)&&(managers<=4))
	{
// 		alert('manager > 1');
	// 	if value of [Events] < 18 and value of [Delegates] <  2800 then
	if ((events<18)&&(delegates<2800))
		{
		// select Package {Team}
		choosePackage('Team');
		
		}
	// else
	// if value of [Events] > = 18 or value of [Delegates] > = 2800 then
	else if ((events>=18)||(delegates>=2800))
		{
		// select Package {Professional}
		choosePackage('Professional');
		}
	
	}
	// end if
// 
// If value of [Event managers] > 4 and <= 12 then
if (managers>4)
	{
		
// 	if value of [Events] < 60 and value of [Delegates] <  8000 then
	if ((events<60)&&(delegates<8000))
	  {
		
// select Package { Professional }
		choosePackage('Professional');
		}
// else
// if value of [Events] > = 60 or value of [Delegates] > = 8000 then
	else if ((events>=60)||(delegates>=8000))
  	{
			
// select Package {Enterprise}
		choosePackage('Enterprise');
	  }
		
// end if
	}
}

// 



}
function modulesmanage()
{
	
var charges=$$('input[name=charges]');
charges = getchecked(charges);

var where = $$('input[name=wheres]'); //array
where = getchecked(where);

var accommodation = $$('input[name=config_accommodation]');
accommodation = getchecked(accommodation);

var awards_table = $$('input[name=awards_table]');
awards_table = getchecked(awards_table);

var abstract_submissions = $$('input[name=abstract_submissions]');
abstract_submissions = getchecked(abstract_submissions);

var websites = $$('input[name=config_websites]');
websites = getchecked(websites);

// if value of [Q.5] is “Always” then Add {Financial Module} in the Package results 
var modules = Array();
var detectEnterprise = Array();
if(charges)
{
	addSetting(charges.getAttribute('id'));
	
}
if(charges.value=="always" || charges.value=="sometimes")
{
	addModule('Financial');
}
if(charges.value=="never")
{
	var ele_ = $$('input[name=charges]');
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			try
			{
				
				var maybethis = ele_[i].getAttribute('id');
				if(maybethis == charges.getAttribute('id'))
						continue;
				removeSetting(maybethis);
				
			}
			catch(e)
			{
// 				alert("not this one in setting : "+maybethis);
			}
		}
	}
// 	removeSetting('charges2');
	removeModule('Financial');
}

// if value of [Q.6] is “EMEA” or “World” then Add {Multilingual Module} in the Package results
if(where)
{
	addSetting(where.getAttribute('id'));
}
if(where.value=="UK" || where.value=="USA")
{
	var ele_ = $$('input[name=wheres]')
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			var maybethis = ele_[i].getAttribute('id');
			try
			{
				if(maybethis == where.getAttribute('id'))
					continue;
				removeSetting(maybethis);
			}
			catch(e)
			{
			}
		}
	}
	removeModule('Multilingual');
}
if(where.value=="EMEA" || where.value=="World") //World
{

	addModule('Multilingual');
}
// if value of [Q.7] is “Yes” then Add {Flight Module}and{Accommodation Module}  in the Package results 

if(accommodation)
{
	
	addSetting(accommodation.getAttribute('id'));
}
if(accommodation.value=="yes")
{
	addModule('Flights');
	addModule('Accommodation');
}
if(accommodation.value == "no")
{
	
	var ele_ = $$('input[name=config_accommodation]')
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			var maybethis = ele_[i].getAttribute('id');
			try
			{
				if(maybethis == accommodation.getAttribute('id'))
					continue;
				removeSetting(maybethis);
			}
			catch(e)
			{
			}
		}
	}
	removeModule('Flights');
	removeModule('Accommodation');
}
// if value of [Q.8] is “Yes” then Add {Awards Module}and{Table Manager Module}  in the Package results 
if(awards_table)
{
	
	addSetting(awards_table.getAttribute('id'));
}
if(awards_table.value == "yes")
{
	
// 	addSetting('awards_table');
	addModule('Awards');
	addModule('Table Manager');
}

if(awards_table.value == 'no')
{
	var ele_ = $$('input[name=awards_table]')
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			var maybethis = ele_[i].getAttribute('id');
			try
			{
				if(maybethis == awards_table.getAttribute('id'))
					continue;
				removeSetting(maybethis);
			}
			catch(e)
			{
			}
		}
	}
	
	removeModule('Awards');
	removeModule('Table Manager');
}
// if value of [Q.9] is “Yes” then Add {Abstracts Module} in the Package results 
if(abstract_submissions)
	addSetting(abstract_submissions.getAttribute('id'))
if(abstract_submissions.value == "yes") 
{
	
	addModule('Abstracts');
}
else if(abstract_submissions.value == "no")
{
// 	removeSetting('abstract_submissions');
var ele_ = $$('input[name=abstract_submissions]')
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			var maybethis = ele_[i].getAttribute('id');
			try
			{
				if(maybethis == abstract_submissions.getAttribute('id'))
					continue;
				removeSetting(maybethis);
			}
			catch(e)
			{
			}
		}
	}
	removeModule('Abstracts'); //Abstracts
}
// if value of [Q.10] is “Yes” then Add {Web Site Module} in the Package results 
if(websites)
	addSetting(websites.getAttribute('id'));
if(websites.value == "yes") 
{
	
	addModule('Website');
}
else if(websites.value == "no")
{
	var ele_ = $$('input[name=config_websites]')
	if(ele_)
	{
		for(var i=0; i<ele_.length; ++i)
		{
			var maybethis = ele_[i].getAttribute('id');
			try
			{
				if(maybethis == websites.getAttribute('id'))
					continue;
				removeSetting(maybethis);
			}
			catch(e)
			{
			}
		}
	}
	removeModule('Website');
	
}
}
function modulestoent()
{
	var count =0;
	var s = readCookie('setting');
	
	if (s)
	{
		var setting = s.split(',');
		var arr = Array('websites', 'awards_table', 'accommodation', 'abstract_submissions')
		
		for(var i=0; i<setting.length; ++i)
		{
			for(var j=0; j<arr.length; ++j)
				if(arr[j].toLowerCase() == setting[i].toLowerCase())
				{
					count += 1;
				}
		}
		
		if(count>=2)
			return true;
		else
			return false;
	}
	return false;
}
function checkindex(mlist, m)
{
	var result = -1;
	for(var i=0; i<mlist.length; ++i)
	{
		if(mlist[i] == m)
		{
			result = i;
			break;
		}
	}
	return result;
}
function getchecked(radio)
{
	for(var i=0;i<radio.length;++i)
	{
		if(radio[i].checked)
		{
			var status_ = true;
			radio = radio[i];
			break;
		}
	}
	if(!status_)
	{
		
			radio = radio[0];
	}
	return radio;
}
function checkmodules(mlist, m)
{
	var result = 0;
	for(var i=0; i<mlist.length; ++i)
	{
		if(mlist[i] == m)
		{
			result = 1;
		}
	}
	return result;
}
// function addmodules(modules)
// {
// 	
// 	var moduleshow = $$('.chosenmodules .moduleslist')[0];
// 
// 	for(var i=0; i<(moduleshow.childNodes).length; ++i)
// 	{
// 		moduleshow.removeChild((moduleshow.childNodes).item(i));
// 	}
// 	
// 	while((moduleshow.childNodes.length) > 0)
// 	{
// 		//remove again 
// 		for(var i=0; i<(moduleshow.childNodes).length; ++i)
// 		{
// 			moduleshow.removeChild((moduleshow.childNodes).item(i));
// 		}
// 	}
// 	
// 	for(var i=0; i<modules.length; ++i)
// 	{
// 		
// 		var minusbtn = document.createElement('a');
// 		minusbtn.setAttribute('class', 'minusbtn');
// 		minusbtn.setAttribute('onClick', "removeModule(this)");
// 		
// 		var li = document.createElement('li');
// 		li.setAttribute('class', 'eachmodule');
// 		li.innerHTML = modules[i];
// 		moduleshow.appendChild(li);
// 		
// 		new Insertion.Top(li, minusbtn);
// 		
// 	}
// 	
// 	
// 	if($$('.chosenmodules .moduleslist .eachmodule').length > 0)
// 	{
// 		if($$('.default_text')[0])
// 		{
// 			$$('.default_text')[0].parentNode.removeChild($$('.default_text')[0]);
// 		}
// 	}
// 	else
// 	{
// 		if(!$$('.default_text')[0])
// 		{
// 			var addaftertitle = document.createElement('span');
// 			addaftertitle.setAttribute('class', 'default_text');
// 			addaftertitle.innerHTML = "You currently have no modules chosen";
// 			new Insertion.After($$('.chosenmoduletitle')[0], addaftertitle);
// 		}
// 	}
// }
  function convertSelectToSlider(sourceObj,s)
	{
	    var sld = document.createElement('div');
	    sld.setAttribute('id','slider'+s);
	    sld.setAttribute('class','slider');
			sld.style.margin="0px auto 0px auto";
			sld.style.width='246px';
			sld.style.height='3px';
		sld.style.position="relative";

	    new Insertion.Before(sourceObj,sld);
			
			var slh = document.createElement('div');
			slh.innerHTML='&nbsp;';
			
			slh.style.width='14px';
			slh.style.height='23px';
			slh.style.backgroundImage="url('/images/slider_handle.gif')";
			slh.style.position='absolute';
			slh.style.cursor='e-resize';

			if (slh.getAttribute('class')==null) slh.setAttribute('class','handle');
		  else  slh.setAttribute('class',slh.getAttribute('class')+' handle');
			slh.setAttribute("id", "handle"+s);
	    document.getElementById('slider'+s).appendChild(slh);
			
			
//	    var slider = $('slider'+s); //same as sld
			var slider = sld;
			var box = $('text');
			//get handle for IE
			
//			for(var i=0; i<slider.childNodes.length; ++i)
//			{
//				
// 				if((slider.childNodes[i].getAttribute('class')).toLowerCase() == "handle")
// 					var handle = slider.childNodes[i]; //same as slh
// 			}
			var handle = slh;
			
	    var optionlist = Array();
			
	    for (var o=0;o<sourceObj.options.length;o++)
			{
					optionlist.push(o);
			}
			
	    new Control.Slider(handle, slider, 
	     {
	      range: $R((optionlist.min()), (optionlist.max())),
	      sliderValue: sourceObj.selectedIndex,
	      values: optionlist,
	      onSlide: function(value) 
				{
					var sourceObj = $$('.sliderreplacement')[s];

					a=value;
					sourceObj.selectedIndex=a;
					sourceObj.onchange();
	      },
	      
	      onChange: function(value,sourceObj) 
				{ 
					var sourceObj = $$('.sliderreplacement')[s];

					a=value;
					sourceObj.selectedIndex=a;
					sourceObj.onchange();
	      }
	     });
			 
		sourceObj.onchange();
		sourceObj.style.left='-999em';
		sourceObj.style.position='absolute';
	}    

function listModules()
{
 var m = readCookie('modules');
 
 var template = '<li class="eachmodule"><a onclick="removeModule(\'modulename\')" class="minusbtn"></a>modulename</li>';
 if (m) 
	 var modules = m.split(',');
 else 
	 return "<span class='default_text'>You currently have no modules chosen..</span>"; 
 modules.sort();
 var o = '';
 for (var i=0;i<modules.length;i++) 
		o = o + template.replace(new RegExp('modulename','g'),modules[i]);
	 
return o;
}
function cr_listModules()
{
 var m = readCookie('modules');
 
 var template = '<li class="eachmodule"><span><img src="/images/ulbullet.png"></span>modulename<br style="clear:both;"></li>';
 if (m) 
	 var modules = m.split(',');
 else 
	 return "<span class='default_text'>You currently have no modules chosen..</span>"; 
 modules.sort();
 var o = '';
 for (var i=0;i<modules.length;i++) 
		o = o + template.replace(new RegExp('modulename','g'),modules[i]);
	 
return o;
}
function addModule(modulename)
{	
	
 var m = readCookie('modules');
 if (m) 
	 var modules = m.split(',');
 else 
	 var modules = Array();
 for (var i=0;i<modules.length;i++) 
   {
    if (modules[i]==modulename)
		{
			
			return updateModuleCookie(m);
		}
   }
	 
 modules[modules.length]=modulename;
 return updateModuleCookie(modules.join(','));
}

function addSetting(settingname)
{
	
	var s = readCookie('setting');
 if (s) 
	 var setting = s.split(',');
 else 
	 var setting = Array();
 for (var i=0;i<setting.length;i++) 
   {
// 		 alert("current setting : "+);
    if (setting[i]==settingname)
		{
			
			return updateSettingCookie(s);
		}
   }
	 
 setting[setting.length]=settingname;
 return updateSettingCookie(setting.join(','));
}

function removeModule(modulename)
{
 var m = readCookie('modules');
 if (m) var modules = m.split(',');
 else var modules = Array();
var newmodules = Array();
 for (var i=0;i<modules.length;i++) 
   {
    if (modules[i]==modulename) continue;
    newmodules[newmodules.length]=modules[i];
   }
 return updateModuleCookie(newmodules.join(','));
}

function removeSetting(settingname)
{
 var s = readCookie('setting');
 if (s) var setting = s.split(',');
 else var setting = Array();
var newsetting = Array();
 for (var i=0;i<setting.length;i++) 
   {
    if (setting[i]==settingname) continue;
    newsetting[newsetting.length]=setting[i];
   }
 return updateSettingCookie(newsetting.join(','));
}

function updateModuleCookie(txt)
{
	
   createCookie('modules',txt); // session cookie
	 var objitem = $$('.rightside .chosenmodules .moduleslist')[0];
   if (objitem) 
	 {
		 objitem.innerHTML=listModules(); 
	 }
   return false;
}
function updateSettingCookie(txt)
{
	
   createCookie('setting',txt); // session cook
   return false;
}

function createCookie(name,value,days) {
	
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
// 	alert("have do this !!");
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



	
	/////////////////

