// JavaScript Document
var $jq=jQuery.noConflict();
	
	function calculation(cache_method,ui_id)
	{
			var total = 0;
			var total_price = 0;
			var discout = 0;
			//alert (document.getElementsByName('checkbox[]').length);
			//alert(document.submiturlfrm.checkbox.length);
			//return false;
			
							
			var submission1=  document.getElementById('submission1').value;
			var discount1=  document.getElementById('discount1').value;
			
			var submission2=  document.getElementById('submission2').value;
			var discount2=  document.getElementById('discount2').value;
			
			var submission3=  document.getElementById('submission3').value;
			var discount3=  document.getElementById('discount3').value;
			
			var submission4=  document.getElementById('submission4').value;
			var discount4=  document.getElementById('discount4').value;
				
				
		 	for (i=0; i<document.getElementsByName('checkbox[]').length; i++)
			{	
				if (document.forms["submiturlfrm"]["checkbox[]"][i].checked==true)
				{
					total += 1;
					var price_id = 'price'+document.forms["submiturlfrm"]["checkbox[]"][i].value;
					
					total_price = (parseFloat(total_price) + parseFloat(document.getElementById(price_id).value)) ;
				}
				
			}
			
	
			
			if(total >= submission1)
			{
				discout = discount1 * (total_price / 100);
			}
			
			
			if(total >= submission2)
			{
				discout = discount2 * (total_price / 100);
			}
			
			
			if(total >= submission3)
			{
				discout = discount3 * (total_price / 100);
			}
			
			
			if(total >= submission4)
			{
				discout = discount4 * (total_price / 100);
			}
				
				
			
			document.getElementById('discountprice').innerHTML = 'Discount:&nbsp;$'+discout.toFixed(2);
			document.getElementById('discount').value = discout.toFixed(2);
			
			document.getElementById('subtotalprice').innerHTML = 'Sub Total:&nbsp;$'+total_price.toFixed(2);
			document.getElementById('pricecount').value = total_price.toFixed(2);
			var grand_total = total_price - discout;
			
			document.getElementById('totalpricediv').innerHTML = 'Total Price:&nbsp;$'+grand_total.toFixed(2);
			document.getElementById('totalprice').value = grand_total.toFixed(2);
			
			
			Http.get({
					url: "ajaxresponse/changeprice.php?&discount="+discout+"&tprice="+total_price+"&gprice="+grand_total,
					callback: update,
					cache: cache_method
				
			}, [ui_id]);
			
			
	}
	
	function checkDirectory(cache_method,ui_id,chkVal){
			var cvalue=chkVal;
			var chk= document.getElementById('checkbox'+cvalue).checked;
			var bclass= document.getElementById('windclass'+cvalue).value;
			var bgclass= document.getElementById('bgclass'+cvalue).value;
			document.getElementById('lavel'+cvalue).value = 0;
			
				// Price Calculation
				var total = 0;
				var total_price = 0;
				var discout = 0;
				//alert (document.getElementsByName('checkbox[]').length);
				//alert(document.submiturlfrm.checkbox.length);
				//return false;
				
								
				var submission1=  document.getElementById('submission1').value;
				var discount1=  document.getElementById('discount1').value;
				
				var submission2=  document.getElementById('submission2').value;
				var discount2=  document.getElementById('discount2').value;
				
				var submission3=  document.getElementById('submission3').value;
				var discount3=  document.getElementById('discount3').value;
				
				var submission4=  document.getElementById('submission4').value;
				var discount4=  document.getElementById('discount4').value;
				
				
				for (i=0; i<document.getElementsByName('checkbox[]').length; i++)
				{	
					if (document.forms["submiturlfrm"]["checkbox[]"][i].checked==true)
					{
						total += 1;
						var price_id = 'price'+document.forms["submiturlfrm"]["checkbox[]"][i].value;
						
						total_price = (parseFloat(total_price) + parseFloat(document.getElementById(price_id).value)) ;
					}
					
				}
				
	
				
				if(total >= submission1)
				{
					discout = discount1 * (total_price / 100);
				}
				
				
				if(total >= submission2)
				{
					discout = discount2 * (total_price / 100);
				}
				
				
				if(total >= submission3)
				{
					discout = discount3 * (total_price / 100);
				}
				
				
				if(total >= submission4)
				{
					discout = discount4 * (total_price / 100);
				}
				
				document.getElementById('discountprice').innerHTML = 'Discount:&nbsp;$'+discout.toFixed(2);
				
				document.getElementById('discount').value = discout.toFixed(2);
				
				document.getElementById('subtotalprice').innerHTML = 'Sub Total:&nbsp;$'+total_price.toFixed(2);
		
				document.getElementById('pricecount').value = total_price.toFixed(2);
				var grand_total = total_price - discout;
				
				document.getElementById('totalpricediv').innerHTML = 'Total Price:&nbsp;$'+grand_total.toFixed(2);
				document.getElementById('totalprice').value = grand_total.toFixed(2);
				
				
				
			if(chk){
				
				$jq('#dir'+cvalue).removeClass('onerow_listing '+bclass).addClass('selectedbox '+bclass);
				$jq('#catwindow'+cvalue).show('fast');
			
			
				Http.get({
					url: "ajaxresponse/checkdirectory.php?&fl=1&dirid="+chkVal+"&discount="+discout+"&tprice="+total_price+"&gprice="+grand_total,
					callback: update,
					cache: cache_method
				
					}, [ui_id]);
				
			
			}else{
			  
			   var chk = document.getElementById("catmain0"+cvalue);
			   //document.getElementById('curl'+cvalue).innerHTML='';
			 
			   if(chk){
			  		
					//document.getElementById("catmain0"+cvalue).value='';
			   }
			   
			  for(var i=4; i > 0; i--)
				{
					var divid="subcat"+i+cvalue;
					//document.getElementById(divid).innerHTML = "";	
				}
				
				
			  $jq('#dir'+cvalue).removeClass('selectedbox '+bclass).addClass('onerow_listing ');
			  $jq('#catwindow'+cvalue).hide('fast');
			  
			  Http.get({
					url: "ajaxresponse/checkdirectory.php?&fl=0&dirid="+chkVal+"&discount="+discout+"&tprice="+total_price+"&gprice="+grand_total,
					callback: update,
					cache: cache_method
				
			}, [ui_id]);
			
			}
		 
		 	//calculation(cache_method,ui_id);
	
		 }
		 
		 
	
	
	
	// Display directorys order by title or niche
