var comHTTPS = "http://";
var semHTTPS = "http://";
var semHTTPSComum = "ssComum";
var comHTTPSComum = "ssComum";
var rootPath = "localhost/";

//var pagamentos = "http://www.pagamentosonline.com.br/startSmartPaghandshake.asp"; 
var pagamentoPath = comHTTPS + rootPath + "PagamentoOnline/";
var realPagPath = comHTTPS + rootPath + "RealPag/";
var sitePath = rootPath;
var backOfficePath = comHTTPS+rootPath + "BackOfficeUI/";
var fotosPath = comHTTPS+rootPath + "_fotos/";
var bannerPath = comHTTPS+rootPath + "_banner/";
var realPag = "https://www.realpague.com.br";
var pagamentos = "https://www.smartpag.com.br/startSmartPagHandshake.asp"; 

var textoTelefone;

 expireDate = new Date;
 expireDate.setDate(expireDate.getDate()+365);
 
function openPopUpCentro(url, vwidth, vheight){
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;

	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = vheight/2;
	largura2 = vwidth/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
		
	window.open(url,'','toolbar=0,menubar=0,width=' + vwidth + ',height=' + vheight + ',top=' + meio1 + ',left=' + meio2 + ',scroolbar=0');
}
function openPopUpCentroScroll(url, vwidth, vheight){
	//pega a resolução do visitante
	w = screen.width;
	h = screen.height;
	
	//divide a resolução por 2, obtendo o centro do monitor
	meio_w = w/2;
	meio_h = h/2;

	//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
	altura2 = vheight/2;
	largura2 = vwidth/2;
	meio1 = meio_h-altura2;
	meio2 = meio_w-largura2;
	
	window.open(url,'','resizable = yes ,status=yes,toolbar=no,menubar=no,width=' + vwidth + ',height=' + vheight + ',top=' + meio1 + ',left=' + meio2 + ',scrollbars=yes');
}
function setDetail(field)
	{
		var modulo_index=0;
		for(i=0;i<document.frmModuloUi.modulo.length;i++){
			if(document.frmModuloUi.modulo[i].checked == true){
				modulo_index = i;	
			}	
		}
		var detail = new String(field.value).split("|");
		document.frmModuloUi.index.value = modulo_index;
		field.checked = true;
		return false;
	}
	
function checkLengthTextArea(cp,len){
	if (cp.value.length >= len){
		cp.value = cp.value.substring(0,len-1);
    }
}
function copiaValor(origem,destino)
{
	if (document.getElementById(origem) != null && document.getElementById(destino) != null);
		document.getElementById(destino).value = document.getElementById(origem).value;
}		

function noPostBack(sNewFormAction)
{
	document.forms[0].action = sNewFormAction;
	document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
	document.forms[0].submit();
}
function orderByRefresh(sTipo)
{
	document.forms[0].hOrdenacao.value = sTipo;
	document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
	document.forms[0].submit();
}

function enviar(valor,url)
{
	if (document.getElementById('hidFilter') != null)
		document.getElementById('hidFilter').value = "";
		
	if (document.getElementById('hidBlock') != null)
		document.getElementById('hidBlock').value = "";
	
	if (document.getElementById('hidCurPage') != null)
		document.getElementById('hidCurPage').value = "1";
		
	if (document.getElementById('hidBlock') != null)
		document.getElementById('hidBlock').value = "";
		
	if (document.getElementById('hidCurBlock') != null)
		document.getElementById('hidCurBlock').value = "0";
	
	if (document.getElementById('hidNavigation') != null)
		document.getElementById('hidNavigation').value = "";
	
	document.forms[0].hbusca.value = valor;
	noPostBack(url);
}
function copiaValor(origem,destino)
{
	if (document.getElementById(origem) != null && document.getElementById(destino) != null);
		document.getElementById(destino).value = document.getElementById(origem).value;
}
function CopiaRadio(origem, destino)
{
	if (document.getElementById(origem).checked)
		document.getElementById(destino).value = document.getElementById(origem).value;
}
function copiaTexto(origem, destino)
{
	if (document.getElementById(origem) != null && document.getElementById(destino) != null)
		if (document.getElementById(origem).selectedIndex != -1)
			document.getElementById(destino).value = document.getElementById(origem).options[document.getElementById(origem).selectedIndex].text;
}
function bindAno(control,valorSelecionado)	
{
	j=0;
	date = new Date();
	ano = date.getFullYear();
	obj = document.getElementById(control);
	
	obj.options[0] = new Option('', '');
	
	for (i=ano+1;i>1939;i--)
	{
		j++;
		obj.options[j] = new Option(i, i);
		
		if (i == valorSelecionado)
			obj.options[j].selected = true;
	}
}

