﻿
function ShowProduct(productId) {
    //window.open();
    alert('open ' + productId);
    window.open("/Kaplan.Corporate.WebControls/TestPages/ProductDetail.aspx?productID=" + productId);
}
function CloseChildRefereshParent() {
    self.parent.tb_remove();
    self.parent.location.href = self.parent.location.href;
//    self.parent.document.forms[0].submit();
}
function CloseWindow() {
    window.opener = 'X';
    window.open('', '_parent', '');
    window.close();
}

function SetHeightForCourse() {

   matchColumnsHeight("EqualHeight");
   
}
function courseMoreInfo(divIdSwitch, divIdCol, divAnchor) {

    var elem = document.getElementById(divAnchor)
    if (elem.innerHTML == "More Info") {
        elem.innerHTML = "Less Info";
    }
    else if (elem.innerHTML == "Less Info") {
        elem.innerHTML = "More Info";
    }
    switchMenu(divIdSwitch);
    matchColumnsHeight(divIdCol);
}
/***********************************************/
function BookMoreInfo(divId, aobject) {

    var elem = document.getElementById(aobject)
    if (elem.innerHTML == "More Info") {
        elem.innerHTML = "Less Info";
    }
    else if (elem.innerHTML == "Less Info") {
    elem.innerHTML = "More Info";
    }
    switchMenu(divId);
    
}
/***********************************************/
function courseSVEaqualHeight() {

    matchColumnsHeight('courseFactTblTimetable');

}
/********************Collapse and expand div ***********************/
function OneDivVisible(div1ID, div2ID, tabids) {

   var el = document.getElementById(div1ID);
    el.style.display = '';
    var arrayOfDivs = div2ID.split(",");
    for (var i = 0; i < arrayOfDivs.length; i++) {

        var e2 = document.getElementById(arrayOfDivs[i]);
        if( e2 != null)
        {
        e2.style.display = 'none';
        }
    }
   
   var arrayOfTabs = tabids.split(",");
    for (var i = 0; i < arrayOfTabs.length; i++) {
     
        if (i == 0) {
        
            var e3 = document.getElementById(arrayOfTabs[i]);
            if(e3 != null)
            {     
//            e3.style.backgroundColor = '#a7a7a7';
e3.style.backgroundImage = "url(/Style%20Library/Images/kaplan/mi_but_on.png)";
            }

        }
        else {
            var e4 = document.getElementById(arrayOfTabs[i]);
          if(e4 != null)
            {  
//            e4.style.backgroundColor = '#D4D4D4';
e4.style.backgroundImage = "url(/Style%20Library/Images/kaplan/mi_but_off.png)";
            }
        }
    }
   
}
function switchMenu(divId) {
   
    var el = document.getElementById(divId);
    if (el.style.display != 'none') {
         el.style.display = 'none';
    }
    else {
       
        el.style.display = '';
    }
}
/*************************************
Set equal column for divs having similar id
*****************************************/
function matchColumnsHeight(divId) {

    var divs, contDivs, maxHeight, divHeight, d;
    divs = document.getElementsByTagName('div');
    contDivs = [];
    maxHeight = 0;
    for (var i = 0; i < divs.length; i++) 
    {
    
        // make collection with <div> elements with class attribute "equal"
        if (divs[i].id.indexOf(divId) != -1 && divs[i].id.length > 0) {
            
               d = divs[i];
               contDivs[contDivs.length] = d;
               if (d.style.pixelHeight > 0) 
            {
                divHeight = d.style.pixelHeight;
            }
            else if (d.offsetHeight > 0) 
            {
                divHeight = d.offsetHeight;
           }
          
            maxHeight = Math.max(maxHeight, divHeight);
                    
        }
    }

    if (maxHeight > 0) {
       
       for (var i = 0; i < contDivs.length; i++) {
           contDivs[i].style.height = maxHeight + "px";
           
        }
    }

}
/*******************************************************/
function EmailMeForStock( ProductID) {
    alert('Go to Email me page: ' + ProductID);
}
function PreOrder(ProductID) {
    alert('Go to Pre order page: ' + ProductID);
}
function Buy(ProductID) {
    alert(' Go to buy page: ' + ProductID)
    __doPostBack('Button2', 'My Argument');
}

/*******************************Start Clear control*************/
//Clear the object if the value of the object is set to default text
//Call this function onfoucus event
function ClearText(objectControl, defaultText, newCssClass) {
    if (objectControl.value == defaultText) {
        objectControl.value = "";
        objectControl.className = newCssClass
    }
   
}
function SetText(objectControl, defaultText, newCssClass) {
    if (objectControl.value.length == 0) {
        objectControl.value = defaultText;
        objectControl.className = newCssClass
       
    }
}

/*****************************End COntrol***************************/


/*******************************************************************
PRODUCT CATALOGUE ADMIN - START
/*******************************************************************/
/*
This function makes sure that the element identified by given ID is 
shown in the browser. (It is also possible to call it server side 
within an event handler. For instance, see ProductCatalogueAdmin_Base 
class, OnPreRender method.)
*/
function ScrollToElement(targetElementID) {
    //alert("ScrollToMsgElement with targetElementID = " + targetElementID);
    var objElement = document.getElementById( targetElementID );
    //alert("objElement = " + objElement);

    if (objElement != null) {
        //alert("objElement caught");
        //alert("objElement.text = " + objElement.innerText);
        if (objElement.innerText != "") {
            objElement.scrollIntoView(true);
        }
    }
}

// This javascript code is taken from web http://aspalliance.com/1614_Adding_Filter_Action_to_FileUpload_Control_of_ASPNET_20.all
//Trim the input text
function Trim(input) {
    var lre = /^\s*/;
    var rre = /\s*$/;
    input = input.replace(lre, "");
    input = input.replace(rre, "");
    return input;
}
function CheckForTestFile() {
    //alert("CheckForTestFile called");

    // The code taken from web was using fuProductImage.ClientID but it does not compile.
    // var file = document.getElementById('ProductAdmin1$gvComponent$ctl02$fuProductImage');
    // Workaround is to find the input file with name containing fuProductImage - START...
    var objInputArray = document.getElementsByTagName("input");
    //alert(objInputArray.length);
    var i;
    var fuProductImageFullName = "";
    for (i = 0; i < objInputArray.length; i++) {
        if (objInputArray[i].name.indexOf("fuProductImage") > -1) {
            fuProductImageFullName = objInputArray[i].name;
            break;
        }
    }
    //alert("fuProductImageFullName = " + fuProductImageFullName);
    var file = document.getElementById(fuProductImageFullName);

    var fileName = file.value;
    //Checking for file browsed or not 
    if (Trim(fileName) == '') {
        alert("Please select a file to upload!!!");
        file.focus();
        return false;
    }
    // ... END workaround

    //Setting the extension array for diff. type of text files
    var extArray = new Array(".jpg");

    //getting the file name
    while (fileName.indexOf("\\") != -1)
        fileName = fileName.slice(fileName.indexOf("\\") + 1);

    //Getting the file extension
    var ext = fileName.slice(fileName.indexOf(".")).toLowerCase();

    //matching extension with our given extensions.
    for (var i = 0; i < extArray.length; i++) {
        if (extArray[i] == ext) {
            alert("The product image file type is valid");
            return true;
        }
    }
    alert("Please only upload files that end in types:  "
       + (extArray.join("  ")) + "\nPlease select a new "
       + "file to upload and submit again.");
    file.focus();
    return false;
}        
/*******************************************************************
PRODUCT CATALOGUE ADMIN - END
/*******************************************************************/

