var tempHolder = '';

function proceed_registration_nobill(str_q) {
	if (str_q && str_q.indexOf("add=yes") != -1)
                clr_order_overlay();
	else
		$("#id_divorderbody").fadeOut("slow", function(){$("#id_divbody3").fadeIn("slow",null);});
}

function do_order() {	
	//$("#id_divoverlay").fadeIn("slow");
	//ajax_query_get_xml("apps/register.php?getcat=11", null, function(ObjXml,StrStat){post_products(ObjXml,StrStat,'&add=yes');});
	$("#default-page").hide();
	$("#temporary-page").hide();
	$("#loading-page").show();
	ajax_query_get_xml("apps/register.php?getcat=11", null, displayOrder);
}

function createGroupTitle(title) {
	var thead = document.createElement("thead");
	var tr, th;
	
	tr = document.createElement("tr");
	th = document.createElement("th");		
	th.setAttribute("colspan", "4");
	th.setAttribute("style", "font-size:10pt; font-weight:bold; padding-top: 20px; padding-bottom:10px;");
	th.innerHTML = title;		
	tr.appendChild(th);
	thead.appendChild(tr);
	
	tr = document.createElement("tr");
	tr.setAttribute("style", "background-color: #CCCCCC;");
			
	th = document.createElement("th");
	th.innerHTML = "Quantity";
	th.setAttribute("nowrap", "nowrap");
	tr.appendChild(th);
		
	th = document.createElement("th");
	th.innerHTML = "Product Name";
	th.setAttribute("width", "100");
	th.setAttribute("nowrap", "nowrap");
	tr.appendChild(th);
		
	th = document.createElement("th");
	th.innerHTML = "Price";
	th.setAttribute("align", "right");
	th.setAttribute("nowrap", "nowrap");
	tr.appendChild(th);
		
	th = document.createElement("th");
	th.innerHTML = "&nbsp;";
	th.setAttribute("nowrap", "nowrap");
	tr.appendChild(th);
	thead.appendChild(tr);
	
	return thead;
}

