// JavaScript Document
var packType = ''
function downloadProductForm(pack)
{
	packType = 	pack;
	document.getElementById('integration_downloads_packtype').value = pack;
	document.getElementById('downloadProductForm').className = 'downloadProductForm_'+pack ;
}

function downloadProductFormHide()
{
	document.getElementById('downloadProductForm').className = 'Hide';
}

function downloadProductForm_submit()
{
	var x = Cookies['hubspotutk'];
	var y = Cookies['LOOPFUSE'];	  	  
		if(x)
		{
//			alert(x);
			document.getElementById('Hubspot_ID').value = x;
		}
		if(y)
		{
//			alert(y);
			document.getElementById('loopfuseVID').value = y;
		}	
	
	if($F('integration_downloads_email') != 'email' && $F('integration_downloads_email') != '' )
	  {
		  	if(EmailCheck_integrations())
			{		
				var url = '/website/download_inegration_packs';
				var pars = Form.serialize('integration_downloads');
				var myAjax = new Ajax.Request(
				url, 
				{
					method: 'get', 
					parameters: pars, 
					onComplete: showResponseform_integration
				});					
			}	
			else
			{

			}
	  }
	 else
	 {
		  alert('Please enter email')
	 }		
}

function showResponseform_integration(originalRequest)
{

/*		if(download_packs_type())
		{
			document.getElementById('email_sf').value =  document.getElementById("integration_downloads_email").value;
			document.getElementById('lead_source').options[8].selected=true;
			document.getElementById('lead_source').options[8].value = 'Website : ' + packType;
			document.getElementById('first_name').value = document.getElementById('integration_downloads_firstname').value;
			document.getElementById('last_name').value = document.getElementById('integration_downloads_lastname').value;				
			document.getElementById("salesforce").submit(); 
		}
		else
		{
						document.getElementById('email_sf').value =  document.getElementById("integration_downloads_email").value;
			document.getElementById('lead_source').options[8].selected=true;
			document.getElementById('lead_source').options[8].value = 'Website : ' + packType;
			document.getElementById('first_name').value = document.getElementById('integration_downloads_firstname').value;
			document.getElementById('last_name').value = document.getElementById('integration_downloads_lastname').value;				
			document.getElementById("salesforce").submit(); 
		}	
*/
	downloadProductFormHide();
	download_packs_type();
//	alert('success');
	document.getElementById('integration_downloads_firstname').value = 'First Name';
	document.getElementById('integration_downloads_lastname').value = 'Last Name';
	document.getElementById('integration_downloads_email').value = 'e-mail';
	document.getElementById('integration_downloads_packtype').value = '';

}

function download_packs_type()
{
		if(packType == 'zimlet')
		{
			window.location="Zimbra_Dimdim_v4.0_Integration_Pack.zip";		
		}
		else if(packType == 'claroline')	
		{
			window.location="Claroline_v1.8_Dimdim_v4.0_Integration_Pack.zip";		
		}
		else if(packType == 'sugar')
		{
			window.location="Connector_DimdimSugar_v1.0.10-CE.zip";	
		}
		else if(packType == 'SF_WebMeeting')
		{
			window.location="https://sourceforge.net/project/showfiles.php?group_id=176809&package_id=301331"	
		}
		else
		{
			window.location="Moodle_v1.9_Dimdim_v4.5_Integration_Pack.zip";	
		}
}



function EmailCheck_integrations()
		{
			txt = document.getElementById("integration_downloads_email");
//          m = $F('integration_downloads_email')
			var emailAddress = $F('integration_downloads_email') ;
		  invalidChars = "~`!#$%^&*()\{}[]:;'<,>?";	
		  for (i=0; i<invalidChars.length; i++) {
		  badChar = invalidChars.charAt(i);

		  if (emailAddress.indexOf(badChar,0) > -1) 
		  {
		  	alert(' Please enter a valid email');
			txt.focus();
			  return false
				}
 		  }
			atPos = emailAddress.indexOf("@",1)			
			if (atPos == -1) {
			alert(' Please enter a valid email');
			txt.focus();
			return false 
			}
			if (emailAddress.indexOf("@",atPos+1) != -1) {	
			alert('Please enter a valid email');
			txt.focus();
				return false
			}
			periodPos = emailAddress.indexOf(".",atPos)
			if (periodPos == -1) {	
			alert('Please enter a valid email');		
			txt.focus();		
				return false
			}
			if (periodPos+3 > emailAddress.length)	{	
			alert('Please enter a valid email');
		     txt.focus();
			return false
			}
			return true
		}
		
		
document.write('<div id="downloadProductForm" class="Hide"><a name="downloads"></a><form action="javascript:downloadProductForm_submit();" method="post" style="margin:0px" id="integration_downloads" name="integration_downloads">    <table width="300px" border="0" cellspacing="3" cellpadding="3"><tr><td colspan="2" align="left"><strong style="float:left;">Download</strong>    ');

document.write('	<div style="text-align:right;font-size:9px;">     	<a href="javascript:downloadProductFormHide();"><strong>x Close&nbsp;</strong></a><br /></div>');     
																													
document.write('Please provide details before download.        </td></tr>  <tr>    <td align="right">First Name :</td>    <td align="left"><input name="firstname" id="integration_downloads_firstname" type="text" value="First Name" />  <input type="hidden" name="Hubspot_ID" id="Hubspot_ID" /></td>  </tr><tr>    <td align="right">Last Name :</td>    <td align="left"><input name="lastname" id="integration_downloads_lastname" type="text" value="Last Name" /></td>  </tr>  <tr>    <td align="right">e-mail :</td>    <td align="left"><input name="email" id="integration_downloads_email" type="text" value="email" /></td>  </tr><tr><td colspan="2" align="center"><input name="packtype" id="integration_downloads_packtype" type="hidden" value="" /><input type="hidden" name="loopfuseVID" id="loopfuseVID" /><input name="Submit" type="submit" value="Submit" class="Hide" /><div class="download_btn" align="center" onclick="javascript:downloadProductForm_submit();"></div></td></tr> </table></form></div>');		