﻿// JScript File

//---------------------- Star Rater ----------------------
//<starReterId> Id of the current StarReter object.
//<starNumber> Number of the stars to fill.
function SelectStarsToRate(starRaterId, starNumber)
{
    var rate = document.getElementById(starRaterId + "_inputRate");
        
    for (posicion = 1; posicion <= 5; posicion++)
    {
        star = document.getElementById(starRaterId + "_ibStar" + posicion);
        
        if (posicion <= starNumber)
            try 
            {
            star.src = 'gfx/StarOver.gif';
            }
            catch (err)
            {
             star.src = '../gfx/StarOver.gif';
            }
        else if (posicion <= parseInt(rate.value))
        try 
            {
            star.src = 'gfx/StarOn.gif';
            }
            catch (err)
            {
             star.src = '../gfx/StarOn.gif';
            }
            
        else
        try 
            {                   
            star.src = 'gfx/StarOff.gif';
            }
             catch (err)
            {
             star.src = '../gfx/StarOff.gif';
            }
    }
}

//<starReterId> Id of the current StarReter object.
//<starNumber> Number of the stars to fill.
function UnselectStarsToRate(starRaterId, starNumber)
{
    var rate = document.getElementById(starRaterId + "_inputRate");
    
    for (posicion = 1; posicion <= 5; posicion++)
    {
        star = document.getElementById(starRaterId + "_ibStar" + posicion);
        
        if (posicion <= parseInt(rate.value))
            try
            {
                star.src = 'gfx/StarOn.gif';
            }
            catch (err)
            {
                star.src = '../gfx/StarOn.gif';
            }
        else
        try
            {
            star.src = 'gfx/StarOff.gif';
            }
            catch (err)
            {
                star.src = '../gfx/StarOff.gif';
            }
            
    }
}

//<starReterId> Id of the current StarReter object.
function SelectNotInterested(starRaterId)
{
    notInterestedImage = document.getElementById(starRaterId + "_ibNotInterested");
      try
            {
            notInterestedImage.src = 'gfx/NotInterestedOver.gif';
            }
      catch (err)
            {
                notInterestedImage.src = '../gfx/NotInterestedOver.gif';
            }
            
}

//<starReterId> Id of the current StarReter object.
function UnselectNotInterested(starRaterId)
{
    notInterestedImage = document.getElementById(starRaterId + "_ibNotInterested");
    var notInterested = document.getElementById(starRaterId + "_inputNotInterested");
    
    if (notInterested.value == "0")
        try
        {
         notInterestedImage.src = 'gfx/NotInterestedOff.gif';
        }
        catch (err)
        {
         notInterestedImage.src = '../gfx/NotInterestedOff.gif';
        }
    else
        try
        { 
        notInterestedImage.src = 'gfx/NotInterestedOn.gif';
        }
        catch (err)
        {
        notInterestedImage.src = '../gfx/NotInterestedOn.gif';
        }
}


//---------------------- Character Count ----------------------
//<id> TextBoxId to count characters.
//<len> Quantity of characters to allow to type.
//<idCount> LabelId to store the number of characters typed.
function CheckLen(id, len, idCount, e)
{
    keyPressed = (document.all) ? window.event.keyCode : e.which;
    input = document.getElementById(id);
    countLabel = document.getElementById(idCount);

    var length = "";

    if (document.all)
        length = countLabel.innerText;
    else
        length = countLabel.textContent;
    
    if ( parseInt(length) == parseInt(len) )
    {
        if (document.all)
            countLabel.innerText = parseInt(input.value.length);
        else
            countLabel.textContent = parseInt(input.value.length);

        return false;
    }
    else
    {
        if (document.all)
            countLabel.innerText = parseInt(input.value.length);
        else
            countLabel.textContent = parseInt(input.value.length);

        if ( parseInt(input.value.length) >= parseInt(len) )
        {
            input.value = input.value.substring(0, parseInt(len));

            if (document.all)
                countLabel.innerText = parseInt(input.value.length);
            else
                countLabel.textContent = parseInt(input.value.length);

            return false;
        }
    }
}

//---------------------- Validate Digits ----------------------
function ValidateDigits(e)
{
    keyPressed = (document.all) ? window.event.keyCode : e.which;

	return ((keyPressed >= 48) && (keyPressed <= 57))
}