function setOrder(cache_method,ui_id, fld){

	document.getElementById(ui_id).innerHTML= '<div class="onebox_div" style="padding-top:10px;"><img src="images/loading.gif" width="220" height="19" alt="" title="" /><br> Please wait...</div>';
	//var sum = 0;
	
	//document.getElementById('discount').value = sum.toFixed(2);
	//document.getElementById('pricecount').value = sum.toFixed(2);
	//document.getElementById('totalprice').value = sum.toFixed(2);
	
	if(fld == 'title'){
		var tvalue =  document.getElementById('torder').value;
		document.getElementById('titleTxt').style.color = '#FFFFFF';
		
		if(tvalue==0){
			document.getElementById('torder').value = 1;
			var url="?fldname=title&order=1";
			document.getElementById('titleImg').innerHTML='<img src="images/down.gif" width="9" height="5" alt="" title=""  />';
		}else{
			document.getElementById('torder').value = 0;
			var url="?fldname=title&order=0";
			document.getElementById('titleImg').innerHTML='<img src="images/up.gif" width="9" height="5" alt="" title=""  />';
		}
	
	}else{
		document.getElementById('titleTxt').style.color = '#333333';
		document.getElementById('titleImg').innerHTML='<img src="images/updown.gif" class="updownarrow" alt="" title=""  />';	
	}
	
	
	if(fld == 'niche'){
		var nvalue =  document.getElementById('norder').value;
		document.getElementById('nicheTxt').style.color = '#FFFFFF';
		
		if(nvalue==0){
			document.getElementById('norder').value = 1;
			var url="?fldname=niche&order=1";
			document.getElementById('nicheImg').innerHTML='<img src="images/down.gif" width="9" height="5" alt="" title=""  />';
		}else{
			document.getElementById('norder').value = 0;
			var url="?fldname=niche&order=0";
			document.getElementById('nicheImg').innerHTML='<img src="images/up.gif" width="9" height="5" alt="" title=""  />';
		}
	}else{
		document.getElementById('nicheTxt').style.color = '#333333';
		document.getElementById('nicheImg').innerHTML='<img src="images/updown.gif" class="updownarrow" alt="" title=""  />';	
	}
	
	
	
	if(fld == 'price'){
		var nvalue =  document.getElementById('priceorder').value;
		document.getElementById('priceTxt').style.color = '#FFFFFF';
		
		if(nvalue==0){
			document.getElementById('priceorder').value = 1;
			var url="?fldname=f_price&order=1";
			document.getElementById('priceImg').innerHTML='<img src="images/down.gif" width="9" height="5" alt="" title=""  />';
		}else{
			document.getElementById('priceorder').value = 0;
			var url="?fldname=f_price&order=0";
			document.getElementById('priceImg').innerHTML='<img src="images/up.gif" width="9" height="5" alt="" title=""  />';
		}
	}else{
		document.getElementById('priceTxt').style.color = '#333333';
		document.getElementById('priceImg').innerHTML='<img src="images/updown.gif" class="updownarrow" alt="" title=""  />';	
	}
	
	
	
	if(fld == 'pr'){
		var prvalue =  document.getElementById('prorder').value;
		document.getElementById('prTxt').style.color = '#FFFFFF';
		
		
		if(prvalue==0){
			document.getElementById('prorder').value = 1;
			var url="?fldname=pr&order=1";
			document.getElementById('prImg').innerHTML='<img src="images/down.gif" width="9" height="5" alt="" title=""  />';
		}else{
			document.getElementById('prorder').value = 0;
			var url="?fldname=pr&order=0";
			document.getElementById('prImg').innerHTML='<img src="images/up.gif" width="9" height="5" alt="" title=""  />';
		}
	}else{
		document.getElementById('prTxt').style.color = '#333333';
		document.getElementById('prImg').innerHTML='<img src="images/updown.gif" alt="" class="updownarrow" title=""  />';	
	}
	
	
	
	if(fld == 'ip'){
		var nvalue =  document.getElementById('iporder').value;
		document.getElementById('ipTxt').style.color = '#FFFFFF';
		
		
		if(nvalue==0){
			document.getElementById('iporder').value = 1;
			var url="?fldname=ip&order=1";
			document.getElementById('ipImg').innerHTML='<img src="images/down.gif" width="9" height="5" alt="" title=""  />';
		}else{
			document.getElementById('iporder').value = 0;
			var url="?fldname=ip&order=0";
			document.getElementById('ipImg').innerHTML='<img src="images/up.gif" width="9" height="5" alt="" title=""  />';
		}
	}else{
		document.getElementById('ipTxt').style.color = '#333333';
		document.getElementById('ipImg').innerHTML='<img src="images/updown.gif" class="updownarrow" title=""  />';	
	}
	
	

	Http.get({
	url: "ajaxresponse/directories.php"+url,
	callback: update,
	cache: cache_method

 	}, [ui_id]);
	
}




	
