/* sendEmail.js */
/* functions to send an email from a form using sendDownloadLink function */

dwr.engine._defaultPath = 'https://www.blackberry.com/downloadlink/dwr';
sendDownloadLink._path = 'https://www.blackberry.com/downloadlink/dwr';
DWREngine.setRpcType(DWREngine.ScriptTag);

/* Sends the product download via DWR */
function sendEmailDWR() {
	if( ValidateForm( $('email') ) ) {
		//sendEmailLink(1,DWRUtil.getValue('code'),"en","text",p_val,displayThankYou);
		sendDownloadLink.sendDownloadLink(DWRUtil.getValue('email'),DWRUtil.getValue('code'),DWRUtil.getValue('language'),DWRUtil.getValue('emailType'),displayThankYou);

		var form;
		form = $('downloadForm');
		form.innerHTML = "";
		form.style.background = "url(ajax-loader.gif) no-repeat scroll center center";
		form.style.height = "100px";
	}
}

/* Checks the email value for its validity */
function checkEmail(p_val) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(p_val)){
		return true;
	}
	return false;
}

/* Displays the thank you message */
function displayThankYou(data) {
	var form;
	form = $('downloadForm');
	form.style.background = "none";
	form.style.height = "auto";
	form.innerHTML = "<p>Thank you for submitting your request, please check your email for the download link</p>";
}







function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   toggleform('t');
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   toggleform('t');
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    toggleform('t');
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    toggleform('t');
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    toggleform('t');
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    toggleform('t');
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    toggleform('t');
		    return false;
		 }

 		 return true;
	}

function ValidateForm( emailID ){
	//var emailID=document.emailForm.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		toggleform('t');
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true
 }
 
 function faq2()
{
 // does browser support document.getElementsByTagName

  if ( !document.getElementsByTagName)
  {
    return;
  }
  
  // get all DT and DD tags
  var dt = document.getElementsByTagName('dt');
  var dd = document.getElementsByTagName('dd');
  var tt = document.getElementsByTagName('tt');
  // loop through them
  for (var i=0; i<dd.length; i++)
  {
    // set DD's id
    dd[i].id = 't_'+i;
    // hide current DD
    $('t_'+i).style.display = 'none';
    // replace DT's content with a link, which toggles DD's content
    dt[i].innerHTML = '<a href="#" onclick="toggle(\'t_'+i+'\');return false\">'+dt[i].innerHTML+'</a>';
	dt[i].className='DTplus';
	dt[i].id = 't_'+i+'_dt';
  }

  
  
  // get all DT and DD tags
  

  // loop through them
  for (var i=0; i<tt.length; i++)
  {
    // set DD's id
    tt[i].id = 't';
    // hide current DD
    $('t').style.display = 'none';
    // replace DT's content with a link, which toggles DD's content

  }
  
  
   
}

window.onload = faq2;

function toggleform(l)
{
  $(l).style.display = '';
} 

function toggle(l)
{
  $(l).style.display = $(l).style.display == '' ? 'none' : '';
  $(l+'_dt').className=($(l+'_dt').className=='DTplus')?'DTminus':'DTplus';
} 