function displayOrder(xml, stat) {
	var order = [];
	order.meetings = {tbody:document.createElement("tbody"), length:0};
	order.manuals = {tbody:document.createElement("tbody"), length:0};
	order.kits = {tbody:document.createElement("tbody"), length:0};
	order.misc = {tbody:document.createElement("tbody"), length:0};
	
	xml = xml.childNodes[0];
	xml = xml.nextSibling ? xml.nextSibling : xml;
	for (var i=0; i<xml.childNodes.length; i++) {
		var row = xml.childNodes[i];
		var data = [];
		
		for (var j=0; j<row.childNodes.length; j++) {
			data[row.childNodes[j].tagName] = row.childNodes[j].textContent || row.childNodes[j].text;
		}
		
		var tr = document.createElement("tr"), td;
		
		var input = document.createElement("input");
		input.setAttribute("name", "prodid_"+data.ident);
		input.setAttribute("type", "text");
		input.setAttribute("maxlength", "4");
		input.setAttribute("size", "4");
		input.setAttribute("value", "0");
		input.setAttribute("style", "font-size:8pt; text-align:right;");
		
		td = document.createElement("td");
		td.appendChild(input);
		tr.appendChild(td);
		
		td = document.createElement("td");
		td.setAttribute("id", "prodname_"+data.ident);
		td.setAttribute("align", "left");
		td.setAttribute("nowrap", "nowrap");
		td.innerHTML = data.name;
		tr.appendChild(td);
		
		td = document.createElement("td");
		td.setAttribute("id", "prodprice_"+data.ident);
		td.setAttribute("align", "right");
		td.setAttribute("nowrap", "nowrap");
		td.innerHTML = data.price;
		tr.appendChild(td);
		
		var a = document.createElement("a");
		a.setAttribute("id", "desc-"+i);
		a.setAttribute("href", "#");
		a.innerHTML = "show/hide description";
		a.onclick = function () {
			$("#order-"+this.getAttribute("id")).toggle();
			$("#"+this.getAttribute("id")).next("tr").show();
			return false;
		};
		
		td = document.createElement("td");
		td.setAttribute("align", "right");
		td.setAttribute("nowrap", "nowrap");
		td.appendChild(a);
		tr.appendChild(td);

		var category = "misc";
		if (data.name.match(/meeting/i)) {
			category = "meetings";
		} else if (data.name.match(/manual/i)) {
			category = "manuals";
		} else if (data.name.match(/train|kit/i)) {
			category = "kits";
		}
		
		if (!!$.cookie("buy_product")) {
			if (category != $.cookie("buy_product")) continue;
		}
		
		tr.setAttribute("style", "background-color: "+(order[category].length%2 ? "#E5E5E5" : "#EEEEEE"));		
		order[category].tbody.appendChild(tr);
		order[category].length++;
		
		td = document.createElement("td");
		td.setAttribute("id", "proddesc_"+data.ident);
		td.setAttribute("colspan", "5");
		td.innerHTML = data.description;
		tr = document.createElement("tr");
		tr.setAttribute("id", "order-desc-"+i);
		tr.setAttribute("style", "display:none; background-color: #F8F8F8;");
		tr.appendChild(td);
		order[category].tbody.appendChild(tr);
	}
	
	var td = document.createElement("td"), input;
	td.setAttribute("align", "center");
	td.setAttribute("colspan", "4");
	td.setAttribute("style", "padding-top:20px;");
	
	input = document.createElement("input");
	input.setAttribute("type", "button");
	input.setAttribute("value", "Later");
	input.setAttribute("style", "margin-right:10px;");
	input.onclick = function () {
		$("#temporary-page").hide();
		$("#default-page").show();
		$("html, body").animate({scrollTop: "0px"}, 300);
		return false;
	};
	td.appendChild(input);
	
	input = document.createElement("input");
	input.setAttribute("type", "submit");
	input.setAttribute("value", "Submit");
	input.onclick = function () {
		proceed_registration("&add=yes");
		return false;
	};
	td.appendChild(input);
	
	var table = document.createElement("table");
	table.setAttribute("border", "0");
	table.setAttribute("cellpadding", "5");
	table.setAttribute("cellspacing", "0");
	table.setAttribute("width", "100%");
	table.setAttribute("style", "font-size:8pt;");
	if (order.meetings.length > 0) {
		table.appendChild(createGroupTitle("SAFETY MEETINGS"));
		table.appendChild(order.meetings.tbody);
	}
	if (order.manuals.length > 0) {
		table.appendChild(createGroupTitle("SAFETY MANUALS"));
		table.appendChild(order.manuals.tbody);	
	}
	if (order.kits.length > 0) {
		table.appendChild(createGroupTitle("TRAINING KITS"));
		table.appendChild(order.kits.tbody);
	}
	if (order.misc.length > 0) {
		table.appendChild(createGroupTitle("MISC"));
		table.appendChild(order.misc.tbody);	
	}
	table.appendChild(document.createElement("tr").appendChild(td));
	
	$("#temporary-page").html(table);
	$("#loading-page").hide();
	$("#temporary-page").show();
}

function validateOrder(page) {
	new Request({
		url: 'remote/checkAccess.php',
		method: 'get',
		onSuccess: function(transport) {
			if (transport == true)
				window.location.href = page+'.php';
			else
				window.location.href = 'main.php';
		}
	}).send(null);
}

