// JavaScript Ford.com.br 

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_moveLayers() { //v6.0
  var i,p,t,l,obj,args=MM_moveLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {l=args[i+1]; t=args[i+2];
    if (obj.style) obj=obj.style;
    if(t!='') obj.top=t;
    if(l!='') obj.left=l; }
}

function isMail(str) {
	var hasRegExp=false;
	if(window.RegExp) hasRegExp=(new RegExp(/a/)).test("a");
	
	if(!hasRegExp) return (str.indexOf("@")>0 && str.lastIndexOf(".")>str.indexOf("@"));
	
	var oRegexp=new RegExp(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$/);
	return (oRegexp.test(str))
}
	
function isCPF(cpf){
	var char_valido=0, soma_digito1=0, soma_digito2=0, digito1, digito2, i;
	
	if(cpf=='00000000000' || cpf=='11111111111' ||	cpf=='22222222222' || cpf=='33333333333' ||	cpf=='44444444444' || cpf=='55555555555' ||	cpf=='66666666666' || cpf=='77777777777' || cpf=='88888888888' || cpf=='99999999999') return false;
	
	if(cpf.length!=11) return false;
	
	for(i=0; i<=cpf.length-1; i++) char_valido+=(cpf.charAt(i)>='0' && cpf.charAt(i)<='9')?1:0;
	
	if(char_valido!=11) return false;
	
	for(i=0; i<9; i++) soma_digito1+=(10-i)*(eval(cpf.charAt(i)));
	digito1=11-(soma_digito1%11);
	
	for(i=0; i<9; i++) soma_digito2+=(11-i)*(eval(cpf.charAt(i)));
	soma_digito2+=2*(eval(cpf.charAt(9)));
	digito2=11-(soma_digito2%11);
	
	digito1=((soma_digito1%11)<2)?0:digito1;
	digito2=((soma_digito2%11)<2)?0:digito2;
	
	if(eval(cpf.charAt(9)!=digito1) || eval(cpf.charAt(10)!=digito2)) return false;
	
	return true;
}

function Trim(str){
	var hasRegExp=false;
	if(window.RegExp) hasRegExp=(new RegExp(/a/)).test("a");
	
	if(!hasRegExp) {
		for(var i=0; i<str.length; i++) if(str.charCodeAt(i, i + 1)>32) break;
		for(var j=str.length; j>0; j--) if(str.charCodeAt(j - 1, j)>32) break;
		
		return str.substring(i, j);
	}
	
	var oRegexp=new RegExp(/^[\s]*(.*?)[\s]*$/);
	return str.replace(oRegexp, '$1');
}

function isDate( dd, mm, aaaa )	{
	dtm = new Date( aaaa, mm - 1, dd );
	if( dtm.getMonth() != ( mm - 1 ) )
		return false;			
	return true;	}

function Numerico( key )	{
	if( key < 48 || key > 58 )
		event.keyCode = '';	}
		
function xNumerico(evnt){
	var key=(window.event)?event.keyCode:evnt.charCode;
	if(!window.event && evnt.keyCode!=0) return true;
	if(key<48 || key>58) return false;
	return true;
}

function Minusculas(evnt){
	var key=(window.event)?event.keyCode:evnt.charCode;
	if(key>64 && key<91) if(window.event) window.event.keyCode=key+32;
	return true;
}

function pop( strPagina, intLargura, intAltura, booRolagem ){
	strJanela	=	"pop" + (intLargura+intAltura);
	var	objjan	=	window.open( strPagina, strJanela, 'width=' + intLargura + ',height=' + intAltura +',menubar=no,location=no,scrollbars=' + booRolagem + ',status=no,toolbar=no,resizable=no,top=100,left=100' );	
	objjan.focus();
}

function busca(){	
	window.opener.parent.frames['iframeContent'].location.href	=	'../../institucional/respostaBusca.asp?textfield='	+	document.forms[0].elements['textfield'].value;
	window.opener.focus();
}

