/*
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 printMeWindowOld(id,action){
    var div =document.getElementById(id);         
    if(div !== null ){
        var text = div.innerHTML;                                                           
        //open_window(URL,w, h, n, t,l,d,st,m,sc,r)
        printWindow = window.open("", "printWindow", "status=1,width=500,height=500");        
        printWindow.document.write(text);
        if(action == 'print'){
            printWindow.print();
        }
    }else{
        alert('could not find data to print');
    }
}

function printMeWindow(id,action,windowTitle){
    var div =document.getElementById(id);         
    if(div !== null ){
        var data = div.innerHTML;
        printWindow = window.open("", windowTitle, "status=1,width=500,height=500");
        
        
        printWindow.document.write('<html><head><title>'+windowTitle+'</title></head><body><div id="data">');
        printWindow.document.write('</div></body></html>');

        
        var dataDiv = printWindow.document.getElementById('data');
        dataDiv.innerHTML = data;
        
        //printWindow.document.write(text);
        if(action == 'print'){
            printWindow.print();
        }
        printWindow.focus();
    }else{
        alert('could not find data to 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 numbersonlyOLD(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 numbersonly(e, decimal, id) {
    var key;
    var keychar;                                      
    var str = document.getElementById(id).value;  
         
    if (window.event) {
       key = window.event.keyCode;
    }else if (e) {
       key = e.which;
    }else {
       return true;
    } 
    keychar = String.fromCharCode(key);

    
    var allowedKeys=new Array(0,8,9,10,11,12,13,27,28,29,30,31);
    var allowedCtlKeys=new Array(82);
    if ((key==null) || (findInArray(allowedKeys, parseInt(key)))  || (e.ctrlKey) || (e.altKey) ) {    
        return true;
    }else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;                      
    }else if ((decimal==true) && (keychar == ".")) {   
        var substrings = str.split('.');
        var instances = substrings.length;   
        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;
}

function stripAlphaChars(pstrSource) { 
    var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, '');
    return m_strOut; 
}


    /*
    ################################################################################
    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);
}


//add rows to tables                     
function addRow(tableID){
    var tbody = document.getElementById(tableID).getElementsByTagName("TBODY")[0];
    var row = document.createElement("TR");  
    i=1;      
    while(i<=18){
        var td = document.createElement("TD");
        td.appendChild(document.createTextNode(i));                  
        row.appendChild(td);
        i++;
    }                     
    tbody.appendChild(row);
}

 
//#################################################
// Created Public FUNCTIONS    
function findInArray(arr, obj) {
    for(var i=0; i<arr.length; i++) {
        if (arr[i] == obj) return true;
    }
    return false;
}               
//#################################################


