/**
 * Return ad locations HTML based on new API.
 *
 * @param $html
 * @return string   Locations HTML
 */
function quads_render_ad_locations($html)
{
    global $_quads_registered_ad_locations;
    global $quads_options;
    if (isset($_quads_registered_ad_locations) && is_array($_quads_registered_ad_locations)) {
        foreach ($_quads_registered_ad_locations as $location => $location_args) {
            $location_settings = quads_get_ad_location_settings($location);
            $html .= QUADS()->html->checkbox(array('name' => 'quads_settings[location_settings][' . $location . '][status]', 'current' => !empty($location_settings['status']) ? $location_settings['status'] : null, 'class' => 'quads-checkbox'));
            $html .= ' ' . __('Assign', 'quick-adsense-reloaded') . ' ';
            $html .= QUADS()->html->select(array('options' => quads_get_ads(), 'name' => 'quads_settings[location_settings][' . $location . '][ad]', 'selected' => !empty($location_settings['ad']) ? $location_settings['ad'] : null, 'show_option_all' => false, 'show_option_none' => false));
            $html .= ' ' . $location_args['description'] . '</br>';
        }
    }
    return $html;
}
function quads_ads_head_script()
{
    global $quads_options, $wpvcomp;
    if (isset($quads_options['quicktags']['QckTags'])) {
        ?>
	<script type="text/javascript">
		wpvcomp = <?php 
        echo $wpvcomp == 1 ? "true" : "false";
        ?>
;
		edaddID = new Array();
		edaddNm = new Array();
		if(typeof(edButtons)!='undefined') {
			edadd = edButtons.length;	
			var dynads={"all":[
				<?php 
        for ($i = 1; $i <= count(quads_get_ads()) - 1; $i++) {
            if (isset($quads_options['ad' . $i]['code']) && $quads_options['ad' . $i]['code'] != '') {
                echo '"1",';
            } else {
                echo '"0",';
            }
        }
        ?>
			"0"]};
			for(i=1;i<=<?php 
        echo count(quads_get_ads()) - 1;
        ?>
;i++) {
				if(dynads.all[i-1]=="1") {
					edButtons[edButtons.length]=new edButton("ads"+i.toString(),"Ads"+i.toString(),"\n<!--Ads"+i.toString()+"-->\n","","",-1);
					edaddID[edaddID.length] = "ads"+i.toString();
					edaddNm[edaddNm.length] = "Ads"+i.toString();
				}	
			}
			<?php 
        if (!isset($quads_options['quicktags']['QckRnds'])) {
            ?>
				edButtons[edButtons.length]=new edButton("random_ads","RndAds","\n<!--RndAds-->\n","","",-1);
				edaddID[edaddID.length] = "random_ads";
				edaddNm[edaddNm.length] = "RndAds";
			<?php 
        }
        ?>
                                edButtons[edButtons.length]=new edButton("no_ads","NoAds","\n<!--NoAds-->\n","","",-1);
				edaddID[edaddID.length] = "no_ads";
				edaddNm[edaddNm.length] = "NoAds";
			<?php 
        //if( !isset( $quads_options['quicktags']['QckOffs'] ) ){
        ?>
				//edButtons[edButtons.length]=new edButton("no_ads","NoAds","\n<!--NoAds-->\n","","",-1);
				//edaddID[edaddID.length] = "no_ads";
				//edaddNm[edaddNm.length] = "NoAds";
				//edButtons[edButtons.length]=new edButton("off_def","OffDef","\n<!--OffDef-->\n","","",-1);	
				//edaddID[edaddID.length] = "off_def";
				//edaddNm[edaddNm.length] = "OffDef";
				//edButtons[edButtons.length]=new edButton("off_wid","OffWidget","\n<!--OffWidget-->\n","","",-1);	
				//edaddID[edaddID.length] = "off_wid";
				//edaddNm[edaddNm.length] = "OffWidget";				
			<?php 
        //}
        ?>
			<?php 
        //if( !isset( $quads_options['quicktags']['QckOfPs'] ) ){
        ?>
				//edButtons[edButtons.length]=new edButton("off_bgn","OffBegin","\n<!--OffBegin-->\n","","",-1);
				//edaddID[edaddID.length] = "off_bgn";
				//edaddNm[edaddNm.length] = "OffBegin";
				//edButtons[edButtons.length]=new edButton("off_mid","OffMiddle","\n<!--OffMiddle-->\n","","",-1);
				//edaddID[edaddID.length] = "off_mid";
				//edaddNm[edaddNm.length] = "OffMiddle";
				//edButtons[edButtons.length]=new edButton("off_end","OffEnd","\n<!--OffEnd-->\n","","",-1);
				//edaddID[edaddID.length] = "off_end";
				//edaddNm[edaddNm.length] = "OffEnd";				
				//edButtons[edButtons.length]=new edButton("off_more","OffAfMore","\n<!--OffAfMore-->\n","","",-1);
				//edaddID[edaddID.length] = "off_more";
				//edaddNm[edaddNm.length] = "OffAfMore";				
				//edButtons[edButtons.length]=new edButton("off_last","OffBfLastPara","\n<!--OffBfLastPara-->\n","","",-1);
				//edaddID[edaddID.length] = "off_last";
				//edaddNm[edaddNm.length] = "OffBfLastPara";								
			<?php 
        //}
        ?>
			
		};
		(function(){
			if(typeof(edButtons)!='undefined' && typeof(jQuery)!='undefined' && wpvcomp){
				jQuery(document).ready(function(){
					for(i=0;i<edaddID.length;i++) {
						jQuery("#ed_toolbar").append('<input type="button" value="' + edaddNm[i] +'" id="' + edaddID[i] +'" class="ed_button" onclick="edInsertTag(edCanvas, ' + (edadd+i) + ');" title="' + edaddNm[i] +'" />');
					}
				});
			}
		}());	
	</script> 
	<?php 
    }
}