function showDiv(obj, divName) {
    var value = getObjectValueByType(obj);
    
    if (value.length > 0) 
        document.getElementById(divName).style.display='block'; 
    else 
        document.getElementById(divName).style.display='none';
}

function showDiv(divName) {
    if (document.getElementById(divName).style.display=='none') 
        document.getElementById(divName).style.display='block'; 
    else 
        document.getElementById(divName).style.display='none';
}

function printSummary(div) {
    div.style.display='none';
    window.print();
    div.style.display='block';
}

function clearData(){
    window.clipboardData.setData('text','');
}
function ccd(){
    if(clipboardData){
       clipboardData.clearData();
    }
}

function isNumber(value, msg) {
    if (isNaN(value)) {
        alert(msg);
    }
}

function validaMayotA(name, limit, mensaje) {
    var value = parseFloat(document.getElementById(name).value);
    if (value < limit) {
        alert(mensaje);
        document.getElementById(name).focus();
        document.getElementById(name).select();
        return false;
    }
    return true;
}

function changeLink(path, to, nombreAdicional, cotizacion, claveTipoCotizacion, claveMenu) {
    document.getElementById('nombreAdicional').value = nombreAdicional;
    document.getElementById('cotizacion').value = cotizacion;
    document.getElementById('claveTipoCotizacion').value = claveTipoCotizacion;
    document.getElementById('claveMenu').value = claveMenu;
    document.menuForm.action = path;
    document.menuForm.target = to;
    document.menuForm.submit();
}

function sumTwoFields(fieldOne, fieldTwo, fieldThree) {
    var value1 = 0;
    var value2 = 0;
    var value3 = 0;
    if ((fieldOne.value.length > 0) && !isNaN(fieldOne.value)) {
        fieldOne.value = parseFloat(fieldOne.value).toFixed(2);
        value1 = parseFloat(fieldOne.value);
    }
    if ((fieldTwo.value.length > 0) && !isNaN(fieldTwo.value)) {
        fieldTwo.value = parseFloat(fieldTwo.value).toFixed(2);
        value2 = parseFloat(fieldTwo.value);
    }
    value3 = value1 + value2;
    if (value3 > 0) {
        fieldThree.value = value3.toFixed(2);
    } else {
        fieldThree.value = "";
    }
}

function mayusculas(objTxt) {
    objTxt.value = objTxt.value.toUpperCase();
}
/*****************************************/

function hide(tabla) {
    if (tabla.style.display=="block")
        tabla.style.display="none";
    else 
        tabla.style.display="block";
}

function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObj('tabla'))
		if (!isChild(CSE,getObj('tabla')))
			getObj('tabla').style.display='none';
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

document.write('<table id="tabla" style="position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none" cellpadding=2>');
document.write('<tr><td><img id="tabla_img" src="images/no_prestamo.JPG"></td></tr></table>');
document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick,false);

var updobj;
function lcs(ielem) {
	updobj=ielem;
	getObj('tabla').style.left=Left(ielem);
	getObj('tabla').style.top=Top(ielem)+ielem.offsetHeight;
	getObj('tabla').style.display='';
	
	// First check date is valid
        /*
	curdt=ielem.value;
	curdtarr=curdt.split('/');
	isdt=true;
	for(var k=0;k<curdtarr.length;k++) {
		if (isNaN(curdtarr[k]))
			isdt=false;
	}
	if (isdt&(curdtarr.length==3)) {
		ccm=curdtarr[1]-1;
		ccy=curdtarr[2];
		prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
	}*/
	
}

function showHelpNoPrestamo(ielem) {
    document.getElementById('tabla_img').src="images/no_prestamo.JPG";
    lcs(ielem)
}

function showHelpRFC(ielem) {
    document.getElementById('tabla_img').src="images/rfc.jpg";
    lcs(ielem)
}


function createRequest() {
    var xmlHttp;
    try {    // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {    // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Tu Navegador no soporta AJAX!");
                return false;
            }      
        }    
    }
    return xmlHttp;
}

function iniciaTransaccion(path, divObj, monto) {
    var x = validatePagoEnLineaForm(document.getElementById('paramForm'));

    if (!x) {
        document.getElementById('enviar').disabled = false;
        return;
    }

    var xmlHttpReq = false;
    
    var url = "http://" + path +"/pagoEnLinea.do?action=payworks&monto=" + monto;
            
    xmlHttpReq = createRequest();
    
    xmlHttpReq.onreadystatechange = function() { callBackIniciaTransaccion(xmlHttpReq, divObj) };
    xmlHttpReq.open("GET", url , true);
    if(!xmlHttpReq.send(null)) { }
}

function callBackIniciaTransaccion(xmlHttpReq, divObj) {
    var state = xmlHttpReq.readyState;
    
    if (state == 1) { percentState = "."; }
    if (state == 2) { percentState = ".."; }
    if (state == 3) { percentState = "..."; }
    if (state == 4) { percentState = "...."; }
    
    divObj.innerHTML = percentState;
    
    if(state == 4) {
        if(xmlHttpReq.status == 200) {  
            if(xmlHttpReq.responseText.indexOf("ERROR") == -1) {
                if(xmlHttpReq.responseText.indexOf("EMPTY") == -1) {
                    if(xmlHttpReq.responseText.indexOf("SUCCESS") != -1) {
                    
                        document.getElementById('amount').value = document.getElementsByName('monto')[0].value;
                        document.getElementById('responseUrl').value += document.getElementsByName('monto')[0].value;
                        document.forms[1].submit();
                        
                    } else {
                        divObj.innerHTML = "Falló la Transacción: por favor, intente mas tarde";
                    }
                } else {
                    divObj.innerHTML = "No se encontraron registros.";
                } 
            } else {
                divObj.innerHTML = "Error (2) en conexion: por favor, intente mas tarde";
            }
        } else {
            divObj.innerHTML = "Error (1) en conexion: por favor, intente mas tarde";
        }
        divObj.innerHTML = "&nbsp;";
    }
}

