﻿var queryString1 = window.location.search;

//.substring(1);

/* gets the window size for dynamic div positioning */
/*
function getWindowSize(p) {  // true for parent
   var myWidth = 0, myHeight = 0;
   var mySize=new Array;// = 0, myHeight = 0;
   if (p) { // called from child page (uploading form)
      if( typeof( parent.window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = parent.window.innerWidth;
        myHeight = parent.window.innerHeight;
      } else if( parent.document.documentElement && ( parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = parent.document.documentElement.clientWidth;
        myHeight = parent.document.documentElement.clientHeight;
      } else if( parent.document.body && ( parent.document.body.clientWidth || parent.document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = parent.document.body.clientWidth;
        myHeight = parent.document.body.clientHeight;
      }
   } else { // called from parent page (calling page)
      if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
      } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
      } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
   }
   mySize.width=myWidth;
   mySize.height=myHeight;
  
   return mySize;
}
*/

function init() {
    if (queryString1!=null && queryString1!="") {
        createDivPr();
   }
}
    
/* dynamically create div layer pop-ups (provider form) */
function createDivPr() {
   /* upload form pop-up */
   var h = "550px";
   var w = "1000px";
   dv = document.createElement("div");
   dv.setAttribute("id","providerDiv");
   dv.style.position="absolute";  
   dv.style.width=w;
   dv.style.height=h;
   dv.style.zIndex="1";
   dv.style.backgroundColor="#F0F0F0";
   dv.style.borderStyle="double"
   dv.style.visibility="hidden";
   /* need to pass appropriate parameters */
   document.getElementById("body1").appendChild(dv);
   if (queryString1!=null && queryString1!="") {
        if (getParameter(queryString1,"authorize") == "complete") {
        providerLogin();
        }
   }
}

/* shows and positions the provider form div */
function providerLogin() {
   //if (getParameter(queryString1,"authorize") != "complete") {
   // return;
   //}
 //  if (document.getElementById("searchDiv")==null) {  // puts it in a loop - maybe should of been providerDiv???
   if (document.getElementById("providerDiv")==null) {
       createDivPr();
   }
   var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
   var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
   var dsoctop=document.all? iebody.scrollTop : pageYOffset;
   var theSize=getWindowSize(false); // // called from main form
   
   var upl = document.getElementById("providerDiv");
   //upl.style.pixelLeft=((theSize.width/2)-(parseInt(upl.style.width.replace("px",""))/2))+dsocleft;
   //upl.style.pixelTop=((theSize.height/2)-(parseInt(upl.style.height.replace("px",""))/2))+dsoctop;
   upl.style.left=(((theSize.width/2)-(parseInt(upl.style.width.replace("px",""))/2))+dsocleft).toString() + "px";
   upl.style.top=(((theSize.height/2)-(parseInt(upl.style.height.replace("px",""))/2))+dsoctop).toString() + "px";
 //  var param = "?cdtid="+document.getElementById("hdnDistrict").value+"&cltype="+document.getElementById("hdnLibType").value+"&caddusr="+document.getElementById("hdnAddedBy").value;
 //  var param = "?cdtid=2&cltype=Forms&caddusr=72";
    if (queryString1!=null && queryString1!="") {
       //  queryString1 = queryString1.substr(1);
     //  mode = getParameter(queryString1,"paypal");
     //  if (getParameter(queryString1,"xxx") == "xxx") {
     //   upl.innerHTML="<iframe id='searchframe' src='Login.aspx' width='100%' height='100%' />";
     //  } 
       if (getParameter(queryString1,"authorize") == "complete") {
        upl.innerHTML="<iframe id='searchframe' src='AcctTypeAds.aspx"+queryString1+"' width='100%' height='100%' />";
       }
    } else {
        upl.innerHTML="<iframe id='searchframe' src='Login.aspx' width='100%' height='100%' />";
    }
   
   
   upl.style.visibility="visible";
}

/* clears values in provider form prior to closing form */
function closeDivPr() {
 //  window.frames["searchframe"].document.getElementById("DDListStates").selectedIndex=0;
 //  window.frames["searchframe"].document.getElementById("DDListCounties").selectedIndex = 0;
 //  window.frames["searchframe"].document.getElementById("DDListCats").selectedIndex = 0;
 //  window.frames["searchframe"].document.getElementById("DDListSubCats").selectedIndex = 0;
 //  window.frames["searchframe"].document.getElementById("Train").innerText = "";
 //  window.frames["searchframe"].document.getElementById("listing").src = "Search.htm";
   document.getElementById("providerDiv").style.visibility="hidden";
   location.href = "directory.html";
}

function getParameter ( queryString, parameterName ) {
    // Add "=" to the parameter name (i.e. parameterName=value)
    var parameterName = parameterName + "=";
    if ( queryString.length > 0 ) {
        // Find the beginning of the string
        begin = queryString.indexOf ( parameterName );
        // If the parameter name is not found, skip it, otherwise return the value
        if ( begin != -1 ) {
            // Add the length (integer) to the beginning
            begin += parameterName.length;
            // Multiple parameters are separated by the "&" sign
            end = queryString.indexOf ( "&" , begin );
            if ( end == -1 ) {
                end = queryString.length;
            }
            // Return the string
            return unescape ( queryString.substring ( begin, end ) );
        }
    }
    // Return "null" if no parameter has been found
    //alert("null");
    return null;
} 