function getCookie(cookieName) 
{
  thisCookie = document.cookie.split('; ')
  for (i = 0; i < thisCookie.length; i++) 
  {
	 if (cookieName == thisCookie[i].split('=')[0]) 
         {
         	return thisCookie[i].split('=')[1];
	 }	

  }
  return 0;
}

function delAnuncio(valor) 
{
   if (getCookie('ListaWebMotors')  != 0)
   {
	var cookieValor=getCookie('ListaWebMotors');
	document.cookie = 'ListaWebMotors='+cookieValor+';expires=' + expireDate.toGMTString();
   }

}
var IFrameObj; // our IFrame object
function removerMinhaListaAnuncio(valor) 
{
	refreshMinhaListaAnuncio('E',valor);
}
function adicionarMinhaListaAnuncio(valor) 
{
	refreshMinhaListaAnuncio('I',valor);
}

function detalheAnuncio(sNewFormAction,codidoAnuncio)
{
	document.getElementById('hidCodAnuncio').value = codidoAnuncio;
	noPostBack(sNewFormAction);
}

function refreshMinhaListaAnuncio(operacao,valor) 
{
	if (!document.createElement) {return true};
	var IFrameDoc; // our IFrame object
	
	var URL = semHTTPS + sitePath + semHTTPSComum + "/pgAtualizandoMinhaLista/pgAtualizandoMinhaLista.aspx?operacao=" + operacao + "&valor=" + valor;

	if (!IFrameObj && document.createElement) {
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame'+valor);
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				IFrameObj = document.frames['RSIFrame'+valor];
			}
		} catch(exception) {
			iframeHTML='<iframe id="RSIFrame'+valor + '" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame'+valor);
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout('refreshMinhaListaAnuncio('+ operacao + ',' + valor + ')',100);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	IFrameDoc.location.replace(URL);	
	return false;
}

function clickTelefone(link,codigo,descricao,placa,cor,telefone) {
	// Rotina para contagem de clicks em paralelo //
	if (document.referrer.indexOf('https:') != -1)
		document.getElementById(link).innerHTML = "<img src='" + comHTTPS + sitePath + "outros/gravaTelefone.asp?codusado=" + codigo + "' width='1' height='1'>"
	else
		document.getElementById(link).innerHTML = "<img src='" + semHTTPS + sitePath + "outros/gravaTelefone.asp?codusado=" + codigo + "' width='1' height='1'>"
	//
	
	if (!document.createElement) {return true};
	var IFrameDoc; // our IFrame object
	
	if (document.referrer.indexOf('https:') != -1)
		var URL = comHTTPS + sitePath + "ssComum/pgClickTelefone/pgClickTelefone.aspx?link=" + link + "&CodigoAnuncio=" + codigo + "&DescricaoVeiculo=" + descricao +"&PlacaVeiculo="+placa+"&Cor="+cor+"&telefone=" + telefone;
	else
		var URL = semHTTPS + sitePath + "ssComum/pgClickTelefone/pgClickTelefone.aspx?link=" + link + "&CodigoAnuncio=" + codigo + "&DescricaoVeiculo=" + descricao +"&PlacaVeiculo="+placa+"&Cor="+cor+"&telefone=" + telefone;

	if (!IFrameObj && document.createElement) {
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','RSIFrame');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);
			
			if (document.frames) {
				IFrameObj = document.frames['RSIFrame'];
			}
		} catch(exception) {
			iframeHTML='<iframe id="RSIFrame'+valor + '" style="';
			iframeHTML+='border:0px;';
			iframeHTML+='width:0px;';
			iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout('clickTelefone(' + link + ','+ codigo + ',' + descricao + ',' + placa + ',' + cor + ',' + telefone + ')',10);
		return false;
	}
	
	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}
	IFrameDoc.location.replace(URL);	
	return false;
}
function exibeTelefone(link, texto, erro)
{
	if (erro != "")
		document.getElementById('lblErro').innerHTML = erro;
	else
		document.getElementById(link).innerHTML = texto;
}