var bIsIE=(navigator.appName.indexOf("Explorer")>-1);
var iVersion=(bIsIE) ? parseInt(navigator.appVersion.split("MSIE")[1]) : parseInt(navigator.appVersion);
var bIsAble=(parseInt(navigator.appVersion)>=4);
var ibama = null;

function placeLayer() {
	if (!bIsIE) return(0);
	var iScreenCenter = document.body.clientWidth;
	ibama.style.left = "" + parseInt((iScreenCenter / 2) - 371) + "px";
	ibama.style.visibility = "visible";
}

function getObject(sObjName) {
	return(document.all[sObjName]);
}

function _MenuLoad() 
{
	ibama = getObject("ibama");	
	placeLayer();
	setTimeout("placeLayer()", 500);
}



//onresize = function() {
//	placeLayer();
//}

// ALERTA
function disclaimer(url,janela){
	if(confirm('Estás saliendo del site www.ford.com.ar/myconnection. Los contenidos exhibidos en otros sitios son responsabilidad de estos. Te recomendamos que verifiques si son seguros. Hacé click en cancelar para permanecer en el sitio www.ford.com.ar/myconnection o, si querés continuar, hace click en OK.')){	
	window.open(url,janela);
	}
}
function disclaimer2(){
	if(confirm('Estás saliendo del site www.ford.com.ar/myconnection. Los contenidos exhibidos en otros sitios son responsabilidad de estos. Te recomendamos que verifiques si son seguros. Hacé click en cancelar para permanecer en el sitio www.ford.com.ar/myconnection o, si querés continuar, hace click en OK.')){
	//window.open('https://200.184.130.31/ford/cliente/frm_login.asp?IDArea=1&sel=Ford','remote','width=320,height=450,menubar=no,location=no,scrollbars=no,status=no,toolbar=no,resizable=no');
	//window.open('https://chatford.atento.com.br/','remote','width=320,height=450,menubar=no,location=no,scrollbars=no,status=no,toolbar=no,resizable=no');
	window.open('https://netcall.atento.com.br/ford/cliente/frm_login.asp?IDArea=1&sel=Ford ','remote','width=320,height=450,menubar=no,location=no,scrollbars=no,status=no,toolbar=no,resizable=no');
	}
}

function go2SalesProcess(){
	alert('Site em manutenção.')
}

/*
Funcção: acertaComboDias
Utilizada para atualizar dinamicamente (de acordo com o mês e ano selecionados) uma combo de dias em um conjunto de combos de data (dia, mês e ano)
A função deve ser chamada no evento OnChange das combos de meses e anos.

Os parâmetros passados para a função devem ser:
cboDia => string contendo o id do objeto Select dos dias;
cboMes => string contendo o id do objeto Select dos meses;
cboAno => string contendo o id do objeto Select dos anos;
*/
function acertaComboDias(cboDia, cboMes, cboAno){
	var iDias=31;
	
	cboDia=(typeof(cboDia)=='object')?cboDia:(typeof(cboDia)=='string')?document.getElementById(cboDia):null;
	cboMes=(typeof(cboMes)=='object')?cboMes:(typeof(cboMes)=='string')?document.getElementById(cboMes):null;
	cboAno=(typeof(cboAno)=='object')?cboAno:(typeof(cboAno)=='string')?document.getElementById(cboAno):null;
	
	if(cboDia && cboMes && cboAno) {
		var iMes=cboMes.selectedIndex;
		
		if(iMes==4 || iMes==6 || iMes==9 || iMes==11) iDias=30;
		if(iMes==2){
			iDias=28;
			
			if(cboAno.selectedIndex>0){
				var iAno=parseInt(cboAno[cboAno.selectedIndex].value);
				
				if((iAno%400==0) || (iAno%4==0 && iAno%100!=0)) iDias=29;
			}
		}
		
		if(iDias+1!=cboDia.length){
			if(iDias+1<cboDia.length) cboDia.length=iDias+1;
			else {
				var oNew, oTxt;
				
				for(var i=cboDia.length; i<iDias+1; i++){
					oNew=document.createElement('option');
					oNew.setAttribute('value',i);
					oTxt=document.createTextNode(i);
					oNew.appendChild(oTxt);
					cboDia.appendChild(oNew);
				}
			}
		}
	}
}

