// JavaScript Document
function closeAllToggleThisconf(openThisOne){
	items = document.getElementsByClassName("conf");
	for (i = 0; i < items.length; i++){
		if(items[i].offsetHeight!==0){
			new fx.Height(items[i], {duration: 400}).toggle();
			new fx.Opacity(items[i], {duration: 400}).custom(100,0);
		}
	}
		new fx.Height(openThisOne, {duration: 400}).toggle();
		new fx.Opacity(openThisOne, {duration: 400}).custom(0, 100);
}
// find x or y
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}else if (obj.y){
		curtop += obj.y;
	}
	return curtop;
}
//------------------------
function WriteLayer(ID,parentID,URL) {
	if (document.layers) {
		var oLayer;
		if(parentID){
			//oLayer = eval('document.' + parentID + '.document.' + ID + '.document');
			oLayer = 'document.' + parentID + '.document.' + ID + '.document';
		}else{
			oLayer = document.layers[ID].document;
		}
		oLayer.open();
		oLayer.write(URL);
		oLayer.close();
	}else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
		document.getElementById(ID).innerHTML = URL;
	}else if (document.all) {
		document.all[ID].innerHTML = URL;
	}
}

function valueInArray(value, array){
	for (var i=0;array.length>i;i++){
		if(array[i]==value){
			return true;
		}
	}
}

