/** AJAX SYTLE */


var sURL = "http://pdeapress.org/tempup.jsp";
//var sURL = "/PDEA_Public/pdeapublic.jsp/tmpUpload.jsp"


var isXMLRequest = (typeof XMLHttpRequest == "object" || window.ActiveXObject) 
var sParams =""

//sParams = addPostParam(sParams, "name", "Nicholas");
//sParams = addPostParam(sParams, "book", "Professional JavaScript");

var sData =""
var oRequest = false;
function makeRequest() {
	  oRequest = getRequestType();
	   if (oRequest.overrideMimeType) {
          oRequest.overrideMimeType('text/html');
       }
       var idvalue = document.myForm._SID.value
       var ctrvalue = document.myForm._CTR.value
       
       //get counter from Entry-Data.jsp hidden input
       //if counter is not empty
       if(ctrvalue.length=='2'){       
       idvalue = idvalue + ctrvalue;       
       }
       
      
      sURL = addURLParam(sURL, "id", idvalue);
	
    //sURL = addURLParam(sURL, "imgname", idvalue);
	
	oRequest.onreadystatechange = alertContents;
    oRequest.open('GET', sURL , true);
    oRequest.send(null);
    //show_progressbar("loading");
    
     //oRequest.setRequestHeader("Content-length", 0);
     //oRequest.setRequestHeader("Connection", "close");
     // oRequest.send(parameters);
      
	 
}

function getRequestType() {
	var http_request = false;

	 if (window.XMLHttpRequest)  {
	 	
	  	http_request = new XMLHttpRequest();
	  }
	  else {
	  	
	  	http_request = createXMLHTTP() 
	  }	  
	  return http_request;
}


function createXMLHTTP() {
	var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
						"MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
						"Microsoft.XMLHTTP"];
	for (var i=0; i < arrSignatures.length; i++) {
		try {
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		} catch (oError) {
			//alert("MSXML is not installed on your system")
		}
	}
	throw new Error("MSXML is not installed on your system.");
}
//for get request
function addURLParam(sURL, sParamName, sParamValue) {
	sURL += (sURL.indexOf("?") == -1 ? "?" : "&");
	sURL += encodeURIComponent(sParamName) + "=" + encodeURIComponent(sParamValue);
	return sURL;
}

//for post request
function addPostParam(sParams, sParamName, sParamValue) {
	if (sParams.length > 0) {
		sParams += "&";
	}
	return sParams + encodeURIComponent(sParamName) + "="
	+ encodeURIComponent(sParamValue);
}

function alertContents() {
	 
	  //show_progressbar("loading");
	    
      if (oRequest.readyState == 4) {      	
      	 if (oRequest.status == 200) {     
      	 	
      	 	fnCallback(oRequest.responseText)
//       setTimeout('remove_progressbar("loading")',2000);
//       setTimeout('fnCallback(oRequest.responseText)',2000);
       
            
         } else {
            //alert('Request Error:'+oRequest.status)
         }
      }
   }

function fnCallback(sData) {
	setTimeout('remove_progressbar("loading")',6000);
//	var displaySource =document.getElementById('imageview')
	var displaydiv = document.getElementById("displaydiv")
//	var sesID = document.getElementsByName('_SID')
//	alert("sData value: " +sData)
	//var info = getDocInfo(sData)
//	alert(sData.replace(/^\s+|\s+$/g, ''));
	if (sData.replace(/^\s+|\s+$/g, '')=="OK") {
	//alert ('Application sent Successfully to PDEA')
		outputMessage();
	}
	else {
	 styleLizeOutput(sData,displaydiv)
	}
}
 
 
 function styleLizeOutput(bdyTxt, div) {
	
	var image = "http://pdeapress.org/Photos/"
	
//	var image = "http://192.168.1.45:8888/PDEA_Public/Photos/"
//var image = "http://localhost:8888/PDEA_Public/Photos/"
 	div.innerHTML="";	
 	//alert(image+bdyTxt);
 	//div.style.backgroundColor="yellow";
 	//applychanges(image+bdyTxt)
 	myimg = document.createElement("img");
// 	myimg.setAttribute("id", "imageview");
 	myimg.setAttribute("src",image+bdyTxt)
 	
 	div.appendChild(myimg)
 	
 }
 


