<?php

function verde_logo() {

    $logo_type = verde_top('logo_type');

    switch ($logo_type) {
        case 'text_logo':
            $logo = '<a class="a-rounded" href="'.verde_top('logo_link').'" title=""><h1>' . verde_top('logo_text') . '</h1></a>';
            break;
        case 'image_logo':
            $logo = '<a href="'.verde_top('logo_link').'" title=""><img src="' . verde_top('logo_image') . '" alt="" /></a>';
            break;
        default:
            $logo = '';
    }

    return $logo;
}

function verde_content() {
    if (verde_top('module_content_intro') == 'enable') {
        $content = '<h3>'.verde_top('page_content').'</h3>';
    } else {
        $content = '';
    }
    return $content;
}

function verde_countdown() {
	if (verde_top('module_countdown') == 'enable') {
		include('language.php');
        $date = verde_top('launch_date');
        $today = date('Y-m-d h:i:s a');
        if (strtotime($date) > strtotime($today)){

        $content = '<div class="timer">
		<script type="text/javascript">
		var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
		function countdown(yr,m,d,h,i,s){
		theyear=yr;themonth=m;theday=d;thehour=h;themin=i;thesec=s
		var today=new Date()
		var todayy=today.getYear()
		if (todayy < 1000)
		todayy+=1900
		var todaym=today.getMonth()
		var todayd=today.getDate()
		var todayh=today.getHours()
		var todaymin=today.getMinutes()
		var todaysec=today.getSeconds()
		var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
		futurestring=montharray[m-1]+" "+d+", "+yr+" "+h+":"+i+":"+s
		dd=Date.parse(futurestring)-Date.parse(todaystring)
		dday=Math.floor(dd/(60*60*1000*24)*1)
		dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
		dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
		dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
		if((dday<=0)&&(dhour<=0)&&(dmin<=0)&&(dsec<=0)){';
        if (verde_top('date_ended') == 'text') {
        	$content.='$(\'.timer\').text(\''.verde_top('date_text').'\');';	
	    } else{
	    	$content.='$(\'.timer\').fadeOut();';	
	    }
		$content.= '}
		else 
		$(\'.timer\').html(\'<span class="days">\'+dday+\'</span> <span class="daysText"></span> / <span class="hours">\'+dhour+\'</span> <span class="hoursText"></span> / <span class="minutes">\'+dmin+\'</span> <span class="minutesText"></span> / <span class="seconds">\'+dsec+\' </span><span class="secondsText"></span>\');
		if ( dday == 1 ){$(\'.daysText\').text("'.$day.'"); }else{ $(\'.daysText\').text("'.$days.'"); }
		if ( dhour == 1 ){ $(\'.hoursText\').text("'.$hour.'"); }else{ $(\'.hoursText\').text("'.$hours.'"); }
		if ( dmin == 1 ){ $(\'.minutesText\').text("'.$minute.'"); }else{ $(\'.minutesText\').text("'.$minutes.'"); }
		if ( dsec == 1 ){ $(\'.secondsText\').text("'.$second.'"); }else{ $(\'.secondsText\').text("'.$seconds.'");}
		setTimeout("countdown(theyear,themonth,theday,thehour,themin,thesec)",1000);
		}
		countdown(' . date('Y', strtotime($date)) . ',' . date('m', strtotime($date)) . ',' . date('d', strtotime($date)) . ',' . date('H', strtotime($date)) . ',' . date('i', strtotime($date)) . ',' . date('s', strtotime($date)) . ')
		</script>
		    <noscript>
		        <span class="launch-date">' . date('M dS, Y') . '</span>
		    </noscript>
		</div>';

        }else{
	        if (verde_top('date_ended') == 'text') {	
		        $content = '
		        <div class="timer">
				<p>'.verde_top('date_text').'</p>
		        </div>';
	        }else{
	        	$content = '';
	        }
        }

    } else {
        $content = '';
    }
    return $content;
}

function verde_email_subscription() {
	$content = '
	<script type="text/javascript">
	$(\'.success-message\').hide();
    $(\'.error-message\').hide();

    $(\'.subscribe form\').submit(function() {
        var postdata = $(\'.subscribe form\').serialize();
        $.ajax({
            type: \'POST\',
            url: \''.verde_product_info('extend_url').'/themes/php/sendmail.php\',
            data: postdata,
            dataType: \'json\',
            success: function(json) {
                if(json.valid == 0) {
                    $(\'.success-message\').hide();
                    $(\'.error-message\').hide();
                    $(\'.error-message\').html(json.message);
                    $(\'.error-message\').fadeIn().delay(3000).fadeOut();
                }
                else {
                    $(\'.error-message\').hide();
                    $(\'.success-message\').hide();
                    $(\'.subscribe form\').hide().delay(3000).fadeIn();';
	if (verde_top('redirect_active') == 'enable'){
	$content.='
					setTimeout(function() { 
					    window.open(\''.verde_top('redirect_link').'\'); 
					 }, 2000);';
	}
    $content.='
					 $(\'.subscribe form input\').val(\'\');
                    $(\'.success-message\').html(json.message);
                    $(\'.success-message\').fadeIn().delay(2000).fadeOut();
                }
            }
        });
        return false;
    });
	</script>';
    return $content;
    
}


function verde_contact_form() {
	$content = '
	<script type="text/javascript">
	$(\'.success-message-2\').hide();
    $(\'.error-message-2\').hide();

    $(\'#contactform\').submit(function() {
        var postdata = $(\'#contactform\').serialize();
        $.ajax({
            type: \'POST\',
            url: \''.verde_product_info('extend_url').'/themes/php/contact.php\',
            data: postdata,
            dataType: \'json\',
            success: function(json) {
                if(json.valid == 0) {
                    $(\'.success-message-2\').hide();
                    $(\'.error-message-2\').hide();
                    $(\'.error-message-2\').html(json.message);
                    $(\'.error-message-2\').fadeIn().delay(3000).fadeOut();
                }
                else {
                    $(\'.error-message-2\').hide();
                    $(\'.success-message-2\').hide();
                    $(\'#contactform\').hide().delay(3000).fadeIn();';
    if (verde_top('redirect_active') == 'enable'){
	$content.='
					setTimeout(function() { 
					    window.open(\''.verde_top('redirect_link').'\'); 
					 }, 2000);';
	}
    $content.='
                    $(\'#contactform input\').val(\'\');
                    $(\'#contactform textarea\').val(\'\');
                    $(\'.success-message-2\').html(json.message);
                    $(\'.success-message-2\').fadeIn().delay(2000).fadeOut();
                }
            }
        });
        return false;
    });
	</script>';
    return $content;
    
}

function contact_captcha(){
	$longitud = 5;
	for ($i=1; $i<=$longitud; $i++) {
		$letra = chr(rand(48,57));
		$codigo .=$letra;
	}
	
	 return $codigo;
}

function verde_map() {
	$content = '
	<script type="text/javascript">
	var $map 				= $(\'#map\'),
	$address 			= \''.verde_top('direction').'\'; 

	$map.gMap({
	address: $address,
	zoom: 17,
	scrollwheel: false,
	navigationControl: false,
	mapTypeControl: false,
	scaleControl: false,
	draggable: false,
	mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	</script>';
return $content;
}