﻿<!--
// jack_port - mockartstudio.com
// version 1.0 
// shur*02/08/2009

    var j = null;
    var d = null;
    var sent_status = '';
    var jack_limit = 100;    
    var jack_count = 0;
    var jack_timeout = 100;  
    var jack_row_id = 0;
    var jack_wt = null;
    var jack_status = '';
    
    function LoadJack(par_attributes) 
    {
        d = new Date();  
        sent_status = d.getFullYear().toString() + d.getMonth().toString() + d.getDate().toString() + d.getHours().toString() + d.getMinutes().toString() + d.getSeconds().toString() + d.getMilliseconds().toString();  
        
        // works fine in IE, however the firefox is buffering external javascript files
        // and does not want to reload them without the whole page reload
        //
        //jack_status = '';
        //
        //if(j == null) j = GetObject('wf_jack');
        //if(j == null) return;
        //
        //j.src = 'jack.aspx?sent_status=' + sent_status + par_attributes;

        j = document.createElement('script');
        j.src = 'jack.aspx?sent_status=' + sent_status + par_attributes;
        
        var head = document.getElementsByTagName('head')[0];
        head.appendChild(j);
        
    }
    
    function VoteForImage(attributes, row) 
    {
        if(jack_count != 0) { DispErrMsg('Communication conflict. Please try again.', 'errMsgSpan'); return; }
        
        LockScreen(true);   // lock screen to prevent double calls
        
        ShowHidePanel('vote_pannel_' + row , false);
        
        jack_row_id = row;
        
        LoadJack(attributes);
        
        jack_wt = window.setTimeout('GetVoteConfirmation()', jack_timeout);
    }

    function GetVoteConfirmation()
    {
        jack_count++;  
        if(jack_count > jack_limit) 
        {
            jack_row_id = 0;
            jack_count = 0;
            LockScreen(false);  // unlock screen 
            DispErrMsg('Vote failed.','errMsgSpan');
        }
        else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
        {
            jack_row_id = 0;
            jack_count = 0;
            LockScreen(false);  // unlock screen 
            DispErrMsg(jack_status.replace('error: ',''),'errMsgSpan');
        }
        else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
        {
            // display vote result
            var ico = GetObject('ico_vote_' + jack_row_id);
            if(ico != null) ico.style.display = 'none';

            var spv = GetObject('vote_' + jack_row_id);
            if(spv != null) 
            {
                spv.style.display = '';
                spv.innerHTML = jack_vote;
            }
            
            DispErrMsg('Vote accepted. The Rating will be changed in a few minutes.','errMsgSpan');
            
            jack_row_id = 0;
            jack_count = 0;
            LockScreen(false);  // unlock screen 
        }
        else
        {
            jack_wt = window.setTimeout("GetVoteConfirmation()", jack_timeout);       
        }
    }

    function GetMailImageConfirmation()
    {
        jack_count++;    
        if(jack_count > jack_limit) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen  
            DispErrMsg('It takes too long to send the message. Please check the e-mail address.','errMsgSpan');
        }
        else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen 
            DispErrMsg(jack_status.replace('error: ',''),'errMsgSpan');
            jack_status = '';
        }
        else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
        {
            if(jack_send != '')
            {
                DispErrMsg(jack_send,'errMsgSpan');
            }
            else { DispErrMsg('','errMsgSpan'); }
            
            jack_count = 0;
            LockScreen(false);  // unlock screen 
        }
        else
        {
            jack_wt = window.setTimeout("GetMailImageConfirmation()", jack_timeout);
            DispErrMsg('','errMsgSpan');       
        }
    }
        
    function LockScreen(lock)
    {
        var progress = GetObject('icon_progress');

        var shield = GetObject('whiteShield');
        if(shield == null) shield = GetObject('e_mailPannelShield');
        
        if(lock) /////// lock screen and display progress indicator
        {
            if(shield != null)   
            {
                shield.style.width  = 2000; // parseInt(document.body.clientWidth) - 20;
                shield.style.height = 2000; // parseInt(document.body.clientHeight) - 10;
                shield.style.display = '';
            }
            if(progress != null) progress.style.display = '';
        }
        else /////////// hide progress indicator and enable screen
        {
            if(shield != null)   shield.style.display = 'none';
            if(progress != null) progress.style.display = 'none';
            window.clearTimeout();
        }
    }

    var mailControls = new Array('E_Mail_to','First_Name_to','Last_Name_to','E_Mail_from','First_Name_from','Last_Name_from');
    var mcLen = mailControls.length;
    
    function ShowCustomEMailPannel(top, left, title, msg, sendImage)
    {
        var p = GetObject('send_page_pannel');
        var m = GetObject('message');
        var t = GetObject('send_page_pannel_title');
        
        if(p == null || m == null || t == null ) return;
        
        var c = null;
        for(var i = 0; i < mcLen; i++)
        {
            c = GetObject(mailControls[i]);
            if(c == null) continue;
		    c.style.backgroundColor = nrmBG;
		    c.style.color = nrmTX;
        }

        var cmd_msg = GetObject('cmd_send_msg');
        var cmd_img = GetObject('cmd_send_img');
        
        if(cmd_msg != null && cmd_img != null)
        {
            if(sendImage)
            {
                if(cmd_msg.style.display != 'none')
                {
                    cmd_msg.style.display = 'none';
                    cmd_img.style.display = '';
                    m.value = '';
                }
            }
            else if(cmd_img.style.display != 'none')
            {
                cmd_msg.style.display = '';
                cmd_img.style.display = 'none';
                m.value = '';
            }
        }

        if(top   != '') p.style.top  = top;
        if(left  != '') p.style.left = left;
        if(title != '') t.innerHTML  = title;
        if(msg   != '') m.value      = msg;

        CountTACharacters(m, 200, 'charCounterBoard');
        ShowHidePanel('send_page_pannel', true);
    }
    
    function SendPageToFriend()
    {
        ShowCustomEMailPannel('', '', 'Send Page to Friend:', '', false);
    }

    function ShowHidePanel(pannel_id, show)
    {
        var shield = GetObject('clearShield');
        if(shield == null) shield = GetObject('e_mailPannelShield');
        
        var pannel = GetObject(pannel_id);

        if(show) /////// lock screen and display progress indicator
        {
            if(shield != null) 
            {
                shield.style.width  = 2000; //parseInt(document.body.clientWidth) - 1;
                shield.style.height = 2000; //parseInt(document.body.clientHeight);
                shield.style.display = '';
            }
            if(pannel != null) pannel.style.display = '';
        }
        else /////////// hide progress indicator and enable screen
        {
            if(shield != null) shield.style.display = 'none';
            if(pannel != null) pannel.style.display = 'none';
        }
    }

    function EMailPageAsync(attributes)
    {
        var email_to    = GetObject('E_Mail_to');
        var fn_to       = GetObject('First_Name_to');
        var ln_to       = GetObject('Last_Name_to');
        
        var email_from  = GetObject('E_Mail_from');
        var fn_from     = GetObject('First_Name_from');
        var ln_from     = GetObject('Last_Name_from');
        
        var msg         = GetObject('message');

        if(email_to == null || fn_to == null || ln_to == null || email_from == null || fn_from == null || ln_from == null || msg == null)   { ShowHidePanel('send_page_pannel', false); return; }
        
        if(!HasValue(fn_to,'send_page_pannel_title'))               return;
        if(!ValidEMailAddr('E_Mail_to','send_page_pannel_title'))   return;
        
        if(!HasValue(fn_from,'send_page_pannel_title'))             return;
        if(!ValidEMailAddr('E_Mail_from','send_page_pannel_title')) return;

        if(msg.value.length > 200)  { DispErrMsg('The Message is too long', 'send_page_pannel_title'); return; }
        
        // ask jack to send the image:    
        if(jack_count != 0) { DispErrMsg('Communication conflict. Please try again.', 'errMsgSpan'); return; }
        
        ShowHidePanel('send_page_pannel', false);

        LockScreen(true);   // lock screen to prevent double calls
        
        attributes += ('&eato=' + ProcessInput(email_to.value)); 
        attributes += ('&fnto=' + ProcessInput(fn_to.value)); 
        attributes += ('&lnto=' + ProcessInput(ln_to.value)); 

        attributes +=  ('&eafr=' + ProcessInput(email_from.value)); 
        attributes += ('&fnfr=' + ProcessInput(fn_from.value)); 
        attributes += ('&lnfr=' + ProcessInput(ln_from.value)); 

        attributes += ('&msg=' + ProcessInput(msg.value)); 

        LoadJack(attributes);
        
        jack_wt = window.setTimeout("GetMailSentConfirmation()", jack_timeout);
    	
    }	// ------------------------------------------------------    

    function GetMailSentConfirmation()
    {
        jack_count++;    
        if(jack_count > jack_limit) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen  
            DispMailMessage('Error sending message.<br/>Please check the e-mail address.');
        }
        else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen 
            DispMailMessage(jack_status.replace('error: ',''));
            jack_status = '';
        }
        else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
        {
            if(jack_send != '')
            {
                DispMailMessage(jack_send);
            }
            else { ClearMailMessage(); }
            
            jack_count = 0;
            LockScreen(false);  // unlock screen 
        }
        else
        {
            jack_wt = window.setTimeout("GetMailSentConfirmation()", jack_timeout);
            ClearMailMessage();       
        }
    }

// -->