﻿// JScript File

var w3c=(document.getElementById)? true:false;
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var ie5=(w3c && ie)? true : false;
var ns6=(w3c && (navigator.appName=="Netscape"))? true: false;
var op8=(navigator.userAgent.toLowerCase().indexOf("opera")==-1)? false:true;
var ff=(agt.indexOf("firefox")>0);
var ie_7=(!window.XMLHttpRequest&&ie)?true:false;//< IE 7
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh"); 


function getEvent()
{ 
    if(document.all) return window.event; 
    func=getEvent.caller; 
    while(func!=null)
    { 
        var arg0=func.arguments[0]; 
        if(arg0)
        { 
            if((arg0.constructor==Event&&arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
            { 
                return arg0; 
            } 
        } 
    func=func.caller; 
    } 
    return null; 
}

function findPos(o)
{
var nLt=0;
var nTp=0;
  var offsetParent = o;
  while (offsetParent!=null && offsetParent!=document.body) {
  nLt+=offsetParent.offsetLeft;
  nTp+=offsetParent.offsetTop;
  if(!ns6){
  parseInt(offsetParent.currentStyle.borderLeftWidth)>0?nLt+=parseInt(offsetParent.currentStyle.borderLeftWidth):"";
  parseInt(offsetParent.currentStyle.borderTopWidth)>0?nTp+=parseInt(offsetParent.currentStyle.borderTopWidth):"";
  }
  offsetParent=offsetParent.offsetParent
  }
  return [nLt,nTp];
}

function findPosForBrowsers(obj,wgap,hgap,fromleft,fromtop)
{
     var _top=findPos(obj)[1];
     var _left=findPos(obj)[0];
     if(!document.all)
     {
        if(ff){_top-=8;_left-=8;}
        else{_top-=10;_left-=8;}
     }
     else
     {
        _top-=wgap?wgap:16;//6//ie difference,please change this value to adjust the position of the combox in ie
        _left-=hgap?hgap:12;//2//ie difference
        if(ie_7)
        {
            _top-=4;
            _left-=4;
        }
     }
     if(fromleft&&!isNaN(fromleft))
     {
        _left-=fromleft;
    }
    if (fromtop && !isNaN(fromtop)) {
        _top -= fromtop;
    }    
     return [_left,_top];
}

function openCollegeSelector(obj,url,width,height,wgap,hgap,fromleft,formtop)
{


 var currentUrl='';
 var pc1;
 if(!obj)return;
 if(document.getElementById(obj.id+"pc1"))
 {
     pc1=document.getElementById(obj.id+"pc1");
     pc1.style.display='block';
     
     pos=findPosForBrowsers(obj,wgap,hgap,fromleft,formtop);
     _top =pos[1];
     _left=pos[0];
     if(document.all&&ie_7)
     {
        if(url.indexOf('homecollegeselector.aspx')!=-1)
        {            
            _left+=7;
        }
     }
     if(!document.all&&!ff)
     {
        _top+=2;
     }
     pc1.style.top=_top+'px';
     pc1.style.left=_left+'px';
     frm=document.getElementById(obj.id+"autotextFrame");
     
     if(frm&&frm.src)
     {
        currentUrl=frm.src;
        if(currentUrl.indexOf("http://")==0)
        {
            currentUrl=currentUrl.replace("http://",'');
            currentUrl=currentUrl.substring(currentUrl.indexOf('/'),500);
        }
        if(currentUrl==url||currentUrl==encodeURI(url))
        {
            var doc;
            if(frm.contentDocument)
            doc=frm.contentDocument;
            else if(frm.contentWindow.document)
            doc=frm.contentWindow.document;
            
            var autotext=doc.getElementById("ctl_ddl_college_Input");
            
            if(autotext)
            {            
                if(document.all)
                {   
                    var lastKey = "";
                    if(event!=null)
                    {
                    lastKey=String.fromCharCode(event.keyCode); 
                    }
                    if(    typeof(window.frames[obj.id+"autotextFrame"].SetTextIE)!="undefined"){
                    window.frames[obj.id+"autotextFrame"].SetTextIE(lastKey);}
                    autotext.focus();
                    var r=autotext.createTextRange();       
                    r.moveStart('character',autotext.value.length);       
                    r.collapse();       
                    r.select();                    
                }
                else
                {
                    var eve=getEvent();
                    if(eve&&eve.keyCode&&eve.keyCode!=16)
                    {
                        var lastKey=String.fromCharCode(eve.keyCode);
                        
                        if(autotext.value==''&&typeof(window.frames[obj.id+"autotextFrame"].SetText)=="function")
                        {
                            if(obj&&obj.value!='')
                            {obj.value='';}
                            var enableTextSelection=true;
                            if(ff){enableTextSelection=false;}
                            window.frames[obj.id+"autotextFrame"].SetText(lastKey,eve,enableTextSelection);
                        }
                    }
                    setTimeout( function(obj){return function(){obj.focus()}}(autotext),1);                    
                }
                function OpenSelectorForClick()
                {
                    try
                    {
                        setTimeout( function(obj){return function(){obj.blur()}}(obj),1);
                        openCollegeSelector(obj,url,width,height,wgap,hgap,fromleft,formtop);
                        if(autotext)
                        {
                            if(autotext.value==" ")
                            {
                                autotext.value="";
                            }
                        }
                    }
                    catch(ex){}
                    finally
                    {
                        //setTimeout( function(autotext){return function(){autotext.focus()}}(autotext),1);
                    }
                }
                if(!obj.getAttribute("focusEventAttached"))
                {
                    BindEvent(obj,"focus",OpenSelectorForClick);
                    BindEvent(obj,"click",OpenSelectorForClick);
                    obj.setAttribute("focusEventAttached","true");
                }
            }
            return;
        }     
     }
 }
 
 else{pc1=document.createElement("DIV");} 
 
 pc1.style.position="absolute"; 
 pc1.id=obj.id+"pc1";

 var pos=findPosForBrowsers(obj,wgap,hgap,fromleft,formtop);
 var _top =pos[1];
 var _left=pos[0];
 
 if(document.all&&ie_7)
 {
    if(url.indexOf('homecollegeselector.aspx')!=-1) {

        _left += 7;
        
    }
 }
 if(!document.all&&!ff)
 {
    _top+=2;
 }
 if(document.all)width+=2;
 
 pc1.style.width=width+"px";
 pc1.style.height=height+"px";
 pc1.style.zIndex='999'; 
 pc1.style.top=_top+'px';
 pc1.style.left=_left+'px';
 
  var html="";
  html+="<center>"
  html+='<table cellspacing="0" cellpadding="0" border="0" style="z-index: 3006; width: '+width+'px;height: '+height+'px; position: absolute; left: 50%; top: 50%; margin-left: -'+width/2+'px;margin-top:-'+height/2+'px; text-align: center;"><tbody style="height: 100%;"><tr height="100%" style="height: 100%;"><td id="" align="left" style="width: 100%; height: 100%;" colspan="8"><iframe id="'+obj.id+'autotextFrame" name="'+obj.id+'autotextFrame" frameborder="0" scrolling="no" border="no" src="'+url+'" style="border: 0px solid green;width: 100%; height: 100%;"  allowtransparency="true"></iframe></td></tr></tbody></table>'
  html+="</center>"
  document.body.appendChild(pc1);
  pc1.innerHTML=html;
  
resizeEvent=function()
{
        var _pc1=document.getElementById(obj.id+"pc1");
        if(_pc1)
        {
             var pos=findPosForBrowsers(obj,wgap,hgap,fromleft,formtop);
             var top =pos[1];
             var left=pos[0];

             _pc1.style.top=top+'px';
             _pc1.style.left=left+'px';
        }
    
}

if(document.all)
{
    window.attachEvent("onresize",resizeEvent);
}
else
{
    window.addEventListener("resize",resizeEvent,false);
}

}

function preloadCollegeSelector(obj,url,width,height,wgap,hgap,fromleft,formtop)
{
    if(!obj)return;
    openCollegeSelector(obj,url,width,height,wgap,hgap,fromleft,formtop);
    if(document.getElementById(obj.id+"pc1"))
    {
        var pl=document.getElementById(obj.id+"pc1");
        pl.style.display='none';
    }
}
function BindEvent(target,eventType,eventName) {


    if (target == null)
        return;
    if(typeof(target)!="undefined"&&eventType&&eventName&&typeof(eventName)=='function')
    {
        if(document.all)
        {
            target.attachEvent("on"+eventType,eventName);
        }
        else
        {
            target.addEventListener(eventType,eventName,false);
        }
    }
}

function BindEventAndPreload(target,eventType,eventName) {
        BindEvent(target,eventType,eventName)
        eventName(true);
}
