/* 
Content Management System v1
 * Didin Nurdin <didin@transformatika.com>
 * http://transformatika.com
 */

function Delete_Confirm(url){
    if(confirm("Apakah anda yakin data yang dipilih akan dihapus?")){
        redirect(url);
    }else{
        return false;
    }
}

function redirect(url){
    document.location.href = url;
}

function generateMenu(t,actionlist,event){
     /*actionList = [
         ['<b>Edit</b>','alert("Edit");',"b_edit.png"],
         ['<b>Edit2</b>','alert("Edit");',"b_delete.png"],
         ['<b>Edit3</b>','alert("Edit");',"b_other.png"],
         ['<b>Edit4</b>','alert("Edit");',"b_edit.png"]
     ];
    */
    var x = (event.pageX) ? event.pageX - 10 : event.screenX - 10;
    var y = (event.pageY) ? event.pageY - 10 : event.screenY - 160;
    topPos  = y + 'px';
    leftPos = x + 'px';
    numArray = actionList.length;
    html = '<table id="tlayerMenu" cellpadding="2" cellspacing="2">';
    for(i=0;i<numArray;i++){
        html+= '<tr style="cursor:pointer;" onmouseover="this.bgColor=\'#CFCFCF\'" onmouseout="this.bgColor=\'\'" onclick="'+ actionList[i][1] +'"><td style="padding:1px 2px 1px 2px;"><img src="' + TEMPLATES_PATH + 'images/button/' + actionList[i][2] + '" /> '+ actionList[i][0] +'</td></tr>';
    }
    html+= '</table>';
    newLayer = document.createElement('div');
    document.body.appendChild(newLayer);
    newLayer.id = 'layerMenu';
    myLayer = document.getElementById('layerMenu');
    myLayer.style.background = '#FBEC88';
    myLayer.style.opacity = '0.1';
    myLayer.style.zIndex = 300000;
    myLayer.style.position = 'absolute';
    myLayer.style.top = topPos;
    myLayer.style.left = leftPos;
    myLayer.innerHTML = html;
    jQuery("#layerMenu").animate({opacity:1.0},1000).show();
    myLayer.onmouseout = function(){
        jQuery("#layerMenu").hide();
    }
    myLayer.onmouseover = function(){
        jQuery("#layerMenu").show();
    }
    //t.innerHTML = '<img src="'+ TEMPLATES_PATH +'images/button/b_other2.png" style="border-bottom:1px solid black;border-left:1px solid black;"/>';
}

function createLayer(url){
    newLayer = document.createElement('div');
    document.body.appendChild(newLayer);
    newLayer.id = 'layerContainer';
    jQuery("#layerContainer").css({
        width:0,
        height:0,
        opacity:0.0,
        background:'yellow',
        position:'absolute',
        top:0,
        left:0,
        zIndex:50000
    }).animate({opacity:0.5,width:jQuery(window).width(),height:jQuery(document).height()},1000);
    popup(url);
    //document.location.href='#layerContainer';
}

function popup(url){    
    newLayer = document.createElement('div');
    document.body.appendChild(newLayer);
    newLayer.id = 'layerPop';    
    jQuery("#layerPop").css({
        background:'#FFFFFF',
        position:'absolute',
        top:150,
        width:500,
        zIndex:50001,
        opacity:0.1,
        border:'1px solid #CFCFCF',
        padding:'5px 5px 5px 5px'
    }).load(url);

    var center = (jQuery(window).width() /2) - 250;
    jQuery("#layerPop").css({
        left:center
    }).animate({opacity:1.0},1000);
}

function removeLayer(){
    jQuery("#layerPop").remove();
    jQuery("#layerContainer").animate({opacity:0.0,width:0,height:0},1000);
    //jQuery("#layerContainer").animate({opacity:0.0,width:0,height:0},2000).remove();
}

function deleteConfirm(url){
    if(confirm("Apakah anda yakin, data yang dipilih akan dihapus?")){
        document.location.href = url;
    }
    return false;
}
function isValidEmail(email){
   if (email.match("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[a-zA-Z]{2,4}$")){
       return true;
   } else {
       return false;
   }
}

function isValidURL(url){
   if (url.match("^(.*)+\.[a-zA-Z]{2,4}$")){
      return true;
   }else{
      return false;
   }
}

function redirect(url){
    document.location.href = url;
}