function post_orders(ObjXML, stat, dl) {
	var dtablebody = document.getElementById("id_tablebody");
	$("#id_divorderbody").find("table").each(function(i){
		$(this).empty();
	}); 
        var dthead = document.createElement("thead");
        var dtbody = document.createElement("tbody");
        var dtr = document.createElement("tr");
        var dth = document.createElement("th");
        dtablebody.appendChild(dthead);
        dtablebody.appendChild(dtbody);
        dthead.appendChild(dtr);
        dtr.appendChild(dth);
        dth.setAttribute("align", "center");
        dth.setAttribute("colspan", "4");
        !dl?dth.appendChild(document.createTextNode("Order Details")):dth.appendChild(document.createTextNode("Downloadables"));
        dtr = document.createElement("tr");
        dtd = document.createElement("td");
        dtr.appendChild(dtd);
        dtbody.appendChild(dtr);
        dtd.setAttribute("colspan", "4");
        dtd.innerHTML = "&nbsp;";
        dtr = document.createElement("tr");
        dtbody.appendChild(dtr);
        dtd = document.createElement("td");
        dtd.setAttribute("align", "center");
        dtd.className = "highlight";
        dtd.appendChild(document.createTextNode("Quantity"));
        dtr.appendChild(dtd);
        dtd = document.createElement("td");
        dtd.setAttribute("align", "center");
        dtd.className = "highlight";
        dtd.appendChild(document.createTextNode("Product Name"));
        dtr.appendChild(dtd);
        dtd = document.createElement("td");
        dtd.setAttribute("align", "center");
        dtd.className = "highlight";
        dtd.appendChild(document.createTextNode("Price"));
        dtr.appendChild(dtd);
        dtd = document.createElement("td");
        dtd.setAttribute("align", "center");
        dtd.className = "highlight";
        dtd.appendChild(document.createTextNode("Total Price"));
        dtr.appendChild(dtd);
        var Oxml1 = ObjXML.childNodes[0];
        Oxml1 = Oxml1.nextSibling ? Oxml1.nextSibling : Oxml1;
        var ilen = Oxml1.childNodes.length;
        for (inc1=0;inc1<ilen;inc1++) {
          dtr = document.createElement("tr");
          dtr.className = (inc1%2?"tableAltOne":"tableAltTwo");
          dtbody.appendChild(dtr);
          var Oxml2 = Oxml1.childNodes[inc1];
          ilen2 = Oxml2.childNodes.length;
          for (inc2=0;inc2<ilen2;inc2++) {
            var tname = Oxml2.childNodes[inc2].tagName;
            var ttext = Oxml2.childNodes[inc2].textContent || Oxml2.childNodes[inc2].text;
            if (tname != "pident") {
              dtd = document.createElement("td");
              dtr.appendChild(dtd);
              dtd.innerHTML = ttext;
            }
          }
        }
        if (dl)
          $("#id_tablebody").ready(function(){
            $("#id_tablebody").find("tr[class^=tableAlt]").each(function(ii){
              /*start*/ 
            });
          });
        $("#id_divorderbody").fadeIn("slow", null);
        return true;
}

function do_vorder() {
        $("#id_divoverlay").fadeIn("slow");
        ajax_query_get_xml("apps/orders.php?&oid="+$(this).attr('oid'), null, function(Oxml,Istat){post_orders(Oxml,Istat,0);});
}

function do_download() {
        $("#id_divoverlay").fadeIn("slow");
        ajax_query_get_xml("apps/download.php?&oid="+$(this).attr('oid'), null, function(Oxml,Istat){post_orders(Oxml,Istat,1);});
}

function clr_order_overlay() {
	$("#id_divorderbody").fadeOut("slow", null);
	$("#id_divoverlay").fadeOut("slow", null);
	window.location.href = "main.php";
}

