var xmlHttp;
var reportoutputid;

function GetXmlHttpObject(handler)
	{ 
		var objXmlHttp=null
	
		if (navigator.userAgent.indexOf("MSIE")>=0)
		{ 
			var strName="Msxml2.XMLHTTP"
			if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
			{
				strName="Microsoft.XMLHTTP"
			} 
			try
			{ 
				objXmlHttp=new ActiveXObject(strName)
				objXmlHttp.onreadystatechange=handler 
				return objXmlHttp
			} 
			catch(e)
			{ 
				alert("Error. Scripting for ActiveX might be disabled") 
				return 
			} 
		} 
		if (navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0)
		{
			objXmlHttp=new XMLHttpRequest()
			objXmlHttp.onload=handler
			objXmlHttp.onerror=handler 
			return objXmlHttp
		}
	}

function _submit()
{

	var chkContact,strTitle,strFirstName,strLastName,strOrganization,strEmail,strPhone,strOrganizationType,strHowDidYouHear,strWhitePaper,strVerificationCode,page;
	
	var frmWhitePaper		=	document.getElementById("frmWhitePapers");
	
	for (var intI = 0; intI < frmWhitePaper.elements.length; intI++)
	{
		if (frmWhitePaper.elements[intI].type == "text")
		{
			_clearText(frmWhitePaper.elements[intI], frmWhitePaper.elements[intI].defaultValue);
		}
	}
	
	spryFirstName.validate();
	spryLastName.validate();
	spryOrganization.validate();
	spryEmail.validate();
	spryPhone.validate();
	spryOrganizationType.validate();
	
	if(spryFirstName.validate() == true && spryLastName.validate() == true && spryOrganization.validate() == true && spryEmail.validate()== true && spryPhone.validate()== true && spryOrganizationType.validate() == true)
	{
		//alert("reached1");
		chkContact			= document.frmWhitePapers.chkContact.value;
		txtTitle			= document.frmWhitePapers.txtTitle.value;
		txtFirstName		= document.frmWhitePapers.txtFirstName.value;
		txtLastName			= document.frmWhitePapers.txtLastName.value;
		txtOrganization		= document.frmWhitePapers.txtOrganization.value;
		txtEmail			=        document.frmWhitePapers.txtEmail.value;	
		txtPhone			= document.frmWhitePapers.txtPhone.value;
		selOrganizationType	= document.frmWhitePapers.selOrganizationType.value;
		selHowDidYouHear	= document.frmWhitePapers.selHowDidYouHear.value;
		DemoType			= document.frmWhitePapers.DemoType.value;
		hdnDemoType			= document.frmWhitePapers.hdnDemoType.value;
		hdnfile = document.frmWhitePapers.hdnFile.value; //(18-12-09)
		page				= document.frmWhitePapers.page.value;

		//alert(page);
		if(page == 'consultant' || page=='information')
		{
			var para = "?chkContact="+escape(chkContact)+"&txtTitle="+escape(txtTitle)+"&txtFirstName="+escape(txtFirstName)+"&txtLastName="+escape(txtLastName)+"&txtOrganization="+escape(txtOrganization)+"&txtEmail="+escape(txtEmail)+"&txtPhone="+escape(txtPhone)+"&selOrganizationType="+escape(selOrganizationType)+"&selHowDidYouHear="+escape(selHowDidYouHear)+"&page="+escape(page)+"&hdnfile="+escape(hdnfile);
		
			url = "consultant_form_db.cfm"+para;
			//alert(url);
			xmlHttp=GetXmlHttpObject(stateChangedReportList) //Create XMLHTTPRequest object with Event Handler
			xmlHttp.open("GET", url , false) //Retrive data from specified url
			xmlHttp.send(null) //Trigger actual request with null because called with 'GET'
		//	alert("Done");
		}
		else if (page =='Demo')
		{
			
			var para = "?chkContact="+escape(chkContact)+"&txtTitle="+escape(txtTitle)+"&txtFirstName="+escape(txtFirstName)+"&txtLastName="+escape(txtLastName)+"&txtOrganization="+escape(txtOrganization)+"&txtEmail="+escape(txtEmail)+"&txtPhone="+escape(txtPhone)+"&selOrganizationType="+escape(selOrganizationType)+"&selHowDidYouHear="+escape(selHowDidYouHear)+"&page="+escape(page)+"&DemoType="+DemoType+"&hdnDemoType="+hdnDemoType;
		//alert(para);
			url = "demo_form_db.cfm"+para;
			//alert(url);
			xmlHttp=GetXmlHttpObject(stateChangedReportList) //Create XMLHTTPRequest object with Event Handler
			xmlHttp.open("GET", url , false) //Retrive data from specified url
			xmlHttp.send(null) //Trigger actual request with null because called with 'GET'	
		}
		else if (page =='submition')
		{
			
			var para = "?chkContact="+escape(chkContact)+"&txtTitle="+escape(txtTitle)+"&txtFirstName="+escape(txtFirstName)+"&txtLastName="+escape(txtLastName)+"&txtOrganization="+escape(txtOrganization)+"&txtEmail="+escape(txtEmail)+"&txtPhone="+escape(txtPhone)+"&selOrganizationType="+escape(selOrganizationType)+"&selHowDidYouHear="+escape(selHowDidYouHear)+"&page="+escape(page);
		//alert(para);
			url = "subscribe_form_db.cfm"+para;
			//alert(url);
			xmlHttp=GetXmlHttpObject(stateChangedReportList) //Create XMLHTTPRequest object with Event Handler
			xmlHttp.open("GET", url , false) //Retrive data from specified url
			xmlHttp.send(null) //Trigger actual request with null because called with 'GET'	
			//return;
		}
		else
		{
		var para = "?chkContact="+escape(chkContact)+"&txtTitle="+escape(strTitle)+"&txtFirstName="+escape(strFirstName)+"&txtLastName="+escape(strLastName)+"&txtOrganization="+escape(strOrganization)+"&txtEmail="+escape(strEmail)+"&txtPhone="+escape(strPhone)+"&selOrganizationType="+escape(strOrganizationType)+"&selHowDidYouHear="+escape(strHowDidYouHear)+"&page="+escape(page);
	
		url = "whitepaper_form_db.cfm"+para;
		//alert(url);
		xmlHttp=GetXmlHttpObject(stateChangedReportList) //Create XMLHTTPRequest object with Event Handler
		xmlHttp.open("GET", url , false) //Retrive data from specified url
		xmlHttp.send(null) //Trigger actual request with null because called with 'GET'
		}
	}
	else
	{
		for (var intI = 0; intI < frmWhitePaper.elements.length; intI++)
		{
			if (frmWhitePaper.elements[intI].type == "text")
			{
				_setText(frmWhitePaper.elements[intI], frmWhitePaper.elements[intI].defaultValue);
			}
		}
	}
}

