﻿
var currimg = 0
function changeimage(list1, ImageElem) {
    // used by the image portlet to rotate images (slide show)
    $("#" + ImageElem).fadeTo("slow", .01);

    setTimeout(function() { nextimage(list1, ImageElem, currimg) }, 800)
    var imgarray = new Array();
    imgarray = list1.value.split(",")
    currimg = (currimg < imgarray.length - 1) ? currimg + 1 : 0
}

function nextimage(list1, ImageElem, currimg) {
    var imgarray = new Array();
    imgarray = list1.value.split(",")
    var img_src = '/generic_pages/streamimage.aspx?imageid=' + imgarray[currimg] + 9999
    document.getElementById(ImageElem).src = img_src;
    $("#" + ImageElem).fadeTo("slow", 1);

}
function fadeimagein(ImageElem, Duration) {
    var inteval = parseInt(Duration) 
    $("#" + ImageElem).fadeIn(inteval);
    //$("#" + ImageElem).fadeTo(''+ inteval +'', 1);
}

function animatediv(ImageElem) {
    ImageElem = document.getElementById(ImageElem)
     $(ImageElem).animate({
        width: 'toggle',
        height: 'toggle'

        //    left: '+=500',
        //        opacity: 0.4
        //marginLeft: "0.6in",
        //fontSize: "3em",
        //borderWidth: "10px"
    }, 500);
 

}
function animatediv2(ImageElem) {
   
    $(ImageElem).animate({
        width: 'toggle',
        height: 'toggle'

        //    left: '+=500',
        //        opacity: 0.4
        //marginLeft: "0.6in",
        //fontSize: "3em",
        //borderWidth: "10px"
    });

}




;
function showpopup(elem) {
    //make the image visible
    var img = document.getElementById(elem)
   // $(img).fadeIn('fast');
    img.setAttribute("class", "popshow");
    img.setAttribute("className", "popshow");
    //$(img.children).fadeTo("fast", 1.0);
//alert('done?')
}

function hidepopup(elem) {
    //hide the image
    var img = document.getElementById(elem)
    //$(img).fadeOut('fast');
    img.setAttribute("class", "pophide");
    img.setAttribute("className", "pophide");
    
}



function CheckKey(evnt) {
// ctrl + M key checker to set admin mode
   // var e = window.event
    var e = evnt
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    //if (window.event.ctrlKey || (window.event.ctrlKey && window.event.shiftKey)) {
    //Modified to work with firefox event is passed in to function from src, window.event not supported
       if (e.ctrlKey || (e.ctrlKey && e.shiftKey)) {
        if (e.keyCode == 77) // M pressed
        {
            // call the web service to set the session var
            IMDOTNET.updateportal.toggleadminmode(show)

        }
    }
}
;


function addtobasket(productid) {
    IMDOTNET.addtobasket1.addtobasket(productid, onproductadded)
    return true;
}
function onproductadded(result) {
    alert(result);

    //update the basket summary
    try {
        var t = setTimeout("reloadbasketsumm()", 2000);
        
    }
    catch (err) {
        //Handle errors here
        //do nothing
    }
    return true;
}
function reloadbasketsumm() { 
// calls the sript embeded into the basket summary portlet
updatesumm()
}

function searchproducts(searchbox, HdnButtonID, TargetPortal,mode) {
    //call the webservice to build the array
    var searchstr 
    if (mode == 'textbox') {

        var inputbox = document.getElementById(searchbox)
         searchstr = inputbox.value
    }
    else {
         searchstr = searchbox
    }
    if (searchstr.length > 0) {
        IMDOTNET.ProductSrch.BuildSrchArry(searchstr, onsearchbuilt);

        if (TargetPortal > 0) {
            document.location = "dvportal.aspx?targetportal=" + TargetPortal
        }
        else {
            __doPostBack('' + HdnButtonID + '', 'search');
       return false
        }
    }
    else { 
    alert('Please enter some text to search')
    }
}
;
function onsearchbuilt(result) {
  
}
function searchdcm(searchbox, HdnButtonID, TargetPortal, mode) {
    //call the webservice to build the array
    var searchstr
    if (mode == 'textbox') {

        var inputbox = document.getElementById(searchbox)
        searchstr = inputbox.value
    }
    else {
        searchstr = searchbox
    }
    if (searchstr.length > 0) {
        IMDOTNET.ProductSrch.SetDcmSearchSession(searchstr);

        if (TargetPortal > 0) {
            document.location = "dvportal.aspx?targetportal=" + TargetPortal + "&searchstr=" + searchstr
        }
        else {
            __doPostBack('' + HdnButtonID + '', 'dcmsearch');
            return false
        }
    }
    else {
        alert('Please enter some text to search')
    }
}

