﻿<!--
// 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 timeout_ms = 100;  
    var jack_row_id = 0;
    
    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);
        
        window.setTimeout('GetVoteConfirmation()', timeout_ms);
    }

    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
            if(jack_vote != 0)
            {
                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;
                }
                else { alert('');}
                
                DispErrMsg('Vote accepted. The Rating will be changed in a few minutes.','errMsgSpan');
            }
            else DispErrMsg('','errMsgSpan');
            
            jack_row_id = 0;
            jack_count = 0;
            LockScreen(false);  // unlock screen 
        }
        else
        {
            window.setTimeout("GetVoteConfirmation()", timeout_ms);       
        }
    }

    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
        {
            window.setTimeout("GetMailImageConfirmation()", timeout_ms);
            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  = parseInt(document.body.clientWidth) - 20;
                shield.style.height = 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)
    {
        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;
        
        if(top   != '') p.style.top  = top;
        if(left  != '') p.style.left = left;
        if(title != '') t.innerHTML  = title;
        if(msg   != '') m.value      = msg;

        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;
        }

        ShowHidePanel('send_page_pannel', true);
    }
    
    function SendPageToFriend()
    {
        ShowCustomEMailPannel('', '', 'Send Page to Friend:', '');
    }

    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  = parseInt(document.body.clientWidth) - 20;
                shield.style.height = parseInt(document.body.clientHeight) - 10;
                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);

        window.setTimeout("GetMailSentConfirmation()", timeout_ms);
    	
    }	// ------------------------------------------------------    

    function GetMailSentConfirmation()
    {
        jack_count++;    
        if(jack_count > jack_limit) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen  
            DisplayMessage('Error sending message.<br/>Please check the e-mail address.','mailMsgBoard', true);
        }
        else if(typeof jack_status !== 'undefined' && jack_status.indexOf('error: ') >= 0) 
        {
            jack_count = 0;
            LockScreen(false);  // unlock screen 
            DisplayMessage(jack_status.replace('error: ',''),'mailMsgBoard', true);
            jack_status = '';
        }
        else if(typeof jack_status !== 'undefined' && jack_status == sent_status)
        {
            if(jack_send != '')
            {
                DisplayMessage(jack_send,'mailMsgBoard', true);
            }
            else { DisplayMessage('','mailMsgBoard', false); }
            
            jack_count = 0;
            LockScreen(false);  // unlock screen 
        }
        else
        {
            window.setTimeout("GetMailSentConfirmation()", timeout_ms);
            DisplayMessage('','mailMsgBoard', false);       
        }
    }

// -->