function proceed_registration(str_q) {
	var user_id = getcookie('user_id');
	var sess_id = getcookie('sess_id');
	var sess_key = getcookie('sess_key');
	var strq = 'makeorder=yes'+str_q;
	var prodstr = '';
	var total_price = 0.0;
	var str_display = '';
	$("input[name^=prodid_]").each(function(i){
     	var prodval = parseInt(trim($(this).val()), 10);
        	if (!isNaN(prodval) && prodval > 0) {
        		var prodidstr = trim($(this).attr("name"));
           		var prodid = parseInt(prodidstr.substr(7), 10);
        		var prodprice = parseFloat($("#prodprice_"+prodid).html());
        		var prodname = phpjs.html_entity_decode($("#prodname_"+prodid).html());
        		var proddesc = $("#proddesc_"+prodid).html();
        		str_display += 'Name        : '+prodname+'\nPrice          : '+phpjs.sprintf("%.2f",prodprice)+'\nQuantity    : '+prodval+'\nTotal Price : '+phpjs.sprintf("%.2f",prodprice*prodval)+'\n\n';
        		total_price += prodprice*prodval;
        		prodstr += prodid+'|'+prodval+';';	
				tempHolder = prodname+'|'+phpjs.sprintf("%.2f",prodprice)+'|'+prodval+'|'+phpjs.sprintf("%.2f",prodprice*prodval);

        	}
        });
	if (str_display == '')
		return false;
	if (confirm(str_display+'\nGrand Total Price  : '+phpjs.sprintf("%.2f",total_price)+'\n')) {
		//$("#id_divorderbody").fadeOut("slow", null);
		$("#temporary-page").hide();
		prodstr = prodstr.substr(0,prodstr.length-1);
		strq += '&user_id='+escape(user_id)+'&sess_id='+escape(sess_id)+'&sess_key='+escape(sess_key)+'&product='+escape(prodstr);			
		ajax_query_post_xml('apps/register.php', strq, null, function(qxml, qcde){
                  if (qxml.hasChildNodes){
                        var qxml1 = qxml.childNodes[0];
                        qxml1 = qxml1.nextSibling ? qxml1.nextSibling : qxml1;																	
                        var tname = qxml1.childNodes[0].tagName;
                        var ttext = qxml1.childNodes[0].textContent || qxml1.childNodes[0].text;
                        if (tname == 'qstatus' && ttext == 'ok') {
                        	if (str_q && str_q.indexOf("add=yes") == -1)
                        		$("#id_divbody2").fadeIn("slow", null);
                        	else
                        		$("#id_divbody2_addorder").fadeIn("slow", null);
                        }
                        else if (tname == 'qstatus' && ttext == 'error') {
                        	$("#id_oops").fadeIn("slow", null);
                        }
                  }
               });		
	} else {
		return false
	}
//	return true;
	
}


function copy_billing() {
	document.getElementById('id_street2').value = document.getElementById('id_street').value;
	document.getElementById('id_city2').value = document.getElementById('id_city').value;	
	document.getElementById('id_state2').value = document.getElementById('id_state').value;
	document.getElementById('id_zip2').value = document.getElementById('id_zip').value;
}

