// JavaScript Document
function isValidEmail(strEmail){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

    // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) {
        return false;
    }
    return true;
}
function showregmessage(html,  left, top,width, height) {
    alert(html);
}
//"4px solid #000"
function creatediv(id, html,  left, top,width, height,color,borderstyle) {

    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', id);

    if (width) {
        newdiv.style.width = width;
    }

    if (height) {
        newdiv.style.height = height;
    }

    if ((left || top) || (left && top)) {
        newdiv.style.position = "absolute";

        if (left) {
            newdiv.style.left = left;
        }

        if (top) {
            newdiv.style.top = top;
        }
    }

    newdiv.style.background = color;
    newdiv.style.border = borderstyle;

    if (html) {
        newdiv.innerHTML = html;
    } else {
        newdiv.innerHTML = "nothing";
    }

    document.body.appendChild(newdiv);

}
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
// EXTJS GUI functions
function vclPanelToExtPanel(vclPanel,panelTitle,layoutName,autoCollapsible) {
    if (layoutName==null){layoutName='fit';}
    if (autoCollapsible==null){autoCollapsible=true;}
    var xx=new Ext.Panel({
            //applyTo:'Panel1_outer',
            contentEl:vclPanel+'_table',
            //region: 'center',
            title:panelTitle,
            collapsible:autoCollapsible,
            scripts:true,
            split: true,
            layout:layoutName
            //width:800,
            //height:320
            //renderTo:Ext.getBody()
            //closeAction:'close',
            //plain: true

        });
    xx.applyToMarkup(vclPanel+'_outer');
}
/* panels functions */
function vp_shd(vclPanel,title) {
 var html='<div class="sidebox">'+
          '<div class="boxhead"><h2>'+title+'</h2></div>'+
          '<div id="'+vclPanel+'_panel" class="boxbody">'+
          '</div>';
 var addTo=$('#'+vclPanel+'_table')[0];
 if (addTo!=null)
 {
  var ohtml=$(html);
  ohtml.insertBefore(addTo);
  $('#'+vclPanel+'_table').appendTo('#'+vclPanel+'_panel');
 }

}
function vp(vclPanel,title) {
 var html='<div class="cornerBox">'+
          '<div class="corner TL"></div>'+
          '<div class="corner TR"></div>'+
          '<div class="corner BL"></div>'+
          '<div class="corner BR"></div>'+
          '<div class="cornerBoxInner">'+title+
          '</div>'+'</div>';
 var addTo=$('#'+vclPanel+'_table')[0];
 if (addTo!=null)
 {
  var ohtml=$(html);
  ohtml.insertBefore(addTo);
 }

}

function extPanelFromUrl(vclPanel,panelTitle,layoutName,autoCollapsible,url) {
    if (layoutName==null){layoutName='fit';}
    if (autoCollapsible==null){autoCollapsible=true;}
    var xx=new Ext.Panel({
            //applyTo:'Panel1_outer',
            contentEl:vclPanel+'_table',
            //region: 'center',
            title:panelTitle,
            collapsible:autoCollapsible,
            scripts:true,
            split: true,
            layout:layoutName,
            autoLoad:url
            //width:800,
            //height:320
            //renderTo:Ext.getBody()
            //closeAction:'close',
            //plain: true

        });
    xx.applyToMarkup(vclPanel+'_outer');
}
function loadApp(vclPanel,panelTitle,layoutName,autoCollapsible,url) {
    if (layoutName==null){layoutName='fit';}
    if (autoCollapsible==null){autoCollapsible=true;}
    var xx=new Ext.Panel({
            //applyTo:'Panel1_outer',
            applyTo:vclPanel+'_table',
            //region: 'center',
            title:panelTitle,
            collapsible:autoCollapsible,
            scripts:true,
            split: true,
            layout:layoutName,
            html:'<iframe src="'+url+'" width="600" height="600"/>'
            //width:800,
            //height:320
            //renderTo:Ext.getBody()
            //closeAction:'close',
            //plain: true

        });
    //xx.applyToMarkup(vclPanel+'_outer');
}

function getPanels(panels) {
    var xx=new Array();
    for(i=0;i<panels.length;i++) {
        xx[i]=new Ext.Panel({
            applyTo:panels[i][0]+'_outer',
            contentEl:panels[i][0]+'_table',
            region:panels[i][1],
            title:'test',
            collapsible:true,
            split: true,
            scripts:true,
            layout:'fit'
            //width:800,
            //height:320
            //renderTo:Ext.getBody()
            //closeAction:'close',
            //plain: true

        });



    }
    return xx;
}
/*function getPanels(panels)
{
    var xx=new Array();
    for(i=0;i<panels.length;i++) {
        xx[i]=new Ext.BoxComponent({
            height: 300, // give north and south regions a height
            region: panels[i][1],
            items:[
            new Ext.Panel({
                applyTo:panels[i][0]+'_outer',
                contentEl:panels[i][0]+'_table',

                title:'test',
                collapsible:true,
                split: true,
                scripts:true
                //layout:layoutName
                //width:800,
                //height:320
                //renderTo:Ext.getBody()
                //closeAction:'close',
                //plain: true

            })]});



    }
return xx;
    }*/

function testGUI(panels) {
    var viewport = new Ext.Viewport({
        //contentEl:Ext.getBody(),
        items:getPanels(panels),
        layout: 'border',
        scripts:true,
        anchorSize: {width:500, height:400},
        applyTo:'panelForm_outer'
    });
    //viewport.show();
    viewport.doLayout();
}
function showMessage(title,msg,msgType)
{
if (msgType==null)
{
 msgType='ext-mb-warning';
}
 Ext.MessageBox.show({
           title:title,
           msg:msg,
           buttons: Ext.MessageBox.OK,
           icon:msgType
       });
}
function unixTimeToTime(unixTime)
{
 var date = new Date(unixTime*1000);
 var time = date.getFullYear()+'-'+date.getMonth()+'-'+date.getDate()+
            ' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
 return time;

}
 function mysqlTimeStampToDate(timestamp) {
    //input has to be in this format: 2007-06-05 15:26:02
    var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1],parts[2],parts[3],parts[4],parts[5]);
  }
