
function loadMsgs()
{
	new Ajax.Request('/fxC.php?action=loadChat&session_id='+session_id+'&staff='+staff+'&customer='+customer, { onSuccess: function(resp){setHistory(resp.responseText);}});	
}

function setHistory(History)
{
	document.getElementById('textbox').innerHTML+=History;
	scrollDiv();

}

minimized=false;

function displayHistoyChat(popout){
	if(popout!='true'){
		document.getElementById('chatContainer').style.display="block";
		loadMsgs();
	}
}

function chatMin(){
	document.getElementById('mainChat').style.display="none";
	document.getElementById('minButton').style.display="none";
	document.getElementById('maxButton').style.display="block";
	minimized=true;
}
function chatMax(){
	document.getElementById('mainChat').style.display="block";
	document.getElementById('minButton').style.display="block";
	document.getElementById('maxButton').style.display="none";
	document.getElementById('msg').focus();
	stopTimer();
	minimized=false;
}
function popOut(){
	document.getElementById('chatContainer').style.display="none";
	if(abc) abc.stop();
URL = '/chatC.php?session_id='+session_id+'&staff='+staff+'&id_user='+customer;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=300,left = 312,top = 234');");
}
	
var Color= new Array(9);
Color[1] = "77";
Color[2] = "77";
Color[3] = "6E";
Color[4] = "66";
Color[5] = "5E";
Color[6] = "55";
Color[7] = "4E";
Color[8] = "44";
Color[9] = "3E";
Color[10] = "33";
Color[11] = "2E";
Color[12] = "22";
Color[13] = "1E";
Color[14] = "11";
Color[15] = "0E";
Color[16] = "00";
function stopTimer(){
	repeat=false;
}
/* Do not display text on a fading background. Instead, let it
fade in and out once or twice, then load a new page.        */
function fadeIn(where) {
	if (where >= 1) {
		document.getElementById('chatHeader').style.backgroundColor="#" + Color[where] + Color[where] + "00";
		where -= 1;
		timerID=setTimeout("fadeIn("+where+")", 25);
	} else {
		timerID=setTimeout('fadeOut(1)', 25);
	}
}
function fadeOut(where) {
	if (where <=16) {
		document.getElementById('chatHeader').style.backgroundColor="#" + Color[where] + Color[where] + "00";
		where += 1;
		timerID=setTimeout("fadeOut("+where+")", 25)
	} else {
		if (repeat==true){
			timerID=setTimeout("fadeIn(16)", 500);
		}else {
			clearTimeout(timerID);
		}
	}
}


/*
function doPOST(url, params, func) 
{    
	http = createRequestObject();
	if (http)
	{
		http.onreadystatechange = func;
		http.open('POST', url, true);
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		http.send(params);
	} 
} 
*/

function trytobuy(url)
{
	new Ajax.Request('/iBizPanel/PurchaseAdd',
	{
		method:'get',
		parameters: url+'&Checkout=1',
		onLoading: function()
		{
			$('answers').innerHTML="Adding your server to your Cart...";	
		},
		onSuccess: function(resp)
		{
			/*alert(resp.responseText);/**/
			$('answers').innerHTML=resp.responseText;
			//window.location='/iBizPanel/PurchaseSignup';
		}
	});
}

function Go()
{	
	repeat=true;
    fadeIn(16);
}

//fin de lo extra

var abc;
var last;
var newm;
var session_id;
var	customer;
var	staff;


var status=0;

function getTimeStamp(){
	Stamp = new Date();
	var Hours;
	var Mins;
	var Time;
	Hours = Stamp.getHours();
	if (Hours >= 12) {
		Time = " PM";
	} else {
	Time = " AM";
	}
	if (Hours > 12) {
		Hours -= 12;
	}
	if (Hours == 0) {
		Hours = 12;
	}
	Mins = Stamp.getMinutes();
	if (Mins < 10) {
		Mins = "0" + Mins;
	}
	Seconds = Stamp.getSeconds();
	if (Seconds < 10) {
		Seconds = "0" + Seconds;
	}

	
	var timeString=Hours + ":" + Mins + ":" + Seconds + Time;
	return timeString;
}
function stampWM(){
	welcomeTime=getTimeStamp();
	document.getElementById('textbox').innerHTML = '<div class="message"><div class="msgHeader"><div class="left">'+staff+' said: </div><div class="time">'+welcomeTime+'</div></div><div class="msgBody">How may I assist you today?</div></div>';
}
	
