function gDoc(x){ return document.getElementById(x);}

function requestAJAX(action,value,target)
{
	if (action == 'linhas')
	gDoc('pnlRuas').innerHTML = "";
	
	oAjax = new ajaxClass();
	oAjax.getResult(action,value,target);
}

function disableSelection(target)
{
	if (typeof target.onselectstart != "undefined") //IE route
		target.onselectstart=function(){return false}
	else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
		target.style.MozUserSelect="none";
	else //All other route (ie: Opera)
		target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function openPopUp(action)
{
	var container = gDoc('popContainer');
	var box = gDoc('popBox');
	var ifrm = gDoc('ifrm');
    
	if(ifrm.style.display == "" || ifrm.style.display == "none")
    {
		ifrm.style.opacity = '.70';
		ifrm.style.filter = 'Alpha(opacity=70)';
		ifrm.style.height = getPageSize().pageHeight + 'px';
		ifrm.style.width = getPageSize().pageWidth + 'px';
		ifrm.style.display = "block";		
		if (document.frames) document.frames['ifrm'].document.body.style.backgroundColor = "#000";
	
		container.style.display = "block";
		gDoc('popHead').innerHTML = action;
		
		if (action == "Enviar Linha" || action == "Indicar Site")
		{
			oAjax = new ajaxClass();
			oAjax.getResult(action,'','popContent');
		}
    }
    else
    {
		ifrm.style.display = "none";
        container.style.display = "none";
    }
}

function getPageSize()
{
    var xScroll, yScroll;
	
    if(window.innerHeight && window.scrollMaxY)
	{
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
	else
	{
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if(self.innerHeight)
	{
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
	else if(document.documentElement && document.documentElement.clientHeight)
	{
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    }
	else if(document.body)
	{
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	

    if(yScroll < windowHeight)
        pageHeight = windowHeight;
    else
        pageHeight = yScroll;

    if(xScroll < windowWidth)
        pageWidth = windowWidth;
    else
        pageWidth = xScroll;

    arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};

    return arrayPageSize;
}

function isValidEmail(email)
{
	pattern = new RegExp("^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([a-z,A-Z]){2,3}([0-9,a-z,A-Z])?$");

	if(email.search(pattern) == -1)
		return false;
	else
		return true;
}

var error = new Array();
error[0] = "&bull; Favor, informe seu nome!<br />";
error[1] = "&bull; Favor, informe seu e-mail!<br />";
error[2] = "&bull; E-mail inválido!<br />";
error[3] = "&bull; Favor, informe o nome do destinatário!<br />";
error[4] = "&bull; Favor, informe o e-mail do destinatário!<br />";
		

function sendLink()
{
	var senderName = gDoc('txtNameSender');
	var senderEmail = gDoc('txtEmailSender');
	var receiverName = gDoc('txtName');
	var receiverEmail =	gDoc('txtEmail');
	var errorMsg = "";
	var messageType = gDoc('hdnType').value;
	
	senderName.className = "";
	senderEmail.className = "";
	receiverName.className = ""
	receiverEmail.className = "";
	
    if(senderName.value == "")
	{
        errorMsg += error[0];
		senderName.className = "errInput";
    }
	if(senderEmail.value == "")
	{
        errorMsg += error[1];
        senderEmail.className = "errInput";
    }
	else if(!isValidEmail(senderEmail.value))
	{
        errorMsg += error[2];
        senderEmail.className = "errInput";
    }
	if(receiverName.value == "")
	{
        errorMsg += error[3];
        receiverName.className = "errInput";
    }
	if(receiverEmail.value == "")
	{
        errorMsg += error[4];
        receiverEmail.className = "errInput";
    }
	else if(!isValidEmail(receiverEmail.value))
	{
        errorMsg += error[2];
        receiverEmail.className = "errInput";
    }
	
	if (errorMsg != "")
	{
		gDoc('errorMsg').className = "err";
		gDoc('errorMsg').innerHTML = errorMsg;
	}
	else
	{	
		var link = linha = '';
		
		if (gDoc('link'))
			link = gDoc('link').value;
		if (gDoc('lblLinha'))
			linha = gDoc('lblLinha').innerHTML;
	
		var value = senderName.value + "||" + senderEmail.value + "||" + receiverName.value + "||" + receiverEmail.value + "||" + link + "||" + linha + "||" + messageType;
		
		oAjax = new ajaxClass();
		oAjax.getResult('sendLink',value,'popContent');
    }
}

function popupPrint()
{window.open('popup_print.php','Print','toolbar=no,location=no,directories=no,height=600,width=560,top=0,left=5,scrollbars=yes,resizable=yes');}


