/*-------------------------------------------------------------------------------------------
  Find [left,top] position of an element on page
-------------------------------------------------------------------------------------------*/
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function get_response_tag(tag,response)
{
	start_tag = "["+tag+"]";
	end_tag   = "[/"+tag+"]";
	spos=response.indexOf(start_tag);
	epos=response.indexOf(end_tag);
    
    if (spos == -1) {
     start_tag = "[" + tag.toUpperCase() + "]";
     spos=response.indexOf(start_tag);
    }
    
    if (epos == -1) {
     end_tag = "[/"+tag.toUpperCase()+"]"
     epos=response.indexOf(end_tag);
    }
        
    if(spos!=-1 && epos!=-1){
		return response.substr(spos+start_tag.length,epos-spos-start_tag.length);
	}
    
	return "";
}

function cntChars(Object,maxlength)
{
  counter = $("n"+Object.name);
  txt     = Object.value;
  if(txt.length>maxlength) {
	    txt = txt.substr(0,maxlength);
   		Object.value = txt;
   		Object.scrollTop = Object.scrollHeight;
	}
  counter.innerHTML = maxlength - txt.length;
}




function focusF(Object)
{
 Object.className='focus';
}
function blurF(Object)
{
 Object.className='';
}
modalObject  = null;
dialogObject = null; 
loaderObject = null;


function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

function init()
{
	
   //if(crt_action=='edit' && crt_section=='links') update_anchors();
}
//window.onload   = init;
//window.onresize = repositionDialog;

function status(target,msg){
    if($("#status-message").length>0) return;
    e = document.createElement('div');
    e.id = 'status-message';
    document.body.appendChild(e);
    e.innerHTML = msg;

    if (target!=''){
        
        pos = $("#"+target).position(); //get the target position
        xpos = parseInt($("#"+target).width()/2 - e.offsetWidth/2)+pos.left;
        ypos = parseInt($("#"+target).height()/2 - e.offsetHeight/2)+pos.top;
           
    }else{
        
        xpos = parseInt((document.body.offsetWidth/2)-(e.offsetWidth/2));
        ypos = parseInt((document.body.offsetHeight/2)-(e.offsetHeight/2));
        
    }

    e.style.top = ypos + 'px';
    e.style.left = xpos + 'px'; 
    e.style.visibility = 'visible'; 
    $("#status-message").fadeTo('slow',1,function(){
        $("#status-message").fadeTo('slow',0,function(){
           e = document.getElementById('status-message');
      document.body.removeChild(e);   
        });
      
    });
}


function show_loading(target){
    if($("#loading-ticker").length>0) return;
    e = document.createElement('div');
    e.id = 'loading-ticker';
    document.body.appendChild(e);
    e.innerHTML = '<img src="'+siteurl + '/public/images/ajax-loader.gif"/>';

    if (target!=''){
        
        pos = $("#"+target).position(); //get the target position
        xpos = parseInt($("#"+target).width()/2 - e.offsetWidth/2)+pos.left;
        ypos = parseInt($("#"+target).height()/2 - e.offsetHeight/2)+pos.top;
           
    }else{
        
        xpos = parseInt((document.body.offsetWidth/2)-(e.offsetWidth/2));
        ypos = parseInt((document.body.offsetHeight/2)-(e.offsetHeight/2));
        
    }

    e.style.top = ypos + 'px';
    e.style.left = xpos + 'px'; 
    e.style.visibility = 'visible'; 
    
}
function hide_loading(){
  
    //$("#loading").hide();
    e = document.getElementById('loading-ticker');
    document.body.removeChild(e);
    
}