function postmsg()
{
	if(document.getElementById('status').innerHTML!='1')
	{
		var msg=document.getElementById('msg');
		var text=msg.value;
		timeString=getTimeStamp();
		var params='msg='+text+'&session_id='+session_id+'&staff='+staff+'&customer='+customer;
		var ajax= new Ajax.Request('/fxC.php', {method: 'post', parameters:params});
		var newtext='<div class="mymessage"><div class="msgHeader"><div class="left">I said: </div><div class="time">'+timeString+'</div></div><div class="msgBody">'+msg.value+'</div></div>';
		document.getElementById('textbox').innerHTML=document.getElementById('textbox').innerHTML+newtext;
		msg.value='';
		scrollDiv();
	}
	else
	{
		document.getElementById('textbox').innerHTML=document.getElementById('textbox').innerHTML+'<font color="red">THIS CONVERSATION HAS BEEN TERMINATED</font><br/>';
		scrollDiv();
		Go();
	}
	
}

function display()
{
 if(abc) abc.stop();
 new Ajax.Request('/fxC.php?action=refresh&session_id='+session_id+'&staff='+staff+'&customer='+customer, { onSuccess: function(resp){printtext(resp.responseText);}});
}





function endconvIN(){
	answer = confirm("Do you really want to end this Conversation?")
	if (answer !=0){
 		if(abc) abc.stop();
 		new Ajax.Request('/admin/includes/chatfx.php?action=endconvIN&session_id='+session_id, { onSuccess: function(resp){closeChat();}});
	}
}
function closeChat(){
	document.getElementById('chatContainer').style.display="none";
}

/*function openChat()
{
	var oc = new Ajax.Updater('ready','admin/includes/chatfx.php?action=newconvo', {method: 'get', onSuccess: checkReady(), asynchronous: true });
}
function checkReady(){
	if (document.getElementById('ready').innerHTML=='ready'){
		document.getElementById('chatContainer').style.display='block';
	}
}*/
function openChat(lang)
{
	new Ajax.Request("/admin/includes/chatfx.php?action=newconvo&lang="+lang, {
onSuccess : function(resp) {
	//alert(resp.responseText);
		var vars= resp.responseText.split("|");
	if (vars[3]=='ready'){
	session_id= vars[0];
	staff= vars[1];
	customer=vars[2];
	
	//document.getElementById('chatContainer').style.display='block';
	//stampWM();
	popOut();
	}
},
onFailure : function(resp) {
alert("Oops, there's been an error.");
},
parameters : "name=Fred"
});
}

function CheckStatus()
{
	//alert(session_id);
	var cs = new Ajax.Request('fxC.php?action=checkstatus&session_id='+session_id, {onSuccess: function(resp) { closewindow(resp.responseText);}});
}

function closewindow(stext)
{
	if(stext=='1')
	{
		status=1;
		document.getElementById('textbox').innerHTML='<span style="color:red">THIS CONVERSATION HAS BEEN ENDED BY THE ADMINISTRATOR</span>';
		timerID=setTimeout('ocultaDivChat()', 5000);
		
	}
}
function ocultaDivChat(){
	document.getElementById('chatContainer').style.display='none';
}

function printtext(elTexto)
{	
	if(elTexto!='')	
	{	
		newm=elTexto;
		var originalText=elTexto;
		timeString=getTimeStamp();
		modifiedText=originalText.replace(/tiempo/,timeString);

		if(newm!=last)
		{
			document.getElementById('textbox').innerHTML+=modifiedText;
			scrollDiv();
			last=newm;
			if (minimized==true){
				Go();
			}
		}
	}
	abc = new  PeriodicalExecuter(display,1);
}

function checkKey(e) 
{
	if(e.keyCode == 13 && document.getElementById('msg').value!='') 
	{
		postmsg();
	}
}

function scrollDiv()
{
	var el;
	if (document.getElementById && (el = document.getElementById('textbox')) && ('undefined' != typeof el.scrollTop))
	{
		el.scrollTop = 0;
		el.scrollTop = 5000;
	}
}

function endconv()
{
	answer = confirm("Do you really want to end this Conversation?")
	if (answer !=0){
		location = "http://www.domaingurus.com/admin/includes/chatfx.php?action=endconv&session_id="+session_id;
	}
}

function refresher()
{
	abc=new PeriodicalExecuter(display, 2);
}

function openChat2(ln)
{
	day = new Date();
	id = day.getTime();
	window.open('/inc/livechat.php?ln='+ln,id,"toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=400,left = 200,top = 200");
}/**/

