// JavaScript Document
/***************************************************************************/
/*     PROGRAMMER     :                                                 */
/*     AUTHER BY      :  PHP Dev Team      								  */
/*     SCRIPT NAME    :  admin_script.js                                  */
/*     CREATED ON     :  6/OCT/2009                                       */
/*     LAST MODIFIED  :  6/OCT/2009                                       */
/*     MODIFIED BY    :      	                                           */
/*                                                                         */
/*     product options and cart brief show/hide scripts 				   */
/***************************************************************************/
function minimize()
{

	document.getElementById('max').className = 'min';
	document.getElementById('min').className = 'max';
	
}
function maximize()
{
	document.getElementById('max').className = 'max';
	document.getElementById('min').className = 'min';
	
}

function submitform(baction, action, searchby, id, option)
{
	var balloons_count = balloons.length;
	var toys_count = toys.length;
	var chocolates_count = chocolates.length;
	var vases_count = vases.length;
	var wines_count = wines.length;
var x = 0;	
var form ='';	
form +='<form action="product_do.php" method="post" enctype="application/x-www-form-urlencoded" id="pform">';
form +='<input name="action" type="hidden" value="'+action+'">';
form +='<input name="searchby" type="hidden" value="'+searchby+'">';
form +='<input name="id" type="hidden" value="'+id+'">';
form +='<input name="option" type="hidden" value="'+option+'">';

form +='<input name="product" type="hidden" value="'+document.getElementById('selectedproduct').value+'">';
form +='<input name="price" type="hidden" value="'+document.getElementById('selectedoptionid').value+'">';
form +='<input name="preference" type="hidden" value="'+document.getElementById('selectedpreference').value +'">';
for(i=0;i<balloons_count;i++) if (balloons[i]['checked']==1) { form +='<input name="special'+x+'" type="hidden" value="'+ balloons[i]['id'] +'">'; x++ ;}
for(i=0;i<toys_count;i++) if (toys[i]['checked']==1) { form +='<input name="special'+x+'" type="hidden" value="'+ toys[i]['id'] +'">'; x++ ;}
for(i=0;i<chocolates_count;i++) if (chocolates[i]['checked']==1) { form +='<input name="special'+x+'" type="hidden" value="'+ chocolates[i]['id'] +'">'; x++ ;}
for(i=0;i<vases_count;i++) if (vases[i]['checked']==1) { form +='<input name="special'+x+'" type="hidden" value="'+ vases[i]['id'] +'">'; x++ ;}
for(i=0;i<wines_count;i++) if (wines[i]['checked']==1) { form +='<input name="special'+x+'" type="hidden" value="'+ wines[i]['id'] +'">'; x++ ;}

form +='<input name="specialcount" type="hidden" value="'+ x +'">';
form +='<input name="baction" type="hidden" value="'+baction+'">';
form +='</form>';
document.getElementById('formblock').innerHTML = form;
document.getElementById('pform').submit();
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function setPreference(obj)
{
	document.getElementById('selectedpreference').value = obj.value;
}
function setOption(optId)
{
	document.getElementById('selectedoptionid').value = optId;
	document.getElementById('selectedoptionprice').value = document.getElementById('pricevalue'+optId).value;
	summarise();
}

function showSpecial(typename, typeobj, element)
{

var next = 'javascript:void(0);';
var prv = 'javascript:void(0);';

var count = typeobj.length;
if ((element+1) < count ) next = 'javascript:showSpecial(\''+typename+'\','+typename+','+ (element+1)+')';
if (element > 0 ) prv = 'javascript:showSpecial(\''+typename+'\','+typename+','+ (element-1)+')';

if (typeobj[element]['checked']==1 ) checked = 'checked="checked"'; else  checked = '';


var bodypart ='<table width="182" border="0" align="center" cellpadding="0" cellspacing="0" >';
bodypart +='<tr>';
bodypart +='	<td height="20" align="center" valign="middle" style="background-image:url(images/special_top.jpg); background-repeat:no-repeat;">';
bodypart +='		<a href="' + prv + '"><img src="images/special_up.jpg" border="0" alt=""/></a>';
bodypart +='	</td>';
bodypart +='</tr>';
bodypart +='<tr>';
bodypart +='	<td height="160" align="center" valign="middle" style="border-left:#D25267 1px solid; border-right:#D25267 1px solid;">';
bodypart +='		<a href="' + typeobj[element]['image'] + '" class="highslide" onclick="return hs.expand(this)"><img src="' + typeobj[element]['image'] + '" border="0"   alt="" /></a>';
bodypart +='	</td>';
bodypart +='</tr>';
bodypart +='<tr>';
bodypart +='	<td class="text02"  align="center" valign="top" style="border-left:#D25267 1px solid; border-right:#D25267 1px solid;">';
bodypart +='		<input onClick="javascript:addspecial('+typename+','+ element +')" name="radiobutton" id="'+typename+'_'+element+'" type="radio" value="radiobutton" ' + checked + ' />';
bodypart +='		<small>'+ typeobj[element]['title'] +'  - $' + typeobj[element]['price'] + '</small>';
bodypart +='	</td>';
bodypart +='</tr>';
bodypart +='<tr>';
bodypart +='	<td height="20" align="center" valign="middle"  style="background-image:url(images/special_bottom.jpg); background-repeat:no-repeat;" >';
bodypart +='		<a href="' + next + '"><img src="images/special_down.jpg" border="0"  alt=""/></a>';
bodypart +='	</td>';
bodypart +='</tr>';
bodypart +='</table>';


document.getElementById('specials').innerHTML = bodypart;
//document.getElementById('ss').value = bodypart;
 // toggle link images
 
if (document.getElementById('im_choco')) document.getElementById('im_choco').src = 'images/chocolates.jpg';
if (document.getElementById('im_toys')) document.getElementById('im_toys').src = 'images/toys.jpg';
if (document.getElementById('im_balloons')) document.getElementById('im_balloons').src = 'images/balloons.jpg';	
if (document.getElementById('im_vases'))document.getElementById('im_vases').src = 'images/vases.jpg';	
if (document.getElementById('im_champagne'))document.getElementById('im_champagne').src = 'images/champagne.jpg';
	 
switch (typename)
{	
	case 'chocolates': document.getElementById('im_choco').src = 'images/chocolates-h.jpg'; break;	
	case 'balloons': document.getElementById('im_balloons').src = 'images/balloons-h.jpg'; break;	
	case 'toys':  document.getElementById('im_toys').src = 'images/toys-h.jpg'; break;	
	case 'wines':  document.getElementById('im_champagne').src = 'images/champagne-h.jpg'; break;	
	case 'vases':  document.getElementById('im_vases').src = 'images/vases-h.jpg'; break;	
}

}
function addspecial(typeobj, element)
{
	typeobj[element]['checked']=1 ;
	summarise();
}

function removespecial(typename, typeobj, element)
{
	radObj = document.getElementById(typename + '_' + element);
	if (radObj) radObj.checked = false;
	typeobj[element]['checked']=0 ;
	summarise();
}

function summarise()
{
	var selected ="";
	var special_total = 0.0;
	var balloons_count = balloons.length;
	var toys_count = toys.length;
	var chocolates_count = chocolates.length;
	var vases_count = vases.length;
	var wines_count = wines.length;
	for(i=0;i<balloons_count;i++) if (balloons[i]['checked']==1) 
	{
		selected += '<img src="images/front_bullet4.jpg" width="10" height="12" />&nbsp;' + balloons[i]['title']+'&nbsp;<img src="images/front_bullet3.jpg" width="10" height="12" onClick="javascript:removespecial(\'balloons\',balloons,'+ i +')"/><br>';
		special_total = special_total  + parseFloat(balloons[i]['price']) ;
	}	
	for(i=0;i<toys_count;i++) if (toys[i]['checked']==1) 
	{
		selected += '<img src="images/front_bullet4.jpg" width="10" height="12" />&nbsp;' + toys[i]['title']+'&nbsp;<img src="images/front_bullet3.jpg" width="10" height="12"  onClick="javascript:removespecial(\'toys\',toys,'+ i +')"/><br>'	;
		special_total = special_total  + parseFloat(toys[i]['price']) ;
	}	
	for(i=0;i<chocolates_count;i++) if (chocolates[i]['checked']==1) 
	{
		selected += '<img src="images/front_bullet4.jpg" width="10" height="12" />&nbsp;' + chocolates[i]['title']+'&nbsp;<img src="images/front_bullet3.jpg" width="10" height="12"  onClick="javascript:removespecial(\'chocolates\', chocolates,'+ i +')"/><br>';
		special_total = special_total  + parseFloat(chocolates[i]['price']) ;
	}	
	for(i=0;i<vases_count;i++) if (vases[i]['checked']==1) 
	{
		selected += '<img src="images/front_bullet4.jpg" width="10" height="12" />&nbsp;' + vases[i]['title']+'&nbsp;<img src="images/front_bullet3.jpg" width="10" height="12"  onClick="javascript:removespecial(\'vases\', vases,'+ i +')"/><br>';	
		special_total = special_total  + parseFloat(vases[i]['price']) ;
	}	
	for(i=0;i<wines_count;i++) if (wines[i]['checked']==1) 
	{
		selected += '<img src="images/front_bullet4.jpg" width="10" height="12" />&nbsp;' + wines[i]['title']+'&nbsp;<img src="images/front_bullet3.jpg" width="10" height="12"  onClick="javascript:removespecial(\'wines\', wines,'+ i +')" /><br>';	
		special_total = special_total  + parseFloat(wines[i]['price']) ;
	}	
	if (document.getElementById('special_sum')) document.getElementById('special_sum').innerHTML = "Total : $ "+ special_total.toFixed(2);
	if (selected.length ==0 )selected ='&nbsp;No Specials';
	if (document.getElementById('special_selected')) document.getElementById('special_selected').innerHTML = '<small>' + selected + '</small>';
	//document.getElementById('orderTotal').innerHTML = '$' + roundNumber((parseFloat(document.getElementById('selectedoptionprice').value) + special_total),2);
	var oTotal = parseFloat(document.getElementById('selectedoptionprice').value) + special_total;
	document.getElementById('orderTotal').innerHTML = '$' + oTotal.toFixed(2);	
}
