// JavaScript Document WebyPlus wyWhatsapp

wyWhatsapp = function(){
	//contenedor = document.body.insertBefore(newDiv, currentDiv);
	var $bWhatsapp = document.createElement( 'div' );
		$bWhatsapp.style.position = 'fixed';
		$bWhatsapp.style.display = 'inline-block';
		$bWhatsapp.style.bottom = '25px';
		$bWhatsapp.style.right = '15px';
		$bWhatsapp.style.padding = '8px';
		$bWhatsapp.style.color = '#ffffff';
		$bWhatsapp.style.fontSize = '36px';
		$bWhatsapp.style.backgroundColor = '#22c15e';
		$bWhatsapp.style.borderTopLeftRadius = '50%';
		$bWhatsapp.style.borderTopRightRadius = '50%';
		$bWhatsapp.style.borderBottomLeftRadius = '50%';
		$bWhatsapp.style.borderBottomRightRadius = '50%';
		$bWhatsapp.style.width = '54px';
		$bWhatsapp.style.height = '54px';
		$bWhatsapp.style.cursor = 'pointer';
		$bWhatsapp.style.zIndex = '900';
		$bWhatsapp.setAttribute( 'id', 'bWSChat' );
		$bWhatsapp.align = 'center';
		$bWhatsapp.innerHTML = '<i class="fa fa-whatsapp"></i>';
		
		if( ws_script.tbws == 1 ) 
		{
			$bWhatsapp.style.fontSize = '18px';
			$bWhatsapp.style.padding = '10px';
			$bWhatsapp.innerHTML = 'Hola! ¿Tienes alguna consulta? <i class="fa fa-whatsapp" style="font-size:18px;"></i>';
			$bWhatsapp.style.borderTopLeftRadius = '10px';
			$bWhatsapp.style.borderTopRightRadius = '10px';
			$bWhatsapp.style.borderBottomLeftRadius = '10px';
			$bWhatsapp.style.borderBottomRightRadius = '10px';
			$bWhatsapp.style.width = 'auto';
			$bWhatsapp.style.height = 'auto';
			$bWhatsapp.style.fontSize = 'medium';
		}
		
		$bWhatsapp.onclick = function(){
											wyClickWhatsapp();;
										}
		
		document.body.appendChild( $bWhatsapp );
}

/*var abrirWS = document.querySelector('#bWSChat');
	abrirWS.onclick = function(){
		wyClickWhatsapp();
	}*/

wyClickWhatsapp = function(){
		if ( isMobile() ) {
			window.open('https://api.whatsapp.com/send?phone=' + ws_script.tel + '&text=' + ws_script.text );
		} else {
			window.open('https://web.whatsapp.com/send?phone=' + ws_script.tel + '&text=' + ws_script.text );
		}	
}


function isMobile(){
    return (
        (navigator.userAgent.match(/Android/i)) ||
        (navigator.userAgent.match(/webOS/i)) ||
        (navigator.userAgent.match(/iPhone/i)) ||
        (navigator.userAgent.match(/iPod/i)) ||
        (navigator.userAgent.match(/iPad/i)) ||
        (navigator.userAgent.match(/BlackBerry/i))
    );
}