//var source         = "";
var commentID        = "";
var picture        = "";

var title          = "";
var moText         = "";
var borderWidth    = "";
var marginWidth    = "";
var borderType     = "";
var colorboxTitle  = "";
var colorboxMoText = "";
var colorboxBorder = "";
var titleSize      = "";
var moTextSize     = "";

var titleJustify = "";
var moTextJustify = "";

var quality = "";




function createPreview(mode)
{
var picDate = document.getElementById("dateTD").innerHTML;
initVars();
xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="generate.php" + getQueryString(mode) + "&picDate=" + picDate
//url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

} 
 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ //alert("done" + xmlHttp.responseText);
document.getElementById("previewDiv").innerHTML=xmlHttp.responseText
} 
if (xmlHttp.readyState==1)
{ 
document.getElementById("previewDiv").innerHTML="<center><img src='Art/loading.gif' alt=''></center>";
//document.getElementById("previewDiv").style.background="#99cc99"
} 
} 

function GetXmlHttpObject()
{ 
var objXMLHttp=null

/*if (window.XMLHttpRequest)
        objXMLHttp=new XMLHttpRequest()
else if (window.ActiveXObject)
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
*/

if(window.XMLHttpRequest){
			objXMLHttp = new XMLHttpRequest;	
		}else if(window.ActiveXObject){
			try{
				objXMLHttp = new ActiveXObject("MSXML2.XMLHTTP");	
			}catch(e){
				try{
					objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");	
				}catch(e){}
			}
		}else{
			alert("Your browser doesn't support AJAX");
			return;
		}



return objXMLHttp
} 

function getQueryString(mode){
var returnString = "";
//returnString += "?source=" + source;      
returnString += "?picture=" + picture;      
returnString += "&commentID=" + commentID;     
returnString += "&title=" + title;        
returnString += "&moText=" + moText;       
returnString += "&borderWidth=" + borderWidth; 
returnString += "&marginWidth=" + marginWidth; 
//returnString += "&borderType=" + borderType;   
returnString += "&colorboxTitleValue=" + colorboxTitle ;
returnString += "&colorboxMoTextValue=" +colorboxMoText;
returnString += "&colorboxBorderValue=" +colorboxBorder;
returnString += "&titleSize=" + titleSize;    
returnString += "&moTextSize=" + moTextSize;  

returnString += "&titleJustify=" + titleJustify;    
returnString += "&moTextJustify=" + moTextJustify; 
returnString += "&quality=" + quality; 

returnString += "&mode=" + mode;  

return returnString;
}


function initVars(){

try{

//source         = get_radio_value();//document.getElementById('source').checked;
//picture        = document.getElementById('picture').nodeValue;

commentID = document.getElementById('commentID').value;

title          = document.getElementById('title').value;
moText         = document.getElementById('moText').value;
borderWidth    = document.getElementById('borderWidth').value;
marginWidth    = document.getElementById('marginWidth').value;
//borderType     = document.getElementById('borderType').value;
colorboxTitle  = rgbConvert(document.getElementById('colorboxTitle').style.background);
colorboxMoText = rgbConvert(document.getElementById('colorboxMoText').style.background);
colorboxBorder = rgbConvert(document.getElementById('colorboxBorder').style.background);




titleSize      = document.getElementById('titleSize').value;
moTextSize     = document.getElementById('moTextSize').value;

titleJustify = document.getElementById('titleJustify').value;
moTextJustify = document.getElementById('moTextJustify').value;

quality = document.getElementById('quality').value;

//init colors
if (colorboxTitle == "")
colorboxTitle  = "#FFFFFF";

if (colorboxMoText == "")
colorboxMoText  = "#FFFFFF";

if (colorboxBorder == "")
colorboxBorder  = "#FFFFFF";



//alert("color: " + colorboxBorder);
} catch(e){
alert(e);
}
//var font_times = 'C:/Windows/Fonts/times.ttf';
//var font_arial = 'C:/Windows/Fonts/arial.ttf';
}

function rgbConvert(str) {

if (str.indexOf("rgb") > -1){
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
  
   return ('' + str.join(""));
   } else return str;
}

function get_radio_value()
{
for (var i=0; i < document.generateForm.source.length; i++)
   {
   if (document.generateForm.source[i].checked)
      {
      var rad_val = document.generateForm.source[i].value;
      }
   }
   return rad_val;
}




/*source        
picture       
title         
moText        
borderWidth  
marginWidth   
borderType    
colorboxTitle  
colorboxMoText
colorboxBorder
titleSize     
moTextSize 
*/