function changeLinks()
{
	var m = Array();
	var s= Array();
	var c=0;
	var c2=0;
	var href='';
	var pars= Array();
	try
	{
		var links = $('dedicatedServersWrapper').getElementsByTagName("A");
		var fees = $('dedicatedServersWrapper').getElementsByTagName("ul");
		for(i=0;i<fees.length;i++)
		{
			
			if(fees[i].className=="costs")
			{
				try{
					var thetext = fees[i].innerHTML;
					//thetext = thetext.toLowerCase();
					if(!isIE())	{
						thetext = thetext.split("</sup> ");
						thetext = thetext[1].split("<span>");
						m[c]=thetext[0];
						//alert(m[c]);
						thetext = thetext[1].split("	$");
						thetext = thetext[1].split("</li>");
						s[c]=thetext[0];
					/**/}
					else
					{
						thetext = thetext.split("</SUP> ");
						thetext = thetext[1].split("<SPAN>");
						m[c]=thetext[0];
						if(thetext[1].indexOf("red")>0)
						{
							thetext = thetext[1].split('0</SPAN> $');
						}
						else thetext = thetext[1].split("G> $");
						//alert(thetext[1]);
						thetext = thetext[1].split(" </LI>");
						s[c]=thetext[0];
						//alert(s[c]);
					}/**/
					//alert(s[c]);
					//if(isIE()) alert(m[c]+' y el otro es '+s[c]);
					c++;
				}catch(err)
				{
					s[c]=0;
					c++;
				}
			}
		}
		//alert(c);
		c=0;
		for(i=0;i<links.length;i++)
		{
			href = links[i].getAttribute("href");
			if(href.indexOf("//admin.domaingurus.com/cgi-bin/onlinepurchase.cgi")>0)
			{
				href = href.replace(/http:\/\/admin.domaingurus.com\/cgi-bin\/onlinepurchase.cgi\?/,	 "https://www.domaingurus.com/iBizPanel/PurchaseAdd?");
				href= href.replace(/os_name/,"&attrib_os_name");
				var temp = href.split("?");
				pars[c] = temp[1];
				href = href+"&final_price="+m[c]+"&final_setup="+s[c]+"&Checkout=1";
				//alert(m[c]);
				c++;
				links[i].setAttribute("href",href);
				
			}
			else
			if(href.indexOf("custom-dedicated")>0)
			{
				href = href.replace(/..\/custom-dedicated-server-order-form.php\?/,	 "https://www.domaingurus.com/iBizPanel/PurchaseAdd?");
				href= href.replace(/os_name/,"&attrib_os_name");
				var temp = href.split("?");
				if(isIE()) 
				{
					href=href.replace(/http:\/\/www.domaingurus.c/g,'');
					
					//alert(href);
				}
				href = temp[0]+"?"+pars[c2];
				href = href+"&productoffer_id=48410&final_price="+m[c2]+"&final_setup="+s[c2];
				c2++;
				if(isIE())
				{
					href=href.replace(/http:\/\/www.domaingurus.com\/spanish\/servidores-dedicados\/om\/spani/g,'');
					href=href.replace(/http:\/\/www.domaingurus.com\/spani/g,'');
				}
				links[i].setAttribute("href",href);
			}
		}	
	}catch(err){}
	
	try 
	{ 
		var fees = $('comparison').getElementsByTagName("span");
		var links = $('comparison').getElementsByTagName("A");
		for(i=0;i<fees.length;i++)
		{
			if(fees[i].className=='comparePriceMonthly')
			{
				var tmp = fees[i].innerHTML.split('$');
				tmp = tmp[1].split('/mo');
				m[c]=tmp[0];
				//alert(m[c]);
				c++;
			}
			if(fees[i].className=='comparePriceSetup')
			{
				var tmp = fees[i].innerHTML.split('$');
				tmp = tmp[1].split(' setup');
				s[c2]=tmp[0];
				//alert(s[c2]);
				c2++;
			}
		}
		
		c=0;
		c2=0;
		for(i=0;i<links.length;i++)
		{
			href = links[i].getAttribute("href");
			if(href.indexOf("//admin.domaingurus.com/cgi-bin/onlinepurchase.cgi")>0)
			{
				href = href.replace(/http:\/\/admin.domaingurus.com\/cgi-bin\/onlinepurchase.cgi\?/,	 "https://www.domaingurus.com/iBizPanel/PurchaseAdd?");
				href= href.replace(/os_name/,"&attrib_os_name");
				var temp = href.split("?");
				pars[c] = temp[1];
				href = href+"&final_price="+m[c]+"&final_setup="+s[c]+"&Checkout=1";
				//alert(m[c]);
				c++;
				links[i].setAttribute("href",href);
				
			}
		}
		
		
	}
	catch(err){}
}

function isIE()
{
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer") return 1;
	else return 0;
}

//window.onload=changeLinks;
/*Uncomment these lines if the chat is going to be IN the page, as in, not in a pop up
refresher();
var pcs = new PeriodicalExecuter(CheckStatus,10);
/**/
