function explodeArray(item,delimiter) {
tempArray=new Array(1);
var Count=0;
var tempString=new String(item);

while (tempString.indexOf(delimiter)>0) {
tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
Count=Count+1
}

tempArray[Count]=tempString;
return tempArray;
} 


function getLocation(){
	var a = window.location.href;
	var value = a.lastIndexOf('/')+1;
	var temp = a.slice(value)
	var str = explodeArray(temp,'.');
	return str[0];
}




function openWindowChatVentas(mensaje){
    var location = getLocation();
	
    if ((screen.width<1024) && (screen.height<768)){
        window.open('http://tochat.toservers.com/init/auth/room_ventas/'+location+'/'+mensaje, '_blank', 'width=500,height=450');
    }
    else if (((screen.width>=1024) && (screen.height>=768)) && ((screen.width<=1680) && (screen.height<=1050)))
    {   
        window.open('http://tochat.toservers.com/init/auth/room_ventas/'+location+'/'+mensaje, '_blank', 'width=470,height=380');
    }
    else 
    {
        window.open('http://tochat.toservers.com/init/auth/room_ventas/'+location+'/'+mensaje, '_blank', 'width=680,height=580');
    }
    closeChatVentas();
    return false;
}

function closeChatVentas(){
    this.document.getElementById('cont_flotante').style.display="none";
}

function getPromociones(){
    var req = null;
    if(window.XMLHttpRequest)
        req = new XMLHttpRequest(); 
    else if (window.ActiveXObject)
        req  = new ActiveXObject("Microsoft.XMLHTTP");

    req.open("GET",'../includes/chat_promociones.php',true); 

    req.onreadystatechange = function(){
        if(req.readyState == 4){
            if(req.status == 200) {
	    	document.getElementById("chat_promociones").innerHTML = req.responseText;
			}
        }
    }
   req.send(''); 
}

function getChatVentas(){
    var req = null;
    if(window.XMLHttpRequest)
        req = new XMLHttpRequest(); 
    else if (window.ActiveXObject)
        req  = new ActiveXObject("Microsoft.XMLHTTP");

    req.open("GET",'../includes/chat_ventas.php',true); 

    req.onreadystatechange = function(){
        if(req.readyState == 4){
            if(req.status == 200) {
		if (parseInt(req.responseText) > 0){
			getPromociones();
   			document.getElementById('cont_flotante').style.display="inline";
	        }
	    }
        }
    }
   req.send(''); 
}
function getChatVentas_deprecated(){
	var fecha = new Date();
	var dia = fecha.getDay();
	var hora = fecha.getHours();
	if (dia > 0 && dia <6){
		if (hora > 9 && hora < 21){
			this.document.getElementById('cont_flotante').style.display="inline";
		}
	}
}