function P_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function P_swapimage() {
  var i,j=0,x,a=P_swapimage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
    var popwin = window.open(theURL, winName, features);
    popwin.focus();
}

//Allows form submission from element
// Requires element to have onKeyPress="return submitenter(this,event)" Attribut
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13) {
     myfield.form.submit();
   return false;
   }
else
   return true;
}
;


function setadvadmin() {
        IMDOTNET.updateportal.setadvancedadmin("True")
        toggleadvicons('True')
        alert("Advanced update set\n New icons will now be visible on the breadcrumb\n for more advanced features")
    };
   
   function setsimpleadmin() {
       IMDOTNET.updateportal.setsimpleadmin("True")
       IMDOTNET.updateportal.setadvancedadmin("False")
       IMDOTNET.updateportal.setshopadmin("False")
       toggleadvicons('False')
       toggleshopicons('False')
       alert("Simple update set\n Only the basic icons will be visible on the breadcrumb")
      };
      function setshopadmin() {
          IMDOTNET.updateportal.setshopadmin("True")
          toggleshopicons('True')
          alert("Store update set\n Extra icons will be visible on the breadcrumb to add products")
      };
   function toggleadvicons(state)
   {
   var autopopicon
   autopopicon = document.getElementById("adminautopop")
   var adminduplicate
   adminduplicate = document.getElementById("adminduplicate")
   var adminmulti
   adminmulti = document.getElementById("adminmulti")
   try {
       //Run some code here

       switch(state)
        {
        case "True":
            autopopicon.style.visibility = 'visible'
            autopopicon.style.width = '20px'
            adminmulti.style.visibility = 'visible'
            adminmulti.style.width = '20px'
            adminduplicate.style.visibility = 'visible'
            adminduplicate.style.width = '20px'
       break;
       case "False":
           autopopicon.style.visibility = 'hidden'
           autopopicon.style.width = '0px'
           adminmulti.style.visibility = 'hidden'
           adminmulti.style.width = '0px'
           adminduplicate.style.visibility = 'hidden'
           adminduplicate.style.width = '0px'
         break;
       }
   }
   catch (err) {
       //Handle errors here
   }
     }
   ;
   
   
  // function togglesimpleicons(state)
  // {
   
  // }
   function toggleshopicons(state) {
       var shopadmin
       shopadmin = document.getElementById("shopadmin")
       try {
           //Run some code here

       switch (state) {
           case "True":
               shopadmin.style.visibility = 'visible'
               shopadmin.style.width = '20px'
               break;
           case "False":
               shopadmin.style.visibility = 'hidden'
               shopadmin.style.width = '0px'
               break;
       }       
       }
       catch (err) {
           //Handle errors here
       }
       }
    
   // if (advadmin = 'False') {
   //     autopopicon.style.visibility = 'hidden'
   // }
   // else {
   //     autopopicon.style.visibility = 'visible'
   // }
   
    
//};



function show(result) {
    //Reloads the page after admin mode has been set / unset
    //alert("Adminmode " + result);
    document.location = document.location
}
;
function launchcontrol() {
    window.open('/portal/admin/manageportal.aspx?', 'adminwin', 'height=1000px,width=1200px,scrollbars=yes,resizable');

}
;
function launchadmin() {
    window.open('/admin/admin2.aspx?', 'adminwin2', 'height=1000px,width=1000px,scrollbars=yes,resizable');

}
function showoptions(FnID, templateid) {
    window.open('/portal/admin/dvadvancedoptions.aspx?FnID=' + FnID + '&templateid=' + templateid + '', +FnID + 'advwin', 'height=600px,width=500px,scrollbars=yes,resizable=yes');
}
;
function checkEnter(searchbox, HdnButtonID, TargetPortal, mode){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable
var e 
e = window.event
if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
    searchdcm(searchbox, HdnButtonID, TargetPortal, mode)
//return  true
}
else{
    return false 
}

}


