function openPhotoItems(photo) {
	InsertImages = window.open('/files/admin/html-editor/imagemanager?photo='+photo,"HTML_Editor","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, left=0, top=0, height="+(screen.availHeight-60)+" ,width="+(screen.availWidth+400)/2);
}

function resetPhotoItems(photo) {
document.getElementById(photo).value = '';
document.getElementById(photo+'_pic').src = '';	
}

function setImage(img) {
	document.getElementById('photo_id').value = img;
	document.getElementById('photo_id_pic').src='/files/th/'+img;
}

var s = -1;

function getNews(url,rightMenu,m,q){
	loc = "?newsFlag=1&getPage="+url;
	if (rightMenu == 0)	{
		loc = loc + "&hideRightMenu=1"
	}
	if (m)
		loc = loc + "&m="+m;
	if (q)
		loc = loc + "&q="+q;
	document.location = loc;
}
function getPage(url) {
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp==null) {
	alert ("Browser does not support HTTP Request");
	return;
 } 
 xmlHttp.onreadystatechange = loadPage;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function loadPage() {
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
	document.getElementById('text-body').innerHTML=xmlHttp.responseText;
	linkCourses();
 }
}

function checkChildren(node_id, locale, p_pac_id) {
 xmlHttp2=GetXmlHttpObject(); 
 if (xmlHttp2==null) {
	alert ("Browser does not support HTTP Request");
	return;
 }
 var url2 = "/getNodeChilds";
 url2 = url2 + "?parent_node_id=" + node_id;
 url2 = url2 + "&p_pac_id=" + p_pac_id;
 url2 = url2 + "&locale=" + locale;
 xmlHttp2.onreadystatechange = loadChildNodes;
 xmlHttp2.open("GET",url2,true);
 xmlHttp2.send(null);
}

function checkURL(link, id,pid) {
 if (link.indexOf('subsite') == 0) {
	window.location = link.substr(7);
 }  else if (link.indexOf('http://www.birzeit.edu/')!=-1) {
	var p_id = link.substr(link.lastIndexOf('edu/')+4);
	checkURL("../"+p_id);
 } else if (link.indexOf('http://') == 0) {
    window.location = link;
 } else if (link.indexOf('expand') == 0) {
     var p_id = link.substr(link.lastIndexOf('/')+1);
     var url_t = "?exp_node_id=" + id;
	 document.location = url_t;
 } else if (link.indexOf('programs') == 0) {
		if(link.indexOf('-ba') != -1) {
			document.location = "progs/?q=ba";
		} else if(link.indexOf('-dip') != -1) {
			document.location = "progs/?q=dip";
		} else if(link.indexOf('-min') != -1) {
			document.location = "progs/?q=min";
		} else if(link.indexOf('-prog') != -1) {
			document.location = "progs/?q=prog";
		} else {
			document.location = "progs/";
		}
 } else if (link.indexOf('mprograms') == 0) {
	document.location = "progs/?m=1";
 } else if (link.indexOf('p/dept-staff') != -1 || link.indexOf("p/heads")!=-1 || link.indexOf('p/dept-contact') != -1  || link.indexOf('p/heads/uni-president') != -1   || link.indexOf('p/heads/director') != -1  || link.indexOf('/pub_rel/p/') != -1  || link.indexOf('p/heads/dean') != -1  || link.indexOf('p/heads/vp-academic-affairs') != -1 || link.indexOf('p/heads/registrar') != -1 ) {
	document.location = "?hideRightMenu=1&newsFlag=1&getPage="+link;
 } else if (link.indexOf('/president') == 0) {
	if (link.indexOf('/president/res_dev/p/') == 0 ){
		var p_id = link.substr(link.lastIndexOf('/')+1);
		var url_t = "?sin_node_id=" + id ;
		if(pid) 
			var url_t = "?sin_node_id=" + id +"&exp_node_id="+pid  ;
		document.location = url_t;
	} 
	else
		document.location = link; // +"?flag=1";
 } else if(link.indexOf("p/dept-courses")!=-1 ||  link.indexOf("p/dept-staff")!=-1 || link.indexOf("p/heads/cheif-financial")!=-1 || link.indexOf("p/heads/dean")!=-1 || link.indexOf("p/heads/chairman")!=-1   || link.indexOf("p/dept-staff")!=-1  ){
		document.location = "?hideRightMenu=1&newsFlag=1&getPage="+link;
	} 
 else if (link.indexOf('/p') == 0 ){
	if(link.indexOf('p/prog?prog_id=') != -1)	{
		document.location = "?newsFlag=1&getPage="+link;
	}else{
	   var p_id = link.substr(link.lastIndexOf('/')+1);
	     var url_t = "?sin_node_id=" + id ;
		if(pid) 
			var url_t = "?sin_node_id=" + id +"&exp_node_id="+pid  ;
		 document.location = url_t;
	}
 } else if (link.indexOf('/employees/page_d') != -1 ){
	document.location = link;
 } else if((link.search(/[0-9 ]+$/)!= -1) || (link.search(/progs$/)!= -1)|| (link.search(/contact$/)!= -1) ){
	var p_id = link.substr(link.lastIndexOf('/')+1);
	 document.location = "?prog_list="+p_id;
 } else {
	document.location = link;
 }
}

