var xmlHttp;
var srcDivId;
var loadingImagePath;
var isIE;
var divOpen=false;
/**  
 * gets the contents of the form as a URL encoded String
 * suitable for appending to a url
 * @param formName to encode
 * @return string with encoded form values , beings with &
 */ 
function getFormAsString(formName){
   
	returnString ="";
 	 
 	 //Get the form values	
 	 formElements=document.forms[formName].elements;
 	
 	 //loop through the array , building up the url	
 	 for ( var i=formElements.length-1; i>=0; --i ){
 		 //we escape (encode) each value
 		 if(i==formElements.length-1){
 		  returnString=returnString+"?"+escape(formElements[i].name)+"="+escape(formElements[i].value);
 		 }else{
 		 
 		  returnString=returnString+"&"+escape(formElements[i].name)+"="+escape(formElements[i].value);
 		 
 		 } 		 
 	 }

 	 //return the values
 	 return returnString; 
}



/**  
 * submit a form with ajax
 * 
 * @param formName to encode
 * @return string with encoded form values , beings with &
 */ 

function submitFormWithAjax(formName,argSrcDivId,argURL,argLoadingImgPath){
   
  
   document.getElementById(argSrcDivId).style.display ='block'
   var reqURL="";
   if(formName!=""){
   reqURL=getFormAsString(formName);  
   }  
   reqURL=argURL+reqURL;
   srcDivId=argSrcDivId;
   loadingImagePath=argLoadingImgPath;
   try{
	    divOpen=true;
	    getXmlHTTPRequestObject();		
	   
		xmlHttp.onreadystatechange = genericProcessStateChange;		
	    
	   
	    xmlHttp.open("POST", reqURL, true);
	    xmlHttp.send(null);
		
	}catch (e) {
	    alert(e);
	}

}

function loadPDF(url){
   
   
   try{
   
	    getXmlHTTPRequestObject();		
	   
		xmlHttp.onreadystatechange = loadPDFProcessStateChange;	
	    xmlHttp.open("POST", url, true);
	    xmlHttp.send(null);
		
	}catch (e) {
	    alert(e);
	}

}
function loadMyComments(url){
   
   
   try{
   
	    getXmlHTTPRequestObject();		
	   
		xmlHttp.onreadystatechange = processStateChangeForMyComments;	
	    xmlHttp.open("POST", url, true);
	    xmlHttp.send(null);
		
	}catch (e) {
	    alert(e);
	}

}

function processStateChangeForMyComments() {   
    if (xmlHttp.readyState == 4) { // Complete
		  if (xmlHttp.status == 200) { // OK response
		  
		      
		       if(xmlHttp.responseText=="" ||xmlHttp.responseText==null ){		      
		       
		       document.getElementById("leftPanelDiv9").style.display='block';       
		       }else{
		       var sPdf=xmlHttp.responseText;
		       document.getElementById("imageIframe").src = sPdf;
		       
		       }
								
      } else {
		alert(serverResponseMessage + " " + xmlHttp.statusText);
      }
    }else{
		//var image = pubTemplate + "/images/loading.gif";
		
		//document.getElementById("leftPanelDiv9").style.display ='block';		
		//document.getElementById("leftPanelDiv9").innerHTML = '<table border="0" width="50%"><tr><td valign="top" width="100%" align="center"><img src="' + image + '" border="0"/></td></tr></table>';
		
   }
}

function ifDivOpenClose(divId){
if(document.getElementById(divId).style.display =='block'){
document.getElementById(divId).style.display ='none';
return false;

}
return true;

}


function loadPDFProcessStateChange() {   
    if (xmlHttp.readyState == 4) { // Complete
		  if (xmlHttp.status == 200) { // OK response
		  
		       
		       if(xmlHttp.responseText==''){
		       
		    //do nothing   
		       }else{
		       var sPdf=xmlHttp.responseText;
		       document.getElementById("imageIframe").src = sPdf;
		       
		       }
		        
			    	
				
				
				
								
      } else {
		alert(serverResponseMessage + " " + xmlHttp.statusText);
      }
    }else{
		//var image = pubTemplate + "/images/loading.gif";
		
		//document.getElementById(srcDivId).style.display=='block';		
		//document.getElementById(srcDivId).innerHTML = '<table border="0" width="50%"><tr><td valign="top" width="100%" align="center"><img src="' + image + '" border="0"/></td></tr></table>';
		
   }
}

/**  
 * generic process state change
 * 
 * @param formName to encode
 * @return string with encoded form values , beings with &
 */ 
function genericProcessStateChange() {    
   
    if (xmlHttp.readyState == 4) { // Complete
		  if (xmlHttp.status == 200) { // OK response
		  
		      
				document.getElementById(srcDivId).style.display=='block';
				if(srcDivId!=""){
				document.getElementById(srcDivId).innerHTML = xmlHttp.responseText;	
				}
							
				var image = argLoadingImgPath;
								
      } else {
		alert(serverResponseMessage + " " + xmlHttp.statusText);
      }
    }else{
		var image = pubTemplate + "/images/loading.gif";
		
		document.getElementById(srcDivId).style.display=='block';		
		document.getElementById(srcDivId).innerHTML = '<table border="0" width="50%"><tr><td valign="top" width="100%" align="center"><img src="' + image + '" border="0"/></td></tr></table>';
		
   }
}




function getXmlHTTPRequestObject(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		isIE = true;
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

	

