
//var images_base=""+"http://"+host_name+"/"+ SiteName+"/Static/Images";




function openPrintWin(winLocation ){
	if (winLocation!=''){
		newWind = window.open(winLocation,"" ,"WIDTH=700 ,HEIGHT =450,scrollbars=yes ,directories=yes,status=yes,toolbar=yes,titlebar=yes, menubar =yes,resizable=yes");
		newWind.moveTo(10,5);
	}
}

function printObject(objUOL ){
	winLocation="en.jsp?"+"enDisplay=view&enDispWhat=Zone&enDispWho="+ZoneName+"&enZone="+ZoneName+"&enInfolet=/WEBINF/Infolets/Components/print_utils/PrintSingleObject.jsp&enPage=ComponentPage&printObject="+objUOL;
	if (winLocation!=""){
		newWind = window.open(winLocation,"" ,"WIDTH=700 ,HEIGHT =450,scrollbars=yes ,directories=yes,status=yes,toolbar=yes,titlebar=yes, menubar =yes,resizable=yes ");
		newWind.moveTo(10,5);
	}
}


var windowHandle=new Object();
var navHandle=new Object();
var editorObjLoad=false;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//
//  find_home_page
//
// this is the logic:
// 1. If the zone_coure_id  exists (i.e. not NULL and not 0), then look up the cookie,if the cookie belongs to the course, then make http:// ...semester/course/ to be the return URL.
// 2. but if the cookie does not exist,  or exist, but not for that course, then return  to default_home_page (see 5)
// 3. If the  zone_coure_id  does not exist then return  to default_home_page (see 5)
// 4. at any rate - remove the cookie

//5 default_home_page: for a normal course, it is the http:// ../courses/<%=course_semester%/course_id URL. if the <%=course_semester% doesn't exist than it is telem home page.  for departments & nosim, the default_home_page is the Zone.course_link, and if that doesn;t exist, than the default would be telem home page.
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function find_home_page(zone_course_id,zone_semester,zone_link){

	newlocation =  "";
	last_char="";
	

     var telem_domain = "http://telem.openu.ac.il";
     var default_home_page     = telem_domain;
	 var course_id=        ""+zone_course_id+"";
	 course_id = course_id.toLowerCase();
     var is_it_a_normal_course =course_id.indexOf("c",0); 

	 //figure out the default home page URL
	 if (  is_it_a_normal_course  != -1){   
		   // a normal course
           var course_semester=  ""+zone_semester+"";
		   if   (course_semester != "")
			   	default_home_page = telem_domain + "/courses/" + course_semester + "/" +  course_id;
	      }

	 else {            
		 //department or NOSE
          var course_link =       ""+zone_link+"";
	      course_link =course_link.toLowerCase();
          if   (course_link != "")
		        default_home_page =course_link;  // this is the default. for departments
	     }
	 

     var courseSemesterCookieName = "TELEM_semester_course";

	newlocation =   default_home_page;
	last_char=newlocation.charAt(newlocation.length-1);
		if(last_char!='/'){
			newlocation=newlocation	+"/";
	}


     document.location.href =newlocation;  // this is the default. takes care of 2 & 3

     if ((course_id == "") || (course_id == "00000") || (course_id == "0"))
			{
				//   case 3 - do nothing	
			}
     else 
		{
           // handle case 1
		   if ( document.cookie.length > 0 ) { // if there are any cookies
	       //find our cookie
	
             var prefix = courseSemesterCookieName + "=";
	         var cookieStartIndex = document.cookie.indexOf(prefix);
             if (cookieStartIndex != -1){
	               //found our cookie
	              var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
                  if (cookieEndIndex == -1)
                         cookieEndIndex = document.cookie.length;
                  var cookie_value = unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	              if (cookie_value =="") {
                       // do nothing 
                      }
                  else   {
	                // our cookie has value
					prefix_depart = "depart#";
					var is_it_depart = cookie_value.indexOf(prefix_depart,0); //cookies from URLs not in "courses" have depart# prefix

		            if ( is_it_depart  == -1){
							var cookie_course = cookie_value.substring(cookie_value.indexOf("/",0)+1, cookie_value.length); //it is the substring of 2002b/c04101 for example
							if (cookie_course == course_id) {
								newlocation =    telem_domain + "/courses/" + cookie_value;
								last_char=newlocation.charAt(newlocation.length-1);
								if(last_char!='/'){
									newlocation=newlocation	+"/";
								}
								document.location.href = 	newlocation;
							}
					}
					else{
			//var the_length=my_car.length;
				//var last_char=my_car.charAt(the_length-1);
					newlocation =  telem_domain + "/" + cookie_value.substring(is_it_depart+prefix_depart.length, cookie_value.length);
					last_char=newlocation.charAt(newlocation.length-1);
					var temp=0;
					while(last_char=='/'){
						temp++;
						size=newlocation.length-1;
						newlocation=newlocation.substring(0,size);
						last_char=newlocation.charAt(newlocation.length-1);
					}
					newlocation=newlocation	+"/";
	       			 document.location.href =  newlocation ;
                        }// depart type course
                  }//cookie_value is not empty
           }//found our cookie
      }//there are cookies
    }//end else - course_id exists
  
 //Delete  the cookie
       var the_date = new Date("December 31, 1999");
       var Expiration_Date = "expires=" + the_date.toGMTString();
       var domain_telem = "openu.ac.il";
       var curCookie = courseSemesterCookieName + "=" + escape("") +
						 ";path="  + "/"  +
						 ";" + Expiration_Date +
                         "; domain=" + domain_telem;

       document.cookie = curCookie;
       return  true;
}