function exibeMensagem(operacao, mensagem)
{
	switch (operacao)
	{
		case 'I':
			__doPostBack('lnkMinhaLista', '')
			break;
		case 'E':
			__doPostBack('lnkRemoverMinhaLista', '')
			break;
		default:
			document.getElementById('lblErro').innerHTML = mensagem;
			break;
	}
}

function reload(img)
{
	var reload;
	reload = document.getElementById(img).src;
	document.getElementById(img).src = '';
	document.getElementById(img).src = reload;
}
// chamada para abrir PopUp de Video e Foto Animada 
function openPopUpCentroVideoFotoAnimada(url, tipo){ 
        /*        tipo = 1 video, 2 foto animada, 
                areaSite = C Clone, W WebMotors, P Patrocinador, S SiteAutomatico, F Feirao  */ 

        vwidth = 370; 
        vheight = 450; 
        
        // foto animada 
        if (tipo != null && tipo == "2") 
                var vheight = 440; 
        
        var qs = new Querystring(url); 
        // Quando for Clone. 
        if (url.indexOf('areaSite') != '-1' && qs.get("areaSite") != null && qs.get("areaSite") == "W") 
        { 
                var vwidth = 500; 
                var vheight = 610; 

                // foto animada 
                if (tipo != null && tipo == "2") 
                        var vheight = 599; 
        } 
                
        //pega a resolução do visitante 
        w = screen.width; 
        h = screen.height; 
        
        //divide a resolução por 2, obtendo o centro do monitor 
        meio_w = w/2; 
        meio_h = h/2; 

        //diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada 
        altura2 = vheight/2; 
        largura2 = vwidth/2; 
        meio1 = meio_h-altura2; 
        meio2 = meio_w-largura2; 
                
        window.open(url,'','toolbar=0,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + vwidth + ',height=' + vheight + ',top=' + meio1 + ',left=' + meio2); 
} 
function Querystring(qs) { // optionally pass a querystring to parse 
        this.params = new Object() 
        this.get=Querystring_get 
        
        if (qs == null) 
                qs=location.search.substring(1,location.search.length) 

        if (qs.length == 0) return 

        // Turn <plus> back to <space> 
        // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 
        qs = qs.replace(/\+/g, ' ') 
        var args = qs.split('&') // parse out name/value pairs separated via & 
        
        // split out each name=value pair 
        for (var i=0;i<args.length;i++) { 
                var value; 
                var pair = args[i].split('=') 
                var name = unescape(pair[0]) 

                if (pair.length == 2) 
                        value = unescape(pair[1]) 
                else 
                        value = name 
                
                this.params[name] = value 
        } 
} 

function Querystring_get(key, default_) { 
        // This silly looking line changes UNDEFINED to NULL 
        if (default_ == null) default_ = null; 
        
        var value=this.params[key] 
        if (value==null) value=default_; 
        
        return value 
} 