function makeRequestPrint2() {
	var retVal = true;
	
	var formtop = document.getElementById("toptitle").innerHTML.replace(/&nbsp;/g," ");
	
    if(formtop == "ONLINE S LICENSE APPLICATION FORM" || 
       formtop == "ONLINE P LICENSE APPLICATION FORM" || 
       formtop == "ONLINE L LICENSE APPLICATION FORM"){
    	var reqFields  = "";
//    	alert(formtop);
		if (document.myForm.ObjValue8.value.length <= 0)
			reqFields += "ComName is Empty! ";
		if (document.myForm.ObjValue11.value.length <= 0)
			reqFields += "Sector is Empty! ";
		if (document.myForm.ObjValue12.value.length <= 0)
			reqFields += "Nature of Business is Empty! ";
		if (document.myForm.ObjValue13.value.length <= 0)
			reqFields += "Office Address is Empty! ";
		if (document.myForm.ObjValue14.value.length <= 0)
			reqFields += "Office Zip Code is Empty! ";
		if (document.myForm.ObjValue18.value.length <= 0)
			reqFields += "Office Tel No is Empty! ";
		if (document.myForm.ObjValue21.value.length <= 0)
			reqFields += "Rep Name is Empty! ";
		if (document.myForm.ObjValue22.value.length <= 0)
			reqFields += "Rep Designation is Empty! ";
		if (document.myForm.ObjValue23.value.length <= 0)
			reqFields += "Rep Home Address is Empty! ";
		if (document.myForm.ObjValue35.value.length <= 0)
			reqFields += "Han Name is Empty! ";
		if (document.myForm.ObjValue36.value.length <= 0)
			reqFields += "Han Designation is Empty! ";						
		if (document.myForm.ObjValue37.value.length <= 0)
			reqFields += "Han Home Address is Empty! ";
		if (document.myForm.ObjValue44.value.length <= 0)
			reqFields += "Han NBI Findings is Empty! ";
		if (document.myForm.ObjValue45.value.length <= 0)
			reqFields += "Han NBI Date is Empty! ";
		if (document.myForm.ObjValue59.value.length <= 0)
			reqFields += "MP No is Empty! ";
		if (document.myForm.ObjValue60.value.length <= 0)
			reqFields += "MP Date is Empty! ";
								
//		alert(reqFields.length);	
        if (reqFields.length > 0) {						
			var answer = confirm(reqFields + "\nDo you want to Continue?");
	//	    alert(answer);
			if (answer){
				document.myForm.submit();
				show_progressbar("loading");
				setTimeout(makeRequestPrint,5000);
				retVal = true;
			}else{
				retVal = false;
	//			alert("byebye!");
			}
        }else{
        	document.myForm.submit();
			show_progressbar("loading");
			setTimeout(makeRequestPrint,5000);
        }
	
    }else{
    	document.myForm.submit();
		show_progressbar("loading");
		setTimeout(makeRequestPrint,5000);
    }
	
	return retVal;
}



function makeRequestPrint() {
	
	sURL = "http://pdeapress.org/CheckPrint.jsp"
	//sURL = "http://192.168.1.45:8888/PDEA_Public/pdeapublic.jsp/CheckPrint.jsp"
	//sURL = "http://localhost:8888/PDEA_Public/pdeapublic.jsp/CheckPrint.jsp"
	oRequest = getRequestType();
	   if (oRequest.overrideMimeType) {
          oRequest.overrideMimeType('text/html');
       }
    
    var last = document.myForm.ObjValue33.value.replace(/^\s+|\s+$/g, '') ;
    var first =  document.myForm.ObjValue34.value.replace(/^\s+|\s+$/g, '') ;
    var mid = document.myForm.ObjValue35.value.replace(/^\s+|\s+$/g, '') ;
    var client = last + ", " + first + " " + mid
    
    sURL = addURLParam(sURL, "client", client);
    //sURL = addURLParam(sURL, "imgname", idvalue);
	oRequest.onreadystatechange = alertContents;
    oRequest.open('GET', sURL , true);
    oRequest.send("");
    
     // oRequest.setRequestHeader("Content-length", parameters.length);
     // oRequest.setRequestHeader("Connection", "close");
     // oRequest.send(parameters);
	 
}

function outputMessage() {
 var msgdiv = document.getElementById("msgdisplay") 

 msgdiv.innerHTML="Application Sent To PDEA";
 	
	
 	//div.style.backgroundColor="yellow";
 	//applychanges(image+bdyTxt)
 	myimg = document.createElement("p");
// 	myimg.setAttribute("id", "imageview");
 	//myimg.setAttribute("width",150)
 	//myimg.setAttribute("height",150) 	
 	myimg.setAttribute("class","msgdisplayvalue") 	
 	div.appendChild(myimg)
}

function replace_html(id, content) {
			document.getElementById(id).style.display="block"
			document.getElementById(id).innerHTML = content;			
		}
		
function show_progressbar(id) {	
//	 	replace_html(id, '<img src="http://192.168.1.45:8888/PDEA_Public/pdeapublic.jsp/images/loading.gif" border="0" alt="Loading, please wait..." />');
		//replace_html(id, '<img src="http://localhost:8888/PDEA_Public/pdeapublic.jsp/images/loading.gif" border="0" alt="Loading, please wait..." />');
		replace_html(id, '<img src="http://pdeapress.org/pdeapublic.jsp/images/loading.gif" border="0" alt="Loading, please wait..." />');
		//document.body.style.overflowY= "hidden"
		}
function remove_progressbar(id){	

	 document.body.style.overflowY= "auto"
	 document.getElementById(id).style.display="none"	 
}



 