//------------------------------
function change(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function get_radio_value(targ){
	for (var i=0; i < targ.length; i++)
	{
		if (targ[i].checked)
		{
			return(targ[i].value);
		}
	}
}

function test_cont(targ, type){
	var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
	var phone = /^\+?[0-9 ()-]+[0-9]$/;
	var nmbr = /[0-9]/;
	if(type=='name' && targ.value.length<3 || type=='email' && !email.test(targ.value) || type=='phone' && !phone.test(targ.value) || type=='number' && !nmbr.test(targ.value) || type=='null' && targ.value.length<1){
		targ.className='conf_input_alert';
		error=true;
	}else{
		targ.className='conf_input';
	}
}

function a0(){
closeAllToggleThisconf("a1");
document.tpicn.src='img/icon/1.gif';
}

function a1(){
	error=false;
	test_cont(document.configform.contact_name, 'name');
	test_cont(document.configform.company, 'name');
	test_cont(document.configform.email_address, 'email');
	test_cont(document.configform.phone1, 'phone');
	test_cont(document.configform.country, 'name');
	if(error === true){
		alert('please correct the fields in yellow');
	}else{
		var url = 'info_submit.php?contact_name='+document.configform.contact_name.value+'&company='+document.configform.company.value+'&email_address='+document.configform.email_address.value+'&phone='+document.configform.phone1.value+'&country='+document.configform.country.value;
		new ajax(url, {update: $('hidden')});
		closeAllToggleThisconf("a2");
	}
}

function a2(){
	var test = ['PA6+30%GF', 'PVC-Hard', 'PET', 'TPU'];
	error=false;
	test_cont(document.configform.partweight, 'number');
	test_cont(document.configform.plastic, 'null');
	test_cont(document.configform.colorchange, 'null');
	test_cont(document.configform.nozzles, 'null');
	test_cont(document.configform.cavities, 'null');
	if(error === true){
		alert('please correct the fields marked in yellow');
	}else	if(document.configform.colorchange.value == "yes" && valueInArray(document.configform.plastic.value, test)===true){
		alert("PA6+30%GF, PVC-Hard, PET, TPU, plastic types are not compatible with color change.");
	}else{
		var url = 'nozzle.php?plastic='+document.configform.plastic.value+'&weight='+document.configform.partweight.value;
		new fx.Opacity('lb1', {duration: 400}).custom(0, 100);
		new ajax(url, {update: $('b1_cont')});
		document.tpicn.src='img/icon/2.gif';
	}
}

function b1(){
	var gate = get_radio_value(document.configform.noz_gate_type);
	if(gate=="none" || gate=="special"){
		var url = 'nozzle_info.php?g='+gate;
		new ajax(url, {update: $('b3_cont')});
		new ajax(url+'&sum=1', {update: $('e1_a_cont')});
	}else{
		var url2 = 'nozzle_length.php?plastic='+document.configform.plastic.value+'&weight='+(document.configform.partweight.value/document.configform.nozzles.value*document.configform.cavities.value);
		new fx.Opacity('lb2', {duration: 400}).custom(0, 100);
		new ajax(url2, {update: $('b2_cont')});
	}
}

function b2(){
	if(document.configform.nozzle_length.value !== "" || document.configform.nozzle_length2.value !== ""){
		var l = document.configform.nozzle_length.value;
		if(document.configform.nozzle_length2.value!==""){
			l = "S"+document.configform.nozzle_length2.value;
		}
		var url = 'nozzle_info.php?s='+document.configform.series.value+'&g='+get_radio_value(document.configform.noz_gate_type)+'&l='+l;
		new ajax(url, {update: $('b3_cont')});
		new fx.Opacity('lb3', {duration: 400}).custom(0, 100);
		new ajax(url+'&sum=1', {update: $('e1_a_cont')});
	} else {
		alert("Please select a nozzle length");
	}
}
function b3(){
	var url = 'mani.php?num='+document.configform.nozzles.value;
	new fx.Opacity('lc1', {duration: 400}).custom(0, 100);
	new ajax(url, {update: $('c1_cont')});
	document.tpicn.src='img/icon/3.gif';
}

function b3back(){
	var gate = get_radio_value(document.configform.noz_gate_type);	
	if(gate == "none" || gate == "special" ){
		closeAllToggleThisconf("b1");
	} else {
		closeAllToggleThisconf("b2");
	}
}

function c1(){
	var mantype =get_radio_value(document.configform.man_type);
 	if(mantype=="none" || mantype=="special"){
		var url = 'mani_info.php?mani='+mantype;
		new ajax (url, {update: $('c3_cont')});
		new ajax (url+'&sum=1'+mantype, {update: $('e1_b_cont')});
	}else{
		var url2 = 'mani_opt.php?mani='+mantype;
		new fx.Opacity('lc2', {duration: 400}).custom(0, 100);
		new ajax(url2, {update: $('c2_cont')});
	}
}

function c2(){
	if(document.configform.manifold_a.value.length<1){
		alert("Please enter the manifold a value");
	}else if(document.configform.manifold_b.value.length<1){
		alert("Please enter the manifold b value");
	}else if(document.configform.manifold_c.value.length<1){
		alert("Please enter the manifold c value");
	}else if(document.configform.manifold_d.value.length<1){
		alert("Please enter the manifold d value");
	}
	var a = document.configform.manifold_a.value;
	var b = document.configform.manifold_b.value;
	var c = document.configform.manifold_c.value;
	var d = document.configform.manifold_d.value;
	var e = get_radio_value(document.configform.heater_exits);
	var f = document.configform.feeder_bush.value;
	var v = document.configform.series.value;
	var mani = get_radio_value(document.configform.man_type);
	var url = 'mani_info.php?mani='+mani+'&a='+a+'&b='+b+'&c='+c+'&d='+d+'&e='+e+'&f='+f+'&v='+v;
	new fx.Opacity('lc3', {duration: 400}).custom(0, 100);
	new ajax (url, {update: $('c3_cont')});
	new ajax (url+'&sum=1', {update: $('e1_b_cont')});
}

function c3(){
	new fx.Opacity('ld1', {duration: 400}).custom(0, 100);
	new ajax ('temp.php?n='+document.configform.nozzles.value, {update: $('d1_cont')});
	document.tpicn.src='img/icon/4.gif';
}
closeAllToggleThisconf("c2");
function c3back(){
	var gate = get_radio_value(document.configform.man_type);	
	if(gate == "none" || gate == "special" ){
		closeAllToggleThisconf("c1");
		} else {
			closeAllToggleThisconf("c2");
			}
}

function d1(){
	var t = get_radio_value(document.configform.temp_type);
	if(get_radio_value(document.configform.temp_type)===null){
		alert('please select a Temperature controller');
	}
	var url = 'temp_info.php?t='+t;
	new ajax (url, {update: $('d2_cont')});
	new fx.Opacity('ld2', {duration: 400}).custom(0, 100);
	new ajax (url+'&sum=1', {update: $('e1_c_cont')});
}
function d2(){
	closeAllToggleThisconf("e1");
}
function e1(){
	document.configform.submit();
}

