/*
c. jeremy van winkle. 2008 - brothers van winkle  -> www.brothersvanwinkle.com
*/

        
 

// ROLLOVER FUNCTIONS    style.color/backgroundcolor
//#################################################
function highlight(element,instance,color_on,name){
 if (name > 0){ 
    for (var n = 1; n < name; n++){ 
        var div = document.getElementById(element + n);
            if( div != null){
                 if (instance=='0'){     
                        div.style.color = color_on;
                 }else if (instance=='1'){          
                        div.style.backgroundColor = color_on;  
                 }
            }
        }
    var n = 1
 }else{
        var div = document.getElementById(element);                                    
        if (instance=='0'){     
                div.style.color = color_on;
         }else if (instance=='1'){    
                div.style.backgroundColor = color_on;  
         }
    }
}
    
    
     
function de_highlight(element,instance,color_off,name){ 
 if (name > 0){ 
    for (var x = 1; x < name; x++){ 
        var div = document.getElementById(element + x);
            if( div != null){
                 if (instance=='0'){     
                        div.style.color = color_off;
                 }else if (instance=='1'){    
                        div.style.backgroundColor = color_off;  
                 }
            }
        }
     var x=1;
}else{
        var div = document.getElementById(element);  
        if (instance=='0'){ 
                div.style.color = color_off;  
         }else if (instance=='1'){      
                div.style.backgroundColor = color_off;
         }
    }
}





 
// ROLLOVER FUNCTIONS    image swap
//#################################################

function rollover(element,image_on){ 
        var div = document.getElementById(element); 
        div.src = image_on;        
}    

function rollout(element,image_off){ 
        var div = document.getElementById(element); 
        div.src = image_off;        
}    



function rollover_td(element,image_on){ 
        var div = document.getElementById(element); 
        div.style.backgroundImage="url("+image_on+")";        
}    

function rollout_td(element,image_off){ 
        var div = document.getElementById(element); 
        div.style.backgroundImage="url("+image_off+")";        
} 


function cursor_hand() {
document.body.style.cursor = 'pointer';
}

function cursor_clear() {
document.body.style.cursor = 'default';
}

 
  //toolbox functions
function open_window(URL,w, h, n, t,l,d,st,m,sc,r){   
    var win =window.open(URL, n,"toolbar="+t+",loaction="+l+",directories="+d+",status="+st+",menubar="+m+",scrollbars="+sc+",resizeable="+r+",width="+w+", height="+h+"");
    win.focus();
}
 

function close_window(){   
    window.close();
}

function close_refresh_window(){   
    window.close();              
    window.opener.location.reload();  
}
function js_logout(URL,mywindow){
        if(mywindow == '0'){ 
            js_redirect(URL);                 
        }else{               
            //mywindow.opener.location.assign(URL);
            window.close();
            window.opener.location = URL;  
            window.opener.focus();       
        }
}
 function print_me(element) {
       var div =document.getElementById(element);                                                           
       div.print();
  }

 function addslashes(str) {
        str=str.replace(/\'/g,'\\\'');
        str=str.replace(/\"/g,'\\"');
        str=str.replace(/\\/g,'\\\\');
        str=str.replace(/\0/g,'\\0');
    return str;
}
function stripslashes(str) {
        str=str.replace(/\\'/g,'\'');
        str=str.replace(/\\"/g,'"');
        str=str.replace(/\\\\/g,'\\');
        str=str.replace(/\\0/g,'\0');
    return str;
}
// RE-DIRECT USERS

function js_redirect(URL){
    window.location = URL;
}


//frames
function get_frame(frame_id,frame_number,project_id,board_id,page,window) {     
 //var URL =  page+'?page=frame_display&project_id='+project_id+'&board_id='+board_id+'&frame_id='+frame_id+'&frame_number='+frame_number;            
 var URL =  page;            
         if(window == '1'){     
        open_window(URL,'800','800','_blank',0,0,0,0,0,1,1);
     }else{
        js_redirect(URL);
     }
}

 
//frames
function get_frame2(frame_id,frame_number,project_id,board_id,page,window) {     
 var URL =  page+'?page=frame_display&project_id='+project_id+'&board_id='+board_id+'&frame_id='+frame_id+'&frame_number='+frame_number;            
 //var URL =  page;            
         if(window == '1'){     
        open_window(URL,'800','800','_blank',1,0,0,0,1,1,1);
     }else{
        js_redirect(URL);
     }
}

                
             
function numbersonly(e, decimal, id) {
    var key;
    var keychar;

    if (window.event) {
       key = window.event.keyCode;
    }else if (e) {
       key = e.which;
    }else {
       return true;
    }
    keychar = String.fromCharCode(key);

    if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
       return true;
    }else if ((("0123456789").indexOf(keychar) > -1)) {
       return true;
    }else if (decimal && (keychar == ".")) { 
        var str = document.getElementById(id).value;        
        var substrings = str.split('.');
        var instances = substrings.length; 
        //alert (instances);  
        if( instances > 1 ){
            return false;
        }
        return true;
    }else{
       return false;
    }
}

function roundNumber(num, dec) {
    var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
    return result;
}



    /*
    ################################################################################
    DropDown Menus
    ################################################################################
    */                
// open menu
function mopen(id){    
    menuitem = document.getElementById(id);
    menuitem.style.visibility = 'visible';
}


// close menu
function mclose(id){
    menuitem = document.getElementById(id);
    if(menuitem) menuitem.style.visibility = 'hidden';
}


  

                   
function sleeper(timer){ 
    var sleeper_t;                    
    sleeper_t = setTimeout("",timer);
    clearTimeout(sleeper_t);
    return;
}
                   
                   
                   
function toggleDiv(divid, img){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
      if( img !== '0'){
        document.getElementById(img).src = "http://www.visualstoryline.com/images/display/buttons/minus.gif";  
      }
    }else{
      document.getElementById(divid).style.display = 'none';
      if( img !== '0'){
        document.getElementById(img).src = "http://www.visualstoryline.com/images/display/buttons/plus.gif";  
      }
    }
    
}


function changeBackgroundColor(id, color){    
    document.getElementById(id).style.backgroundColor = color;
}


//SAMPLES PAGES  
function openSamplePicture(URL,Image,width,height){                                  
    open_window(URL+'?image='+Image,width,height,'sample image',1,0,0,0,1,1,1);
}