function post_products(retxml, retcode, stropt) {
//	htmlstr = "<th align=\"center\" colspan=\"2\">PLACE AN ORDER</th><tr><td>&nbsp;</td></tr>";
	var dtablebody = document.getElementById("id_tablebody");
	$("#id_divorderbody").find("table").each(function(i){
		$(this).empty();
	}); 
	var dtbody = document.createElement("tbody");
	var dthead = document.createElement("thead");
	dtablebody.appendChild(dthead);
	dtablebody.appendChild(dtbody);
	var dtr = document.createElement("tr");
	var dth = document.createElement("th");
	var dtd = document.createElement("td");
	dtd.setAttribute("align", "center");
	dth.setAttribute("align", "center");
	dth.setAttribute("colspan", "2");
	dth.appendChild(document.createTextNode("PLACE AN ORDER"));
	dtr.appendChild(dth);
	dthead.appendChild(dtr);
	var trspcr = document.createElement("tr");
	var tdspcr = document.createElement("td");
	tdspcr.innerHTML = "&nbsp;";
	trspcr.appendChild(tdspcr);
	dtbody.appendChild(trspcr);
	dtbody.appendChild(trspcr);
	if (retxml.hasChildNodes) {
		var xmlbase = retxml.childNodes[0];
		xmlbase = xmlbase.nextSibling ? xmlbase.nextSibling : xmlbase;
		var ilen = xmlbase.childNodes.length;
	//ibalit sa dati
		if (!ilen) {
		//	htmlstr += "<tr><td align=\"center\"><em>No Products Available As of Moment.</em></td></tr>";
		//	htmlstr += "<tr><td>&nbsp;</td></tr>";
		//	htmlstr += "<tr><td align=\"center\"><input type=\"button\" onclick=\"window.location='main.php'\" value=\"Continue\"></td></tr>";
		//	document.getElementById('id_tablebody').innerHTML = htmlstr;
			var tr = document.createElement("tr");
			var td = document.createElement("td");
			var val = document.createElement("em");
			val.appendChild(document.createTextNode("No Products Available As of Moment."));
			td.setAttribute("align", "center");
			td.appendChild(val);
			tr.appendChild(td);
			dtbody.appendChild(tr);
			dtbody.appendChild(trspcr);
			tr = document.createElement("tr");
			td = document.createElement("td");
			td.setAttribute("align", "center");
			var inp = document.createElement("input");
			inp.setAttribute("type", "button");
			inp.setAttribute("value", "Continue");
			if (inp.addEventListener)
				inp.addEventListener("click", function(){clr_order_overlay();}, false);
			else
				inp.attachEvent("onclick", function(){clr_order_overlay();});
			td.appendChild(inp);
			tr.appendChild(td);
			dtbody.appendChild(tr);
			$("#id_divorderbody").fadeIn("slow", null);
			return false;
		}
	//	htmlstr += '<tr>';
	//	htmlstr += '<td align="center"><table>';
	//	htmlstr += '<tr><td class="highlight">Select</td><td class="highlight">Product Name</td><td class="highlight">Price</td><td class="highlight">Description</td></tr>';
		dtr = document.createElement("tr");
		dtablebody2 = document.createElement("table");
		dtd.appendChild(dtablebody2);
		dtr.appendChild(dtd);
		dtbody.appendChild(dtr);
		dthead = document.createElement("thead");
		dtbody = document.createElement("tbody");
		dtablebody2.appendChild(dthead);
		dtablebody2.appendChild(dtbody);
		dtr = document.createElement("tr");
		dth = document.createElement("th");
		dth.className = "highlight";
		dth.innerHTML = "Quantity";
		dtr.appendChild(dth);
		var dth = document.createElement("th");
		dth.className = "highlight";
		dth.innerHTML = "Product Name";
		dtr.appendChild(dth);
		var dth = document.createElement("th");
		dth.className = "highlight";
		dth.innerHTML = "Price";
		dtr.appendChild(dth);
		var dth = document.createElement("th");
		dth.className = "highlight";
		dth.innerHTML = "Description";
		dtr.appendChild(dth);
		dthead.appendChild(dtr);
		for (var i = 0; i < ilen; i ++) {
			var xmlbase2 = xmlbase.childNodes[i];
			var prodid = '';
		//	htmlstr += '<tr>';
			tr = document.createElement("tr");
			dtbody.appendChild(tr);
			for (var ii = 0; ii < xmlbase2.childNodes.length; ii ++) {
				var htmlstr = '';
				td = document.createElement("td");
				tr.appendChild(td);
				(i % 2 == 0) && (td.className = "tableAltOne");
				(i % 2 != 0) && (td.className = "tableAltTwo");
				var tname = xmlbase2.childNodes[ii].tagName;
				var ttext = xmlbase2.childNodes[ii].textContent || xmlbase2.childNodes[ii].text;
			//	alert(tname+" = "+ttext);
				if (tname == 'ident') {
					htmlstr += '<input type="text" maxlength="4" size="4" name="prodid_'+ttext+'" value="0" />';
					prodid = ttext;
			 	}else if (tname == 'name') {
					td.setAttribute("id", "prodname_"+prodid);
					htmlstr += ttext;
				}else if (tname == 'price') {
					td.setAttribute("id", "prodprice_"+prodid);
					htmlstr += ttext;
				}else if (tname == 'description') {
					td.setAttribute("id", "proddesc_"+prodid);
					htmlstr += ttext;
				}
			//	htmlstr += '</td>';
				td.innerHTML = htmlstr;
			}
		//	htmlstr += '</tr>';
		}
		tr = document.createElement("tr");
		td = document.createElement("td");
		td.setAttribute("colspan", "4");
		td.innerHTML = "&nbsp;";
		tr.appendChild(td);
		dtbody.appendChild(tr);
		tr = document.createElement("tr");
		dtbody.appendChild(tr);
		td = document.createElement("td");
		td.setAttribute("colspan", "2");
		td.setAttribute("align", "right");
		td.innerHTML = "<input type=\"button\" value=\"Later\" onclick=\"proceed_registration_nobill('"+stropt+"');\" />";
		tr.appendChild(td);
		td = document.createElement("td");
		td.setAttribute("colspan", "2");
		td.setAttribute("align", "left");
		td.innerHTML = "<input type=\"button\" value=\"Submit\" onclick=\"proceed_registration('"+stropt+"');\" />";
		tr.appendChild(td);
	//	htmlstr += '<tr><td colspan="4">&nbsp;</td></tr>';
	//	htmlstr += '<tr><td colspan="2" align="center"><input type="button" value="Later" onclick="proceed_registration_nobill();" /></td><td colspan="2" align="center"><input type="button" value="Bill Me" onclick="proceed_registration();" /></td></tr>';
	//	htmlstr += '</table></td>';
	//	htmlstr += '</tr>';
	//	document.getElementById('id_tablebody').innerHTML = htmlstr;
		$("#id_divorderbody").css({"width":"430px","margin-left":"-100px"});
		$("th").css({"font-size":"10px","font-weight":"bolder"});
		$("#id_divorderbody").fadeIn("slow", null);
		return true;
	}	
	

}

