var div;//color type
var imprint;
//var form_id = "";

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

function swapClass(){ //v1.4 by PVII
 var i,x,tB,j=0,tA=new Array(),arg=swapClass.arguments;
 if(document.getElementsByTagName){
	 for(i=4;i<arg.length;i++){
		 tB=document.getElementsByTagName(arg[i]);
  		 for(x=0;x<tB.length;x++){
			 tA[j]=tB[x];
			 j++;
		 }
	 }
	 for(i=0;i<tA.length;i++){
  		if(tA[i].className){
			if(tA[i].id==arg[1]){
				if(arg[0]==1){
  					tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];
				} else {
					tA[i].className=arg[2];
				}
  			}else if(arg[0]==1 && arg[1]=='none') {
				if(tA[i].className==arg[2] || tA[i].className==arg[3]){
  					tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];
				}
  			}else if(tA[i].className==arg[2]){
				tA[i].className=arg[3];
			}
		}
	}
}
}

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

function P7_TMenu(b,og) { //v2.5 by Project Seven Development(PVII)
 var i,s,c,k,j,tN,hh;
 if(document.getElementById){
 	if(b.parentNode && b.parentNode.childNodes){
		tN=b.parentNode.childNodes;
	}else{
		return false;
	}
 	for(i=0;i<tN.length;i++){
		if(tN[i].tagName=="DIV"){
			s=tN[i].style.display;
 			hh=(s=="block")?"none":"block";
			if(og==1){
				hh="block";
			}
			tN[i].style.display=hh;
		}
	}
}
}

function P7_TMall(a){ //v2.5 by Project Seven Development(PVII)

 var i,x,ha,s,tN;
 if(document.getElementById){
	ha=document.getElementsByTagName("A");
 	for(i=0;i<ha.length;i++){
		if(ha[i].onclick){
			ag=ha[i].onclick.toString();
				if(ag&&ag.indexOf("P7_TMenu")>-1){
					if(ha[i].parentNode && ha[i].parentNode.childNodes){
						tN=ha[i].parentNode.childNodes;
					}else{
						break;
					}for(x=0;x<tN.length;x++){
						if(tN[x].tagName=="DIV"){
							s=tN[x].style.display;
							if(a==0&&s!='block'){
								P7_TMenu(ha[i]);
							}else if(a==1&&s=='block'){
								P7_TMenu(ha[i]);
							}
							break;
						}
					}
				}
			}
		}
	}

}
////////////////////////
////////////////
////////////////////
/////////////
///////////////////////////////////////////////////////////////////////////////////////////////
function totalPrice () {
	if(!eval("document.forms[0].big_price_" + document.forms[0].bal_type.options[document.forms[0].bal_type.selectedIndex].id) && document.forms[0].pack_type_sel) {
		document.forms[0].pack_type_sel.value = 1;	
		document.forms[0].pack_type.value = 1;
	}
	var pack_type = document.forms[0].pack_type.value;
	var sizes = document.forms[0].elements['bal_type'];
	var arr_length = sizes.length;
	var quantity = document.forms[0].elements['quantity'].value;
	
	for (var i = 0; i < arr_length; i++) {
        if (sizes[i].checked == true) {
			var price = Number(sizes[i].value);
		}
    }
	if(pack_type == '1') {
		var price = Number(document.forms[0].bal_type.options[document.forms[0].bal_type.selectedIndex].value);
	} else {
		var price = Number(eval("document.forms[0].big_price_" + document.forms[0].bal_type.options[document.forms[0].bal_type.selectedIndex].id).value);
	}
	var quantity = document.forms[0].elements['quantity'].value;
	//adding a zero if required
	
	each = "each"+0;
	total_sum = "total_sum"+0;
	document.getElementById(total_sum).innerHTML = addZeroes(price*quantity);
	document.forms[0].elements['total'].value = addZeroes(price*quantity);
	if (pack_type == '1') {
		quan = document.forms[0].normal_price_quantity.value;	
	} else {
		quan = document.forms[0].big_price_quantity.value;	
	}
	if(Number(quan) > 1) {
		document.getElementById(each).innerHTML = quan + " balloons per bag <br />[$"+addZeroes(price);
	} else {
		document.getElementById(each).innerHTML = quan + " balloon only <br />[$"+addZeroes(price);	
	}
}
function addZeroes (n) {
	abss = Math.floor(n);
	//trace('abs = '+abs);
	if (abss == n) {
		fraction = "00";
	} else {
		fraction = n - abss;
		//trace('fraction = '+fraction);
		fraction = Math.round(fraction*100);
	}
	n = abss+"."+fraction;
	return n;
}
//FLASH//////////////////////////////////////////////////////////////////////////
//receive from flash
function stuff_DoFSCommand(command) {
	//document.getElementById('each').innerHTML = div;
	if(!command) {
		command = 0;
	}
	if(div) {
    	document.forms[0].elements[div].value = command;
	}
	document.forms[0].elements['color'].value = command;
	//document.getElementById('eachs').innerHTML = "command"+command;
}
//send to flash
function sendVar (arg) {
	//alert(arg);
	//alert(form_id);
	//document.stuff.SetVariable("baloonType", arg);
	document.forms[0].elements['color_type'].value = arg;
	document.forms[0].elements['color'].value = 0;
	//alert(arg);
}
//send to flash
function sendVar_c (html_color, color_name) {
	//alert("html_color::"+html_color+" color_name:: "+color_name);
	//alert("document.stuff::"+document.stuff);
    if (document.stuff) {

	    document.stuff.SetVariable("html_color", html_color);
	    document.stuff.SetVariable("color_name", color_name);
        document.forms[0].elements['color'].value = color_name;
    }
}
//function for show the color after selecting the color type

