/* Prevent framing */
if (self != top) {
    if (document.images)
        top.location.replace(window.location.href);
    else
        top.location.href = window.location.href;
}
// End framing

function addEvent(obj, evType, fn){    // Registers events in a cross browser fashion. 
 if (obj.addEventListener){
   obj.addEventListener(evType, fn, false);
   return true;
   } 
 else if (obj.attachEvent){
   var r = obj.attachEvent("on"+evType, fn);
   return r;
    }
 else{
      return false;
    }
}
// Global start
var win=null;

// Global end


 
/*  Child browser window.
Examples for for implementing different child browser sizes:
<a href="targetURL" class="childSmall">Small</a>
<a href="targetURL" class="childMedium">Medium/Default</a>
<a href="targetURL" class="childLarge">Large</a>
<a href="targetURL" class="custom300x600yes icoChild">Defined Size</a>  WidthxHeightyes for resizable and, WidthxHeightno for not resizable.
*/

function popup(url,winType,width,height,resize){
	  var properties=null ;		
	  var defaultProps = "directories=no,location=no,menubar=no,scrollbars=yes,status=no,titlebar=yes,toolbar=no,resizable=yes";
	  var largeProps = "directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes,resizable=yes";
		
		switch(winType){
			case 1: //small
			properties="width=300px,height=200px,"+defaultProps;		
			break;
			case 2: //medium/default
			properties="width=500px,height=350px,"+defaultProps;
			break;
			case 3: //large
			properties="width=700px,height=500px,"+largeProps;
			break;
			case 4: //custom: width,height, resizable
			properties="width="+arguments[2]+"px,height="+arguments[3]+"px,"+largeProps;
			break;
		   }
	if (win!=null){   // Close the previously opened window
	 win.close();
	 }	   		
	 win=window.open(url,"child",properties); 	 
     win.focus(); 
	 return win;		
  }
	  
function newWindow (popup){	  
	   if (popup==null || win==null){ alert ('You may have pop up blocker software preventing this window from opening.'); }		
  }
  
  /* Attach onclick events to all child browser opening links */	  
function allLinks(){
	var linkList=document.getElementsByTagName("a");	
	for (var i=0;i<linkList.length;i++){
	   if(linkList[i].className.indexOf("childSmall")>-1 ||  linkList[i].className.indexOf("childMedium")>-1 || linkList[i].className.indexOf("childLarge")>-1 || linkList[i].className.indexOf("custom")>-1){
				linkList[i].onclick=childLinkOnClick;				
				if(linkList[i].title){
					linkList[i].title=linkList[i].title+" New window.";
					 }
				else {
					linkList[i].title=linkList[i].innerHTML+". New window.";
						 }	
				linkList[i].className=linkList[i].className+" childIcon";	// Insert classname to display icon defined in css file.	 
		    } 
	   }
  }	  

function childLinkOnClick(){                    // Set the child window size based on the css class value.
    if(this.className.indexOf("childSmall")>-1){
		newWindow(popup(this,1)); 
	   }
	else if(this.className.indexOf("childMedium")>-1){  
	    newWindow(popup(this,2)); 
	   }
	else if(this.className.indexOf("childLarge")>-1){
		newWindow(popup(this,3)); 
		}
	else if (this.className.indexOf("custom")>-1){		
			var dimensions=this.className.slice(this.className.indexOf("custom")).substr(6);
			var resizable;
			if (dimensions.indexOf("yes")>-1){
			   resizable=dimensions.substr(dimensions.indexOf("yes"));  // Custom size has to have "yes" or "no" for resizable.
			   }
			else {
			   resizable=dimensions.substr(dimensions.indexOf("no"));
			   }   
			var width=dimensions.substr(0,dimensions.indexOf("x"));   // The dimensions are separated by lowercase x.
			var height=dimensions.substr(dimensions.indexOf("x")+1);
			newWindow(popup(this,4,width,height,resizable));
		}
  return false;		
}


addEvent(window,"load",allLinks);
