/*
 * Fake modal windows in the browser area.
 */

var ICWS_ImageUploadWindow;

function ICWS_ModalInit(){
  if(!document.getElementById('icwsModal')){
    $("body").append('<div id="icwsModal"></div><div id="icwsModalForm"></div>');
  }else{
    document.getElementById('icwsModal').style.display='block';
  }
  //$("body").append('<div id="icwsModal"></div><div id="icwsModalForm"></div>');
  ICWS_DIVResize();
  ICWS_Position();
}

function ICWS_Position(){
  tempx=document.getElementById('icwsModalForm').style.width;
  //alert(parseInt(tempx));
  yPosition=GetWindowHeight()/2-225;
  xPosition=GetWindowWidth()/2-225;
  document.getElementById('icwsModalForm').style.top=yPosition+'px';
  document.getElementById('icwsModalForm').style.left=xPosition+'px';
}

function GetWindowWidth(){
  var myWidth = 0, myHeight = 0;
  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;
  }
  return myWidth;
}

function GetWindowHeight(){
  var myWidth = 0, myHeight = 0;
  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;
  }
  return myHeight;
}

function ICWS_ModalClose(){
  document.getElementById('icwsModalForm').style.display='none';
  document.getElementById('icwsModal').style.display='none';
  document.getElementById('icwsModalForm').innerHTML='';
}

function ICWS_DIVResize(){
  if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX) {
    yScroll = window.innerHeight + window.scrollMaxY;
    xScroll = window.innerWidth + window.scrollMaxX;
  } else {
    if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth){
      yScroll = document.body.scrollHeight;
      xScroll = document.body.scrollWidth;
    } else { 
      yScroll = document.body.offsetHeight;
      xScroll = document.body.offsetWidth;
    }
  }
  $("#icwsModal").css({"height":yScroll +"px", "width":xScroll +"px"});
}

function ICWS_ParentImageList(){
  ICWS_ImageUploadWindow.close();
  setTimeout("xajax_ImageList()",1000);
}


function ICWS_ParentProductImageDiv(Size, urlencodedFileName, iconvFileName, Nid, OptionValueId){
  ICWS_ImageUploadWindow.close();
  if(Nid==0){
    setTimeout("xajax_ImageDiv('imagepics_"+Size+"','"+urlencodedFileName+"')",1000);
    if(Size=='small'){
      document.getElementById('edit-image').value=iconvFileName;
    }else{
      document.getElementById('edit-bigimage').value=iconvFileName;
    }
  }else{
    setTimeout("xajax_ProductParameterSetImage("+Nid+", "+OptionValueId+", '"+urlencodedFileName+"')",1000);
  }
  document.getElementById('imagelist').style.display='none';
  
}