//---------------------- Validate Phone Chars ----------------------
function ValidatePhoneChars(e)
{
    keyPressed = (document.all) ? window.event.keyCode : e.which;

	if ((keyPressed < 48) || (keyPressed > 57) )
	{
	    if ( !((keyPressed == 40) || (keyPressed == 41) || (keyPressed == 42) || 
	           (keyPressed == 44) || (keyPressed == 45) || (keyPressed == 46) || (keyPressed == 32)) )
            return false;
    }
}

//---------------------- Validate Decimal ----------------------
//<id> Textbox or Input to validate only type digits like decimal value.
function ValidateDecimal(id, e)
{
    keyPressed = (document.all) ? window.event.keyCode : e.which;

	if ( (keyPressed < 48) || (keyPressed > 57) )
	{
	    if (keyPressed == 46)
	    {
	        input = document.getElementById(id);
	        
	        value = input.value.split(".");
	        if (value.length > 1)
	            return false;
	    }
	    else
	        return false;
	}
}

function ValidateMoney(e)
{
    keyPressed = (document.all) ? window.event.keyCode : e.which;
    
	return (keyPressed == 48 || 
	        keyPressed == 49 ||
	        keyPressed == 50 ||
	        keyPressed == 51 ||
	        keyPressed == 52 ||
	        keyPressed == 53 ||
	        keyPressed == 54 ||
	        keyPressed == 55 ||
	        keyPressed == 56 ||
	        keyPressed == 57 || 
	        keyPressed == 46 || 
	        keyPressed == 44)
}

//----------Searchs Verifing Div Status------
function VerifyDivStatus(idControl, idImage, idInput)
{
    control = document.getElementById(idControl);
    image = document.getElementById(idImage);
    input = document.getElementById(idInput);
    
    if (input.value == 'true')
    {  
        if (idControl.indexOf('srchCtrls')>-1) {
            image.src = 'gfx/ico_SA_arr_d.gif';
        } else {
        image.src = 'Images/minusButton.JPG';
        }
        control.style.display = '';
    }
    else
    {
        if (idControl.indexOf('srchCtrls')>-1) {
            image.src = 'gfx/ico_SA_arr_r.gif';
        } else {
        image.src = 'Images/plusButton.JPG';
        }
        control.style.display = 'none';
    }
}

function DisplayAdvancedControls(idControl, idImage, idInput)
{
    control = document.getElementById(idControl);
    input = document.getElementById(idInput);
    
    if(control.style.display == 'none')
        input.value = true;
    else
        input.value = false;
        
    VerifyDivStatus(idControl, idImage, idInput); 
}

//----------Contacts Importer------
//A TextBox or Input text is needed to store de Contacts Imported,
//the control must be named as tbContacts with the runat server property turned on like a server control.

function onABCommComplete(data)
{   
    __doPostBack(btnImport, data);
}

function ClearContacts()
{
    var contacts = document.getElementById(tbContacts);
    
    if (document.all)
        contacts.innerText = "";
    else
        contacts.textContent = "";
}

function SetRepository(idTbContacts, idBtnImport)
{
    tbContacts = idTbContacts;
    btnImport = idBtnImport;
}


//----------- View Invoice -------
function ViewInvoice(idBillingCycle, viewPDF)
{
    var page;
    
    if (viewPDF == 'True')
        page = 'Invoice';
    else
        page = 'ViewInvoice';
    
    window.open(page + '.aspx?data=' + idBillingCycle,'','width=1020, height=600, scrollbars=yes, resizable=yes, directories=no, menubar=no, toolbar=no, status=yes, titlebar=yes');
}


function WithinPostBack(_ftbMessage, _ddlCoverLetters, _ddlText, _ddlSubject, _tbSubject)
{
    var mylist = document.getElementById(_ddlCoverLetters.id);
    var mylist2 = document.getElementById(_ddlText.id);
    var myList3 = document.getElementById(_ddlSubject.id);
    var myList4 = document.getElementById(_tbSubject.id);
    var myText = document.getElementById(_ftbMessage.id);
    myText.value ='';
    myText.value = mylist2.options[mylist.selectedIndex].text;
    myText.value = myText.value.replace(/\\n/g,"\r\n");
    myList4.value = '';
    myList4.value = myList3.options[mylist.selectedIndex].text;
    mylist.focus();
}