function prase (div_name) {
	//alert(div_name);
	sel_space = 'sel_space'+0;
	if (div_name) {
		div = div_name+0;
		document.getElementById(sel_space).style.display = "none";
	} else {
		document.getElementById(sel_space).style.display = "block";
		div = 0; 
	}
	
	divs = document.getElementsByTagName("div");
	for(i=0;i<divs.length;i++){
		ind = Number(divs[i].id.substr(-1));
		//alert(divs[i].id.substr(divs[i].length-1)+" "+divs[i].id);
		if(divs[i].className == "div_show") {
			divs[i].className = "div_hide";
		}
		if(divs[i].id == div) {
			if(div_name) {
				divs[i].className = "div_show";
				//divs[i].style.visibility = "visible";
			} 
		}
	}
}

//function for showing the different divs depending of balloon imprint sides
function showDivs (sides) {
	//if(!div) {
		div = (document.forms[0].elements['color_type'].value+0).toLowerCase();
		//alert(div);
	//}
	
	step4 = 'step4'+0;
	//alert(sides+" "+div);
	sides = Number(sides);
	if(sides == 4) {
		sides = imprint;
	}
	imprint = sides;
	if (sides && div) {
		/*if (sides == 3) {
			document.getElementById('step5.1').style.display = "block";
		} else {
			document.getElementById('step5.1').style.display = "none";
		}*/
		document.getElementById(step4).style.display = "block";
		//document.getElementById('step5').style.display = "block";
		price_div = div+"_"+sides;
		//alert(price_div);
		divs = document.getElementsByTagName("div");
		for(i=0;i<divs.length;i++){
			if(divs[i].className == "div_price_show") {
				//ind2 = Number(divs[i].id.substr(-3,1));
				//if (ind2 == form_id) {
				divs[i].className = "div_price_hide";
				
				//}
			}
			//alert(price_div);
			if(divs[i].id == price_div) {
				
					divs[i].className = "div_price_show";
					//divs[i].style.visibility = "visible";
				
			}
			if(sides == 3 && (divs[i].id=="file1" || divs[i].id=="design1" || divs[i].id=="text1")) {
				divs[i].className = "div_price_show";
			}
		}
	} else {
		document.getElementById(step4).style.display = "none";
		//document.getElementById('step5').style.display = "none";
	}
	div = "";
}

//davane na ime na flasha
function flash_name(ind) {
	//form_id = ind;
	obs = document.getElementsByTagName('object');
	for(i=0; i<obs.length; i++) {
		if(obs[i].id=="stuff" && i!=ind) {
			obs[i].id="";	
		} else if (i==ind) {
			obs[i].id="stuff";	
		}
	}
	embs = document.getElementsByTagName('embed');
	for(i=0; i<embs.length; i++) {
		if(embs[i].name=="stuff" && i!=ind) {
			embs[i].name="";	
		} else if (i==ind) {
			embs[i].name="stuff";	
		}
	}
}

function openBrWindow(theURL,winName,features)
{ 
	window.open(theURL,winName,features);
}

//check forms //////////////////////////////////////////////////////////////////////
function submitForm (form) {
	var arg = "";
	if (form.color.value == "0") {
		arg = "Please select a color!\n";
	}
	if (form.ink_color.value == "0") {
		arg += "Please select an ink color!\n";
	}
	if (form.imprint_type) {
	if (form.imprint_type.value == "0") {
		arg += "Please select imprint type!\n";
	} }
	if (form.production_time) {
	if (form.production_time.value == "0") {
		arg += "Please select production time!\n";
	} }
	if (form.photo.value == "0") {
		arg += "Please select photographs!\n";
	}
	if ((form.design1.value == "0") && !(form.custom_design1.value) && form.msg1.value == "") {
		arg += "Please select or upload design, or type a message!\n";
	}
	if(form.design2) {
		if ((form.design2.value == "0") && !(form.custom_design2.value) && form.msg2.value == "" && imprint == 3) {
			arg += "Please select or upload design, or type a message for the second side!\n";
		}
	}
	if (form.price.value == "0") {
		arg += "Pleace choose quantity!\n";
	}
	if (arg) {
		alert(arg);
	} else {
		form.submit();
	}
}

function submitFormPl(form) {
	var arg;
	if (form.color.value == "0" || form.color.value == "") {
		alert("Please select a color!");
		return false;
	} else {
		form.submit();
	}
}
function acc_option(form) {
	
	if (form.option.value == "0" || form.option.value == "Select Color") {
		alert("Please select a color!");
		return false;
	} else {
		form.submit();
	}
}

//PERSONALIZED BALOONS DOUBLECHECK FUNCTION ////////////////////////////////////////
function CheckSelect(r_id) {
	document.getElementsById[r_id].select = true;
}

//showDesigns:
//funkciq, koqto sledi v koe pole da se izpratqt designite ot popypa, kato gi reduva
var dField = 2;
function showDesigns() {
	dField == 2? dField -- : dField ++;
	popLink = "design.php?side=1&form_id="+0+"&side="+dField;
	openBrWindow(popLink, 'designs','scrollbars=yes,resizable=yes,width=500,height=600');
}

