var Functions  = new Object();
var Member     = new Object();

Content.historyDivOpened = 0;
//**********************************************************************************//
Functions.changeProductNormalImage = function(imageName, mediaID){
  imgSrc   = "media/product/normal/" + imageName;
  linkTemp = "index.php?_room=media&_spAction=zoomImage&media_id=" + mediaID;
  linkSrc  = "javascript:UtilWindow.openWindow(linkTemp,'1010','800')";
  document.getElementById("productImage").src = imgSrc;
  document.getElementById("largeImage").href  = linkSrc;
}

//**********************************************************************************//
Functions.popUp = function(windowURL,windowName,windowWidth,windowHeight) {

   window.name = 'parentWnd';
   newWindow = window.open(windowURL,windowName,'width='+windowWidth+',height='+windowHeight+',toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');
}

Functions.viewImageAttachment = function(content_id) {
   //var divObj     = document.getElementById("formContainer");
   //var imgSrc = '<div align="center"><img src="/images/loading.gif" border="0" align="center"></div>';
   //divObj.innerHTML = imgSrc;

   var url = "index.php?_room=content&_spAction=viewImageAttachment" + "&content_id=" + content_id + "&showHTML=0";

   var formContent = 'xyz=1';
   XMLHTTP.xmlHttpObj = XMLHTTP.getXMLHTTPObject(function () {Functions.viewImageAttachmentHandler();});
   XMLHTTP.xmlHttpObj.open("POST", url, true);
   XMLHTTP.xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   XMLHTTP.xmlHttpObj.send(formContent);
}

//=====================================================//
Functions.viewImageAttachmentHandler = function(){

   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") {

      var responseText   = XMLHTTP.xmlHttpObj.responseText;
       //alert (responseText);
      //return;
      var divObj         = document.getElementById("viewAttachment");
      divObj.innerHTML = responseText;
   }
}

//=====================================================//
Content.getVideoPopUp = function(path){

   var url = path;
   
   var formContent = 'xyz=1';   
   
   XMLHTTP.xmlHttpObj = XMLHTTP.getXMLHTTPObject(function () {Content.getVideoPopUpHandler();});
   XMLHTTP.xmlHttpObj.open("POST", url, true);
   XMLHTTP.xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
   XMLHTTP.xmlHttpObj.send(formContent);
}


//=====================================================//
Content.getVideoPopUpHandler = function(){
    
   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") {
      var responseText = XMLHTTP.xmlHttpObj.responseText;
      
      var day = new Date();
      var id = day.getTime();
      
      MovWin = window.open('', id, "width=545,height=360,resizable=no,scrollbars=no,left=" + (screen.width-700)/2 + ",top=" + (screen.height-350)/2);
      mw_content = '<html><head>'+
      '<\/head><body>\n'+ responseText + 
      '<\/body><\/html>\n\n';
      MovWin.document.write(mw_content);
      MovWin.document.close();    

   }   
}

//=====================================================//
Member.afterLogin = function(){
   if (XMLHTTP.xmlHttpObj.readyState==4 || XMLHTTP.xmlHttpObj.readyState=="complete") { 
      
      var xmlDoc  = XMLHTTP.loadXML(UtilString.trimAll(XMLHTTP.xmlHttpObj.responseText, 1));
      var root    = xmlDoc.documentElement;

      var headerTag = xmlDoc.getElementsByTagName("header");
      var errorNo = headerTag[0].childNodes[0].firstChild.nodeValue;
      
      if (errorNo == 0){
         var returnUrl = headerTag[0].childNodes[1].firstChild.nodeValue;
         document.location = returnUrl;
      }
   }
}

//=====================================================//
Content.showContentHistory = function(content_id){
   var contentHistDIV = document.getElementById(content_id);

   if (Content.historyDivOpened == 0){
      contentHistDIV.style.display = "block";
      Content.historyDivOpened = 1;
   } else {
      contentHistDIV.style.display = "none";
      Content.historyDivOpened = 0;
   }
}
