// JavaScript Document

var debugMode=1;
var currentPageUrl = window.location.href;

var j = jQuery.noConflict();

function isParent(child, parent, ceil){
	var returnIsParent=false;
	if(ceil==undefined){
		ceil = document.body;
	}
	if(child==parent)return false;
	
	var theParent = child;
	while(theParent && theParent.childNode!=ceil){
		if(theParent == parent){
			returnIsParent = true;
			break;
		}
		theParent = theParent.parentNode;
	}
	/*console.log("===============================");
	console.log(child);
	console.log(parent);	
	console.log(returnIsParent);*/
	return returnIsParent;	
}


function getNodeHtml(el){
    var returnHtml = "";
    var nodeHtml = "";
    //wrap element then get wrapper's contents
    jQuery(el).wrap("<div id='tmpGetNodeHtml'></div>");
    nodeHtml = jQuery(el).parent().html();
    returnHtml += nodeHtml;
    //remove wrapper and reset element
    jQuery(el).parent().replaceWith(nodeHtml);  
    return returnHtml;
}



if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

if (!console) {
	var console = {
		log: function(msg){
			//alert console.log messages if console.log does not exist
			if(debugMode>0)
				alert(msg);
		}
	};
}

function localTrace(msg, priority){
	if(priority==null){
		priority=1;
	}
	if(debugMode>=priority){
		try{
			console.log(msg);
		}catch(ex){
			//alert(ex.message);	
			alert(msg);
		}
	}
}

function xString(str, num){
	if(num<=0)return "";
	
	var tmpStr = str;
	while (num>0) {
		tmpStr += str;
		num--;
	};
	return tmpStr;
}


function toInt(x){return(x>0?Math.floor(x):Math.ceil(x));}