function do_register() {
	var username = document.getElementById('id_username').value || '';
	var password = document.getElementById('id_password').value || '';
	var password2 = document.getElementById('id_repassword').value || '';
	var companyname = document.getElementById('id_companyname').value || '';
	var phone = document.getElementById('id_phone').value || '';
	var phone2 = document.getElementById('id_phone2').value || '';
	var fax = document.getElementById('id_fax').value || '';
	var email = document.getElementById('id_email').value || '';
	var firstname = document.getElementById('id_firstname').value || '';
	var lastname = document.getElementById('id_lastname').value || '';
	var firstname2 = document.getElementById('id_firstname2').value || '';
	var lastname2 = document.getElementById('id_lastname2').value || '';
	var street = document.getElementById('id_street').value || '';
	var city = document.getElementById('id_city').value || '';
	var state = document.getElementById('id_state').value || '';
	var zip = document.getElementById('id_zip').value || '';
	var street2 = document.getElementById('id_street2').value || '';
	var city2 = document.getElementById('id_city2').value || '';
	var state2 = document.getElementById('id_state2').value || '';
	var zip2 = document.getElementById('id_zip2').value || '';
	var fcolor = '#E2DFE3';
	username = trim(username);
	password = trim(password);
	password2 = trim(password2);
	companyname = trim(companyname);
	phone = trim(phone);
	phone2 = trim(phone2);
	fax = trim(fax);
	email = trim(email);
	firstname = trim(firstname);
	lastname = trim(lastname);
	firstname2 = trim(firstname2);
	lastname2 = trim(lastname2);
	street = trim(street);
	city = trim(city);
	state = trim(state);
	zip = trim(zip);
	street2 = trim(street2);
	city2 = trim(city2);
	state2 = trim(state2);
	zip2 = trim(zip2);
//	toggle_div(1);
	if (username.length == 0 || password.length == 0 || password2.length == 0 || companyname.length == 0 || phone.length == 0 ||
		email.length == 0 || firstname.length == 0 || lastname.length == 0 || street.length == 0 || city.length == 0 || 
		state.length == 0 || zip.length == 0) {
		document.getElementById('registerMsg').innerHTML = "Missing values for required(*) fields.";
		
		if (zip.length == 0) {
			document.getElementById('id_zip').style.backgroundColor = fcolor;
//			document.getElementById('id_zip').focus();
		}
		if (state.length == 0) {
			document.getElementById('id_state').style.backgroundColor = fcolor;
//			document.getElementById('id_state').focus();
		}
		if (city.length == 0) {
			document.getElementById('id_city').style.backgroundColor = fcolor;
//			document.getElementById('id_city').focus();
		}
		if (street.length == 0) {
			document.getElementById('id_street').style.backgroundColor = fcolor;
//			document.getElementById('id_street').focus();
		}
		if (lastname.length == 0) {
			document.getElementById('id_lastname').style.backgroundColor = fcolor;
//			document.getElementById('id_lastname').focus();
		}
		if (firstname.length == 0) {
			document.getElementById('id_firstname').style.backgroundColor = fcolor;
//			document.getElementById('id_firstname').focus();
		}
		if (email.length == 0) {
			document.getElementById('id_email').style.backgroundColor = fcolor;
//			document.getElementById('id_email').focus();
		}
		if (phone.length == 0) {
			document.getElementById('id_phone').style.backgroundColor = fcolor;
//			document.getElementById('id_phone').focus();
		}
		if (!document.getElementById('id_category').value) {
			document.getElementById('id_category').style.backgroundColor = fcolor;
//			document.getElementById('id_category').focus();
		}
		if (companyname.length == 0) {
			document.getElementById('id_companyname').style.backgroundColor = fcolor;
//			document.getElementById('id_companyname').focus();
		}
		if (password2.length == 0) {
			document.getElementById('id_repassword').style.backgroundColor = fcolor;
//			document.getElementById('id_repassword').focus();
		}
		if (password.length == 0) {
			document.getElementById('id_password').style.backgroundColor = fcolor;
//			document.getElementById('id_password').focus();
		}
		if (username.length == 0) {
			document.getElementById('id_username').style.backgroundColor = fcolor;
//			document.getElementById('id_username').focus();
		}
		return false;
	}
	if (password2 != password) {
		document.getElementById('registerMsg').innerHTML = "Passwords did not match.";
		document.getElementById('id_repassword').style.backgroundColor = fcolor;
		return false;
	}
	if (username.match(/[^a-zA-Z0-9_]/)) {
		document.getElementById('registerMsg').innerHTML = "Ivalid characters found in username.";
		document.getElementById('id_username').style.backgroundColor = fcolor;
//		document.getElementById('id_username').focus();
		return false;
	}
	if (!email.match(/^[a-zA-Z0-9_.\-+]+@[a-zA-Z0-9_.\-]+\.[a-zA-Z0-9]{2,4}$/i)) {
		document.getElementById('registerMsg').innerHTML = "Invalid Email Address.";
		document.getElementById('id_email').style.backgroundColor = fcolor;
//		document.getElementById('id_email').focus();
		return false;
	}
	$("#id_divoverlay").fadeIn("slow");
	var qstr = '';
	qstr = 'addme=yes&username='+escape(username)+'&password='+escape(SHA1(password))+'&passwordplain='+escape(password)+'&companyname='+escape(companyname)+'&category='+escape(document.getElementById('id_category').value);
	qstr += '&phone='+escape(phone)+'&phone2='+escape(phone2)+'&fax='+escape(fax)+'&email='+escape(email)+'&firstname='+escape(firstname)+'&lastname='+escape(lastname);
	qstr += '&firstname2='+escape(firstname2)+'&lastname2='+escape(lastname2)+'&street='+escape(street)+'&city='+escape(city)+'&state='+escape(state);
	qstr += '&zip='+escape(zip)+'&street2='+escape(street2)+'&city2='+escape(city2)+'&state2='+escape(state2)+'&zip2='+escape(zip2);
	ajax_query_post_xml("apps/register.php", qstr, null, function(retq, retc){
        	if (retq.hasChildNodes) {
        			var xml1 = retq.childNodes[0];
        			xml1 = xml1.nextSibling ? xml1.nextSibling : xml1;
        			var ilen = xml1.childNodes.length;
        			document.cookie = 'user_id='+escape(username)+';path=/';	
        			for (var i = 0; i < ilen; i ++) {
        				var tname = xml1.childNodes[i].tagName;
        				var ttext = xml1.childNodes[i].textContent ? xml1.childNodes[i].textContent : xml1.childNodes[i].text;
        				if (tname == 'sessid') {
        					document.cookie = 'sess_id='+escape(ttext)+';path=/';	
        				}
        				if (tname == 'sesskey') {
        					document.cookie = 'sess_key='+escape(ttext)+';path=/';	
                                                if (confirm("Your account has been created.\nDo you want to request order now?"))
											ajax_query_get_xml("apps/register.php?getcat=11", null, displayOrder);
        					  //ajax_query_get_xml("apps/register.php?getcat=11", null, function(ObjXml,StrStat){post_products(ObjXml,StrStat,'');});
										
                                                else
                                                  window.location='main.php';
        				}
        				if (tname == 'user' && ttext == 'duplicate') {
        					$("#registerMsg").html("Username Already Exists.");
        					$("#id_divoverlay").fadeOut("slow");
        				}
        			}
        	}
        });
	return true;
}

/** continuation of meetings **/

	function showDefaultMeetings() {
		var m = tempHolder.split('|');
		var keys = m[0].split(' ');
		for (var i = 0; i < keys.length; i++)
			alert(keys[i]);
	}
