﻿// JScript File
//search pages add/check
function JavaToCart(id, studentID,myCartId ,itemID,itemAmount ,itemType,packageID,seminarID, enrollmentID, lictypeid, state, partnershipId, Return){
            //Use the ajax web service to add an item to the cart.  On success, it call the
            //javascript function AddedToCart.
            MAGIservice.AddToCart(id, studentID,myCartId ,itemID,itemAmount ,itemType,packageID ,seminarID, enrollmentID, lictypeid,state,partnershipId,Return);
        }
       
       
        function AddedToCart(result){
                //First get the link that was clicked, the id of the link is returned in result
                var stringID = String(result);
                var link = document.getElementById(stringID);
                
                //change the text and href to point to the cart.
                link.href="../Cart/MP_Cart.aspx";
                link.innerHTML="In Cart";
                //if this was a seminar, change the seminar classes to say in cart also.
                
                if(stringID.indexOf('resultsGrid')>-1 && stringID.indexOf('seminarClasses')==-1){
                    var newID = stringID.slice(0, stringID.indexOf('AddSeminarToCartHyperLink')) + 'seminarClassesGridView_ctl';
                    var item = document.getElementById(newID + '02_AddSeminarCourseToCartHyperLink');
                    var Count = 3;
                    var sCount = '';
                    sCount = sCount + Count;
                    while(item != null){
                        //If already enrolled, leave alone, otherwise change to In Cart
                        if (item.innerHTML != "Enrolled"){
                            item.href="../Cart/MP_Cart.aspx";
                            item.innerHTML="In Cart";
                        }
                            if(sCount.length < 2){
                                sCount = '0' + sCount;
                            }
                        
                            item = document.getElementById(newID + sCount + '_AddSeminarCourseToCartHyperLink');    
                            Count++;
                            sCount = '' + Count;
                    }
                ///ctl00_MasterContent_seminarsGridView_ctl02_AddSeminarToCartHyperLink
                ///ctl00_MasterContent_seminarsGridView_ctl02_seminarCoursesGridView_ctl02_AddSeminarCourseToCartHyperLink
                }//ctl00_MasterContent_seminarsGridView_ctl02_seminarCoursesGridView_ctl02_AddSeminarCourseToCartHyperLink
                
        }
        function checkChildForSeminarCourses(object){
            //alert('in sub');
            //alert(object.nodeName);
            if(object.nodeName.indexOf('AddSeminarCourseToCartHyperLink')==-1){
                var loop = 0;
                alert('Start Recursive');
                var children = object.childNodes;
	            for(var i=0; i<children.length; i++)
                {     
                    checkChildForSeminarCourses(children[i]);
                }
            } else {
                alert('Set properties');
                object.href="../Cart/MP_Cart.aspx"
                object.innerHTML="In Cart"
            }
        }
        var containerPanel = {
            bInit  : false,
            widget : undefined,
            init   : function( panelWidth, header, content, courseId, LinkID){
                if ( this.bInit ) return;

                var divCnt = document.createElement("div");
                divCnt.setAttribute("id", "myPanel");
                document.getElementsByTagName("body")[0].appendChild(divCnt);

                this.widget = new YAHOO.widget.Panel("myPanel", { width:panelWidth, visible:false } );
                this.widget.setHeader( header )
                this.widget.setBody( content )
                this.widget.setFooter( "<a id='test' href='courseDescription.aspx?ID=" + LinkID + "' target='_new'>More Info</a>" );
                this.widget.render();
                this.widget.cfg.setProperty("context",[courseId,'tl','bl']);
                this.widget.show();
                this.bInit = true;
            },
            swapContent: function ( contents, title, courseId, LinkID){
                this.widget.setHeader( title );
                this.widget.setBody( contents );
                this.widget.setFooter( "<a id='test' href='courseDescription.aspx?ID=" + LinkID + "' target='_new'>More Info</a>" );
                this.widget.cfg.setProperty("context",[courseId,'tl','bl']);
                this.widget.show();
            }
        }

        function courseSynopsisPopup ( content, title_bar, courseId, LinkID){
            if ( !containerPanel.bInit ){
                containerPanel.init( '425px', title_bar, '. . . LOADING . . .', courseId, LinkID);
            } else {
                containerPanel.swapContent( '. . . LOADING . . .', title_bar, courseId, LinkID);
            }
            containerPanel.swapContent( content, title_bar, courseId, LinkID);
        }
        function showHidePackage(id){
            var packageDiv = document.getElementById(id);
            if (packageDiv.style.display == 'block'){
                packageDiv.style.display = 'none';
            } else {
                packageDiv.style.display = 'block';
            }
        }
        function ViewSample(CID,ST,LID,PartnershipID){
            if (PartnershipID != ''){
                window.open("../../Mckissock/Sample/Sample.aspx?CID=" + CID + "&ST=" + ST + "&LID=" + LID + "&PartnershipID=" + PartnershipID  ,"_blank","menubar=no,resizable=yes,scrollbars=yes");
            }else{
                window.open("../../Mckissock/Sample/Sample.aspx?CID=" + CID + "&ST=" + ST + "&LID=" + LID ,"_blank","menubar=no,resizable=yes,scrollbars=yes");
            }
            ///window.open('../../MyMckissock/Sample/Sample.aspx?CID=' + CID + , '_blank','menubar=no','resizable=yes','scrollbars=yes');
        }
    
    