function progDisp(progId) {
	var loc = "" + document.location;
	if (loc.charAt(loc.length -1 ) == '/') {
		document.location = "?disp_prog_id=" + progId;
	} 
	else {
		if (loc.indexOf('disp_prog_id') != -1) {
			document.location = loc.substring(0, loc.lastIndexOf('disp_prog_id')) + 'disp_prog_id=' + progId;
		} 
		else {
			document.location = loc + "&disp_prog_id=" + progId;
		}
	}
}

function checkIfSubsiteLinkTag(tag) {
 var link = tag.href;
 alert(tag.innerHTML);
 checkIfSubsite(link);
}

function viewCourseInfo(crs_lbl) {
	window.open("/p/course-info?crs_lbl=" + crs_lbl, crs_lbl, "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, left=0, top=0, height=200 ,width=500");
}

function underLine(element) {
	element.style.textDecoration = 'underline'; 
}

function deUnderLine(element) {
	element.style.textDecoration = 'none'; 
}

function GetXmlHttpObject(handler) { 
 var objXMLHttp=null;
 if (window.XMLHttpRequest) {
	objXMLHttp=new XMLHttpRequest();
 }
 else if (window.ActiveXObject) {
	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
return objXMLHttp;
} 

function linkCourses() {
	var item = document.body;
	var txtB = document.getElementById('text-body');
	var crs_exp = /([A-Z]{4}[0-9]{3,4})(?!(\s*<\/a>)|(\s*('|")\);?))/gm;
	txtB.innerHTML = txtB.innerHTML.replace(crs_exp, "<a style='cursor: pointer;' class='course-label' onClick='viewCourseInfo(\"$1\")' onMouseOver='underLine(this)' onMouseOut='deUnderLine(this)'>$1</a>");
	txtB.innerHTML = txtB.innerHTML.replace(/(<table[^>]*)(>)/igm,"$1 class='inner' $2");
	txtB.innerHTML = txtB.innerHTML.replace(/(<td[^>]*)(>)/igm,"$1 class='inner' $2");
	txtB.innerHTML = txtB.innerHTML.replace(/(<th[^>]*)(>)/igm,"$1 class='inner' $2");
}

function linkCourses_xmlHttp(str) {
	/*var crs_exp = /([A-Z]{4}[0-9]{3,4})(?!(\s*<\/a>)|(\s*('|")\);?))/gm;
	str = str.replace(crs_exp, "<a style='cursor: pointer;' onClick='viewCourseInfo(\"$1\")' onMouseOver='underLine(this)' onMouseOut='deUnderLine(this)'>$1</a>");
	str = str.replace(/(<table[^>]*)(>)/gm,"$1 class='inner' $2");
	str = str.replace(/(<td[^>]*)(>)/gm,"$1 class='inner' $2");
	str = str.replace(/(<th[^>]*)(>)/gm,"$1 class='inner' $2");
	return  str*/
}

function changeBgColor(elmnt, color) {
	elmnt.style.backgroundColor = color;
}

function setChildrenClass(obj,tagname,classname) {
	for (var childIndex = 0; childIndex < obj.childNodes.length ; childIndex++ ){
		if (obj.childNodes[childIndex].tagName == tagname ) {
			obj.childNodes[childIndex].className = 	classname;
		}
		setChildrenClass(obj.childNodes[childIndex],tagname,classname);
	}
}