function onselect(i) {
	if (document.images) {
		if (document.images[i+2]) { //yifat 2/3/2009
		 var src=document.images[i+2].src;
         var off= src.lastIndexOf(".gif");
          if (off != -1) {
			end=src.length;
             var newsrc=src.lastIndexOf("m-");
              document.images[10].src=src.substring(0,newsrc)+"m-t"+src.substring(newsrc+2,end);
          }
	}
	}
} 

function deselect(ImagesBase,i) {
//	alert (i)
	if (document.images) {
			var bla=""+ImagesBase+"/spc.gif";
			document.images[10].src=bla;
		}
}          

function OpenWindow(application,admin,HelpBase){
	var admin_var =  (admin) ? "1" : "0";
	var help=""+HelpBase+"/" + application + admin_var +".html";		msgWindow=window.open(help,"HELP","width=618,height=370,resizable=yes,toolbar=no,scrollbars=yes,screenY=50,screenX=40");
}


function checkInLoad(){
	modeView='"+en.getRequestParam("enDisplay")+"';
	typeView='"+en.getRequestParam("enDispWhat")+"';
	if ((modeView=="edit"||modeView=="add")&&typeView=="object"){
		if (editorObjLoad==true)
		element_save_select();
   }
	
}


function setHomePagePointer(course,semester,zone_link){
	telemLinksTag=document.getElementById("telemLinks");
	find_hone_page_function="javascript:find_home_page('"+course+"','"+semester+"','"+zone_link+"')";
	if (telemLinksTag)
	{
	telemLinksTag.innerHTML=telemLinksTag.innerHTML+"<a href=\""+find_hone_page_function+"\" id=\"home\" title=\"בית\"><span>בית</span></a>";
	}

	courseNameTag=document.getElementById("courseName");
	if (courseNameTag)
	{
	courseNameTag.innerHTML="<a class=\"findHomePage\" href=\""+find_hone_page_function+"\" title=\"בית\" >"+courseNameTag.innerHTML+"</a>";
	}


}


function setAnnotationsURL(estudy){
		pinkasPtr=document.getElementById("pinkas");
		var tagNameValue="";
		if(pinkasPtr){
				tagNameValue=	pinkasPtr.tagName;
					if(tagNameValue.indexOf("LI")!=-1){
						pinkasPtr.innerHTML="<a href=\""+estudy+"en.jsp?enPage=AnnotationsPage&enZone=Annotations&\" title=\"\" >פנקס אישי</a>";
				}else{
						pinkasPtr.href=estudy+"en.jsp?enPage=AnnotationsPage&enZone=Annotations";
				}
		}

}



function init()
{
invokeDivRtb();checkInLoad();

}
onload=init; 
