/* 
	modificat: serban - 29 apr 09
*/

$(document).ready(function() {   
    var host = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$3$4');
    var subdomain = window.location.host.replace(/^(([^\/]+?\.)*)([^\.]{4,})((\.[a-z]{1,4})*)$/, '$1');

    if (subdomain == 'www.' || subdomain == '') 
      var subdomains = "(www\.)?";    
    else var subdomains = subdomain.replace(".", "\.");   
    
    var regexp_intern = "^https?://(" + subdomains + host+"|blog.avangate.com|secure.avangate.com)";
    var internal_link = new RegExp(regexp_intern, "i");

    var external_links = new Array();
    $("a").each(function(el) {
      try {
        var url = this.href.toLowerCase();
        if (url.indexOf('http') == 0 && !url.match(internal_link)) 
          external_links.push(this);       
      }     
      catch(error){return false;}
    });

    $links = $(external_links);
    $links.not(':has(img)').append("&nbsp;<sup><img class='external_link' src='http://www.avangate.com/images/external.png' border='0' alt=''></sup>");
});



var google_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');

function highlight_keywords(terms){	
	var c			=	0;
	var found_keys 	= 	new Array();	
	var el = document.getElementById('container');
	
	for(var i=0; i<terms.length; i++){				
		highlightTree(el, terms[i],google_link_colors[c]);
		c = (c == google_link_colors.length-1)?0:c+1;
	}
}

function highlightTree(el,term,color){	
    var matchIndex = 1;		
	for(var startIndex=0, endIndex=el.childNodes.length; startIndex<endIndex; startIndex++) {
		var item = el.childNodes[startIndex];
		if ( item.nodeType != 8 ) {
			if(item.nodeType==3) {
				var text = item.data;
				var newtext="",match,index=0,ind ;				
				 
				ind = text.toLowerCase().indexOf(' '+term.toLowerCase()+' ');
					
				if(ind>=0){ 
					newtext = text.substr(0,ind+1)+'<span style="background-color:'+color+'">'+text.substr(ind+1,term.length)+'</span>'+text.substr(ind+1+term.length);
					var repl = $.merge([],$("<span>"+newtext+"</span>")[0].childNodes);
	                endIndex += repl.length-1;
	                startIndex += repl.length-1;	                            
	                $(item).before(repl).remove();				
				}				
			}else if(item.nodeType==1  && item.tagName.toLowerCase() != 'textarea' )highlightTree(item,term,color);            
		}
	}	
	return;   
}


function openImgWindow(width,height,url) {
	var pag=window.open('/assets/openw.html','','menubar=yes,scrollbars=no,width='+width+',height='+height);
	var htmlS="<img src='"+url+"'>";
	pag.onload=function() {
		pag.document.body.innerHTML=htmlS;
	};
}

function popUpImg(width,height,imgUrl,scrlbar) {	
	if(scrlbar != 'yes') scrlbar = 'no';	
	var popup_tmp = window.open('/assets/popupimg.php?imgUrl='+imgUrl,'tmp','menubar=no,scrollbars='+scrlbar+',width='+width+',height='+height);
}

function printPage()
{
	/*try
	{
		var content = document.getElementById("maincontent").innerHTML;
		var frm=window.parent.framePrnt;
		var destObj=frm.document.getElementById("result");
		destObj.innerHTML = "<img src=\"../images/logo.gif\">" + "<hr>" + content;
		frm.focus();
		frm.print();
	}
	catch(e)
	{
		self.print();
	}*/
	self.print();
}
function changeMenu(obj, cls)
{
	window.offscreenBuffering = true;
	if(cls=="mainmenuover")
	{
		obj.style.backgroundPosition='bottom';
	}
	else
	{
		obj.style.backgroundPosition='top';
	}
	
	//obj.className=cls;
}

function bookmarkPage(title, url){
	netscape = "Netscape and Firefox User's hit CTRL+D to add a bookmark to this site.";
	sorry	 = "Sorry! Your browser doesn't support this function.";
	if (window.external) {
	window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape') {
	   //	window.sidebar.addPanel(title, url, "")
	   alert(netscape);
	} else { 
	   alert(sorry);
	}
 }
 
 function MinipollValidate(obj,objType) {
 	valid=false;
 	for(i=0;i<obj.length;i++) {
 		if(obj[i].name!="sendMinipoll") {
 			valid=(obj[i].checked);
 			if(valid) break; 			
 		}
 	}
 	if(!valid) {
 		if(objType=="radio")alert("Please select one answer from the minipoll");
 		else alert("Please select at least one answer from the minipoll"); 		
 	}
 	return valid;
 }
 
 function basename(path, suffix) {   
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}