// ***** Função para apresentar os popus de informações
function showHideLayer(stLayer, stAction){
	if(lastLayerShown!='' && lastLayerShown.toLowerCase()!=stLayer.toLowerCase()) showHideLayer(lastLayerShown, 'hide');
	
	var oLayer=document.getElementById(stLayer)
	var Combos=document.getElementsByTagName('select');
	
	if(oLayer) if(oLayer.style) {
		if(stAction=='change'){
			showHideLayer(stLayer, (oLayer.style.display=='none')?'show':'hide');
			if(parent.window!=window && parent.adjustIFrameSize) parent.adjustIFrameSize(window, parent.window);
		} else {
			oLayer.style.display=(stAction=='show')?'':'none';
			if(stAction=='show') lastLayerShown=stLayer; else lastLayerShown='';
			for(var i=0; i<Combos.length; i++)
				if(Combos[i]) if(Combos[i].style)
					Combos[i].style.display=(stAction=='show')?'none':'';
			if(parent.window!=window && parent.adjustIFrameSize) parent.adjustIFrameSize(window, parent.window);
		}
	}
}		

// ***** Função para mostrar TRs
function showHideTRs(stLayer, stAction){
	var oLayer=document.getElementById(stLayer)
	
	if(oLayer) if(oLayer.style) {
		if(stAction=='change'){
			showHideTRs(stLayer, (oLayer.style.display=='none')?'show':'hide');
			if((/(\/uuf_)([a-z0-9_]+)(\.asp)/.test(document.location.href)) && parent.window!=window && resizeIFrame) resizeIFrame(parent.document.getElementById('ifrCadastroUUF'));
		} else {
			oLayer.style.display=(stAction=='show')?'':'none';
			if((/(\/uuf_)([a-z0-9_]+)(\.asp)/.test(document.location.href)) && parent.window!=window && resizeIFrame) resizeIFrame(parent.document.getElementById('ifrCadastroUUF'));
		}
	}
}		

// ***** Função para Enviar Post Dinamicamente
function _PostData(_action, _data, _target){
	var regex_data=/&?(.+?)=([^&]*)/g;
	var sHTML='<form id="_frmHdnPostData" name="_frmHdnPostData" action="'+_action+'" method="post"'
	sHTML+=((_target=='')?'':' target="'+_target+'"')+'>'
	sHTML+=_data.replace(regex_data, '<input type="hidden" name="$1" value="$2">')
	sHTML+='</form>';
	
	var objHdnDiv=document.getElementById('_divHdnPostData');
	
	if(!objHdnDiv){
		var objBody=document.getElementsByTagName("body")[0];
		
		objHdnDiv=document.createElement("DIV");
		objHdnDiv.id='_divHdnPostData';
		objHdnDiv.style.display='none';
		
		objHdnDiv.innerHTML=sHTML;
		objBody.appendChild(objHdnDiv);
	} else objHdnDiv.innerHTML=sHTML;
	
	//if(!document._frmHdnPostData);
	
	//document.body.insertAdjacentHTML('AfterBegin', sHTML);
	if(document._frmHdnPostData) document._frmHdnPostData.submit();
}

function openConfig(modelo){
	window.open('blank.htm','novo_config','width=1014,height=680,scrollbars=0');
	_PostData('https://www.configurador.ford.com.br/novo_configurador/drtc_redirect2.asp', 'hdnModelo='+modelo, 'novo_config');
}
