
function pGetPath(){
   	var arr=window.location.toString().match(/(.*)\/(.*)/);
   	var filearr=arr[2].split("?");
    var filename=filearr[0], getstr="";
   	if(filearr.length>1){   	    
   	    getstr=filearr[1];
   	}
   	return {baseurl:arr[1],filename:filename,getstring:getstr};
}
//appends the getstring of current document to the url
function pAppendDocumentGetString(url){
   	var obj=pGetPath();
	var getstring=obj.getstring;
	if(getstring.length>0){
		if(url.indexOf("?") != -1){
			url=url+"&"+getstring;
		}
		else{
			url=url+"?"+getstring;
		}
	}
	return url;
}
function pHeight(ele){
	var ht=ele.style.height;
	//llog("ht="+ht);
	var arr=ht.match(/([\d]+)/);
	return parseInt(arr[1]);
	//llog("pheight="+arr[1]);
}
function pWidth(ele){
	var wt=ele.style.width;
	var arr=wt.match(/([\d]+)/);
	return parseInt(arr[1]);
}

function pTrim(str)
{
	if(str){
		str=str.replace(/^[\s]+/,'');
		str=str.replace(/[\s]+$/,'');/*\s includes newlines*/
		//str=str.replace(/[\\r\\n]+/,'');
	}
	else{
		return "";
	}
	//debug("str length after is "+ str.length);
	return str;
}
function pIsNumeric(str){
	if(str.search(/[\D]+/)==-1)return true;
	return false;
}
//return s extension of files
function pGetExt(name){
	var arr=name.split(".");
	return arr[arr.length-1];
} 

function pGetAttribute(ele,sAtt){
	if(ele==null){
		return false;
	}
	try{
		var a=ele.getAttribute(sAtt);
		if(!a){
			a=ele[sAtt];
		}
	}
	catch(e){
		return false;
	}
	if(typeof(a)=="string"){
		return a;
	}
	else
		return "";//it's preferable to use over false as return value
}
function $(id){
	return document.getElementById(id);
}
function $F(formname){
	return document.forms[formname];
}
function toggle(id){
	if($(id).style.display=="none"){
		$(id).style.display="block";
	}
	else{
        $(id).style.display="none";
	}
}
Array.prototype.indexOf=function(val){
	var a =this,l=a.length;
	for(var i=0; i<l;i++){
		if(a[i]==val){
			return i;
		}
	}
	return -1;
}

Array.prototype.unique=function(){
	var a=this;b=[],len=a.length;
	
	for(var i=0;i<len;i++){
		if(b.indexOf(a[i])<0){
			b.push(a[i]);	
		}
	}
	return b;	
}
		

function paniClip(node,left,top,width,height,origin){
	var me=this;
	var $=xGetElementById;
	var ele=$(node);
    var path_image="include_files/images/";
	if(pGetAttribute(ele,"clipping")){
		//alert("clipping");
		return;
	}
	ele.style.position="absolute";
	ele.style.top=top+"px";
    ele.style.left=left+"px";
    ele.style.width=width+"px";
    ele.style.height=height+"px";
	ele.style.display="none";
	document.body.appendChild(ele);
	var lt=left;
	var tp=top;
	var ht=height+4;
	var wt=width+4;

	if((origin=="")||(origin=="lt")){
		origin="lt";
	}
	/*else if(origin=="tr"){
		xLeft(ele,iniX-wt);
		xTop(ele,iniY);
	}
    else if(origin=="rb"){
		xLeft(ele,iniX-wt);
		xTop(ele,iniY-ht);
	}
    else if(origin=="bl"){
		xLeft(ele,iniX);
		xTop(ele,iniY-ht);
	}
	//alert(iniX+" and "+iniY);
	/*if(ele.style.display=="none"){
		ele.style.display="";
	}*/
	var cclose=document.createElement("div");
	var _rand=Math.random();
	cclose.id="close"+_rand;
	cclose.innerHTML="<img src="+path_image+"close.gif style='cursor:pointer;'>";
	ele.insertBefore(cclose,ele.firstChild);
    cclose.onclick=function(){
		me.hidee();
	}
	cclose.setAttribute("style","float:right");//for FF
    cclose.style.styleFloat="right";//for IE
	cclose.style.color="white";

	var timer=setInterval(clipp,50);
	ele.setAttribute("clipping","true");
	var xincr=yincr=0;
	function clipp(){
		xincr=xincr+20;
        //console.log(xincr);
		yincr=xincr*ht/wt;
		yincr=Math.round(yincr);
		//console.log(yincr);
		if(origin=="lt"){
        	xClip(ele,0,xincr,yincr,0);
		}
		else if(origin=="tr"){
			xClip(ele,0,wt,yincr,(wt-xincr));
		}
        else if(origin=="rb"){
			xClip(ele,(ht-yincr),wt,ht,(wt-xincr));
		}
        else if(origin=="bl"){
			xClip(ele,(ht-yincr),xincr,ht,0);
		}
		if(ele.style.display=="none"){
			ele.style.display="";
		}
		if(xincr>wt){
			clearInterval(timer);//alert(ele.innerHTML);
			ele.setAttribute("clipping","");
		}
	}
	this.hidee=function(cb_fn){
		//ele.style.display="none";
		var parnode=ele.parentNode;
		if(typeof cb_fn=="function"){
			cb_fn();
		}
		parnode.removeChild(ele);
	}
}
function pFrameDocument(frameNode){
	var frm=frameNode;
	var fdoc=(frm.contentWindow || frm.contentDocument||frm.document);
	if(fdoc.document){
		fdoc=fdoc.document;
	}
	return fdoc;
}

function pHeightFrame(doc){
	if(document.all){
		return doc.body.scrollHeight;//scrollheight for IE
	}
	else{
		return doc.body.offsetHeight;//mozilla
	}
}
//cookie->TinyMCE_mce_editor_0_width=759; TinyMCE_mce_editor_0_height=373; left=54px; top=37px; width=351px; height=508px;
function pGetCookie(name){
	var value=null,dc=document.cookie;
	//debug("dc= "+dc);
	if(dc.length>0){
		var search=name+"=";
		var re=new RegExp("(\;|\\s)+"+search);
		var arr=dc.match(re);//returns null if no match
		if(!arr){
			re=new RegExp("^"+search);//may be at beginning of cookie
			arr=dc.match(re);//returns null if no match
		}
        //debug("re= "+re.toString()+"arr= "+arr);
		if(arr){
			var offset=dc.indexOf(arr[0]);
			var sIndex=offset+arr[0].length;
			var eIndex=dc.indexOf(";",sIndex);
			//debug("eindex= "+eIndex);
			if(eIndex==-1){//in IE if last name=value pair
				eIndex=dc.length;
			}
			value=dc.substring(sIndex,eIndex);
		}
	}
	return value;
}

function pBookmark()
{
    var title = document.title;
	//alert(arr[1]);
	
	var url=window.location;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external ) { // IE Favorite
    //else if( parent.external ) { // IE Favorite
		window.external.AddFavorite( url, title);
        //parent.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print) { // Opera Hotlist
		return true;
	}
	else
	{
		alert("You can bookmark this page manually through your browser");
	}
}