function autoResize(){
    //This function is designed to resize the searchIFrame on searchCourses.aspx
    var origheight = 0;
    var id;
    var newheight=0;
    var winheight=0;
    var bheight=0;

    //This check to see if the IFrame is in the McKissock Site or the My McKissock site.
    if (document.getElementById('ctl00_MasterContent_searchIFrame')) {
        id='ctl00_MasterContent_searchIFrame';
    }
//    if (document.getElementById('ctl00_MasterContent_searchIFrame')) {
//        id='ctl00_MasterContent_searchIFrame';
//    }
    //If window.innerWidth returns a number then we can use that to get the height of the window
    //otherwise we will use the clientHeight    
    if (document.getElementById(id)!=null){
        if (typeof(window.innerHeight) =='number')
            winheight+=parseInt(window.innerHeight);
        else
            winheight+=parseInt(document.documentElement.clientHeight);
        
        //if(document.getElementById("advancedSearchDiv").style.display=='none')
            winheight-=200;
        //else
        //    winheight-=320;
            
        newheight=winheight-147
        if (newheight<147)
            newheight=147;
        
        //document.getElementById('body').style.height = winheight + "px";
        //adjustIFrameSize(window.frames(0));
        if (typeof(window.innerHeight) =='number')
            document.getElementById(id).height=newheight + 'px';
        else
            document.getElementById(id).style.height=newheight + 'px';
    }
}
function sleepFor5(redirectPage){
    window.setTimeout('window.location=\'' + redirectPage + '\';',5000);
}


//set the window onresize event to the above function
window.onresize=autoResize; 


//This code is for the expanding and collapsing of the searching grid views
var ie4 = false; 
if(document.all) { ie4 = true; } 

function getObject(id) { 
	if (ie4) { 
		return document.all[id]; 
	} else { 
		return document.getElementById(id); 
	} 
} 

function toggle(link, divId, hiddenId) { 
	var lText = link.innerHTML; 
	var d = getObject(divId); 
	var myHidden = getObject(hiddenId);
 	
	if (lText == '+') { 
		link.innerHTML = '-';
		d.style.display = 'block';  
		myHidden.value = '-';	
    } else { 
		link.innerHTML = '+'; 
		d.style.display = 'none'; 
		myHidden.value = '+';
	} 
}


function textCounter(field, countfield, maxlimit){
    if (field.value.length > maxlimit)
       field.value = field.value.substring(0, maxlimit);
    else
       countfield.value = maxlimit - field.value.length;
}