function stateChangedReportList() //Event Handler
{ 
//	var opid = reportoutputid;

	var hdnFile	=	document.frmWhitePapers.hdnFile.value;
	var hdnMode =	document.frmWhitePapers.hdnMode.value;
	var page = document.frmWhitePapers.page.value;
	
	if (xmlHttp.readyState==4 || xmlHttp.readyState	=="complete")
	{ 
		//alert(document.getElementById("successmsg").innerHTML);
		document.getElementById("successmsg").innerHTML=xmlHttp.responseText;
		//alert(document.getElementById("successmsg").innerHTML);
		
			if(xmlHttp.responseText == 1)
			{
				document.getElementById("hdnsuccess").value = "0";
				document.getElementById("successmsg").innerHTML="Invalid Verification code";
			}
			else
			{
				if(page == 'information' || page == 'consultant' || page == 'Demo')
				{
					document.getElementById("successmsg").innerHTML=xmlHttp.responseText;
				}
				else if (page == 'submition')
				{
					document.getElementById("successmsg").innerHTML ="Thank you for subscribing for Votenet News Alerts and Announcements";
					document.getElementById("txtEmailid").value=document.getElementById("txtEmailid").defaultValue;
				}
				else
				{
					document.getElementById("successmsg").innerHTML = document.getElementById("successmsg").innerHTML + "<a target='blank' href='whitepaper/" + hdnFile + "' class='content'>If your browser does not open the window, Please click here for the view Whitepaper.</a>";
				}

				document.getElementById("hdnsuccess").value = "1";
				setTimeout('_closeLoadSearch()',4500);
				

		if(page == 'Demo')
		{
			document.frmWhitePapers.action = "demo_redirect.cfm"; 
			document.frmWhitePapers.submit();
			return;
		}
		if(page == 'submition')
		{
			return;
		}
		if(page != 'information')
		{
			if(page != 'consultant')
			{
			window.open( "whitepaper/"+hdnFile, "WhitePaper","resizable=1,width=1030,height=900,scrollbars=1");
			}
		}
		
			}
		
	} 
} 

function _closeLoadSearch()
	{
		var divLoadSaveBackground = document.getElementById("divLoadSaveBackground");
		var divLoadSearch = document.getElementById("divLoadSearch");
		
		divLoadSaveBackground.style.display = "none";
		divLoadSearch.style.display = "none";
		
		//showflash();
	}
	function _closepopup()
	{
		var divLoadSaveBackground = document.getElementById("divLoadSaveBackground");
		var divLoadSearch = document.getElementById("popup");
		
		divLoadSaveBackground.style.display = "none";
		divLoadSearch.style.display = "none";
		
		//showflash();
	}
	function _clientHeight() {
	  varmyHeight = 0;
	  if( typeof window.innerHeight != 'undefined' ) {
		//Non-IE
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	  }
	  return myHeight;
	}

	function _clientWidth() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof window.innerWidth != 'undefined' ) {
		//Non-IE
		myWidth = window.innerWidth;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	  }
	  return myWidth;
	}

