/*29 10 2007 Todor*/

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+"  "+color_name);
    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();
	}
}

///////////////////////
// todor 23 april 2008, Chek Form1 
///////////////////////
//check forms //////////////////////////////////////////////////////////////////////
function checkForm1(iSelectedSubCat) {
	var oF = document.getElementById('MyForm');
    var sMesErr = ""
	if(oF) {
		var o = document.getElementById('fSubCat_id')
		if(o) 	o.value = iSelectedSubCat
		
		var sSelectedColor = ""
		var o =  document.getElementById('fBallonsColors_'+iSelectedSubCat)
        if(o) {
			if(o.selectedIndex<=0) sMesErr = "Please select a color!\n";
			else{
				sS = o.options[o.selectedIndex].value
				aW = sS.split("::")
                sSelectedColor = aW[0]
			}
		}
		else{
			sMesErr += "er:1\n";
		}

		var fl=false
		for(i=1;i<5;i++){
			var o =  document.getElementById('fInkColors_'+iSelectedSubCat+"_"+i)
			if(o) {
				if(o.selectedIndex<=0) sMesErr += "Please select an ink color [" + i + "]!\n";
				fl=true
			}
		}
		if(!fl) {sMesErr += "er:2\n";}

		
		var fl1,fl2
			fl1 = fl2 = false
		fl=false
			
		var o =  document.getElementById('sel_1_'+iSelectedSubCat+"_"+sSelectedColor)
		if(o) {
			if(o.selectedIndex>0) fl1=true
			fl=true
		}
		var o =  document.getElementById('sel_2_'+iSelectedSubCat+"_"+sSelectedColor)
		if(o) {
			if(o.selectedIndex>0) fl2=true
			fl=true	
		}

		if(!fl1 && !fl2) sMesErr += "Please select imprint type!\n";
		if(!fl) sMesErr += "er:3\n";

		if (sMesErr) {
			alert(sMesErr);
		} else {
			oF.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');
}



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


function ChangePricesDivs(sObjNameS,iCatID) {
	var o,OldColorType
		OldColorType=""
	//alert(val);
	//this.options[this.options.selectedIndex].id, this.options[this.options.selectedIndex].value, this.parentNode.name
	var oS = document.getElementById(sObjNameS)
	if(!oS) return 
	oS_opt= oS.options[oS.options.selectedIndex]
	sT = oS_opt.value
    aT = 	sT.split("::")// aT[0] - color type, aT[1] - color id,aT[2] - color name
	
	o = document.getElementById('color_type_'+iCatID)
	if(o) {
		OldColorType = o.value
		o.value = aT[0]
	}
	o = document.getElementById('color_id_'+iCatID)
	if(o) o.value = aT[1]

	o = document.getElementById('color_name_'+iCatID)
	if(o) o.value = aT[2]

//	o = 	document.getElementById('div_'+OldColorType)
	if(OldColorType==-1) OldColorType=""
	NewColorType = aT[0];if(NewColorType==-1) NewColorType=""
	if(OldColorType!=NewColorType){ 
			
	  //  swapDiv('div_1_'+iCatID+'_'+OldColorType)
	    setClassName('div_1_'+iCatID+'_'+OldColorType,"hid_div")
	    swapDiv('div_1_'+iCatID+'_'+NewColorType)
		os= document.getElementById('sel_1_'+iCatID+'_'+NewColorType)
		if(os) os.selectedIndex=0

	    //swapDiv('div_2_'+iCatID+'_'+OldColorType)
	    setClassName('div_2_'+iCatID+'_'+OldColorType,"hid_div")
	    swapDiv('div_2_'+iCatID+'_'+NewColorType)
		os= document.getElementById('sel_2_'+iCatID+'_'+NewColorType)
		if(os) os.selectedIndex=0
	}
}
function hideQ(sObjName){
	var o = 	document.getElementById(sObjName)
	if(o)	o.className = "hid_div";
}

function setClassName(sObjName,sClassName){
	var o = 	document.getElementById(sObjName)
	if(o)	o.className = sClassName
}

function swapDiv(sObjName){
	var o = 	document.getElementById(sObjName)
	if(o){
		o.className = (o.className =="hid_div")?"sh_div":"hid_div";
	}
}

    function popUp(url, w, h) {
    var windowprops = "width=" + w + ",height=" + h + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,top=0,left=0";
    imgwin = window.open(url,'remote',windowprops);
    }

function calc1(sVal1,sProdID,weight){
	weight = parseFloat(weight)
//	alert(sVal1+','+sProdID+','+weight)

	Sum1 = 0; pr1=0; pr2=0;

	aW  = sVal1.split(":")
	pr1 = parseFloat(aW[0])
	pr2 = parseFloat(aW[1])
	var o = document.getElementById('fShippSum_'+sProdID)
	var o1 = document.getElementById('fShippSumH_'+sProdID)

	if (weight <= 1) {
		Sum1 = pr1
	}
	else{
		iOver = parseInt(weight-1)
        if(iOver<weight-1) iOver +=1;
		Sum1 =pr1 + iOver*pr2
	}

	if(o) o.value= addZeroes(Sum1)
	if(o1) o1.value= addZeroes(Sum1)

}


function calculateSh(){
		var oF=document.getElementById('oCartForm')
		if(oF){
			//fShippSumH_
			var s = 0;
			for(i=0;i<oF.elements.length;i++) {
					o1 = oF.elements[i]
					if(o1.type=="hidden"){
						if(o1.name.split('_')[0]== 'fShippSumH') s = s +parseFloat(o1.value)
					}
			}

			var o=document.getElementById('oTota')
			var o1=document.getElementById('oSTota')
			if(o&&o1) {
				s1 = 	parseFloat(o1.innerHTML.split("$")[1])+s
				o.innerHTML="$"+addZeroes(s1)
			}

			var o=document.getElementById('oShTotal')
			if(o) o.innerHTML="$"+addZeroes(s)

			
		}
}


////////////////////////////////////////////////
function checkForm3() {
	var oF = document.getElementById('MyForm');
    var sMesErr = ""
	if(oF) {
		var o = document.getElementById('fEventDate')
        if(o) {
			if(o.value=="") sMesErr = "Please Select your Event date!\n";
		}
		else{
			sMesErr += "er:1\n";
		}

		var o = oF['fOrderedBefore'];
        if(o) {
			if(!o[0].checked && !o[1].checked) sMesErr += "Please \"Have you ordered from us before\"!\n";
		}
		else{
			sMesErr += "er:2\n";
		}

		var o = oF['fImprintBefore'];
        if(o) {
			if(!o[0].checked && !o[1].checked) sMesErr += "Please \"If yes, did you use the same artwork\"!\n";
		}
		else{
			sMesErr += "er:3\n";
		}

		
		if (sMesErr) {
			alert(sMesErr);
			return false;
		} else {
	//		oF.submit();
			return true;
		}
	}

}

