YAHOO.namespace("example.share_container");
var AjaxObject = {
 handleSuccess_downloadpopup:function(o){  
   var mobile_number = document.getElementById('mobile_no').value;
   var fileid = document.getElementById('fileid').innerHTML;
   var t = setTimeout("redirectpage("+mobile_number+")",1500);
  },
 handleFailure_downloadpopup:function(o){
    // Failure handler
  }
};


function final_download(filename)
{
  var t = setTimeout("redirect(filename)",1500);
}

function redirect(filename)                                                                                
{
  window.location.href = system_base_url+'mobile/_adda_download_get/'+filename;                         
}  

function redirectpage(mobile_number)
{
  var fileid = document.getElementById('fileid').innerHTML;
  window.location.href = system_base_url+'mobile/_adda_download/'+fileid+'/'+mobile_number;
}

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */

var callback_downloadpopup =
{
    success:AjaxObject.handleSuccess_downloadpopup,
    failure:AjaxObject.handleFailure_downloadpopup,
    scope: AjaxObject
};


//! Method to initialize popup
function init_download()
{
  // Instantiate the Dialog
  YAHOO.example.share_container.share_popup = new YAHOO.widget.Dialog("download_popup", 
      { width : "50em",
		context:["popup_context","tl","bl"],
		visible : false, 
	  modal:true,
	  constraintoviewport :false
	});
  YAHOO.example.share_container.share_popup.render();
}

YAHOO.util.Event.onDOMReady(init_download);
function toggle_faq(obj)
{   	
    var el = document.getElementById(obj);
	el.className="ans1";
    el.style.display = (el.style.display != 'none' ? 'none' : '' );	
}


function toggle_sms_faq(obj)
{  
	//number of questions
	var len = 16;
	var i=1;
	for( i=1; i<len; i++) 
	{
		var divid = "ans"+i;
		var dgid = document.getElementById(divid);		
		dgid.className="ans";
		dgid.style.display = 'none';
	}
	var el = document.getElementById('ans'+obj);
	el.className="ans1";
	el.style.display = (el.style.display != 'none' ? 'none' : '' );	
}

function toggle_wap_faq(obj)
{ 	
	//number of questions
	var len = 55;
	var i=1;
	for( i=1; i<len; i++) 
	{
		var divid = "ans"+i;
		var dgid = document.getElementById(divid);		
		dgid.className="ans";
		dgid.style.display = 'none';
	}
	var el = document.getElementById(obj);	
	//alert("Divid= = "+obj);
	el.className="ans1";
	el.style.display = (el.style.display != 'none' ? 'none' : '' );	
}


function toggle_adda_faq(obj)
{ 	
	//number of questions
	var len = 70;
	var i=1;
	for( i=1; i<len; i++) 
	{
		var divid = "ans"+i;
		var dgid = document.getElementById(divid);		
		dgid.className="ans";
		dgid.style.display = 'none';
	}
	var el = document.getElementById(obj);	
	el.className="ans1";
	el.style.display = (el.style.display != 'none' ? 'none' : '' );	
}


// this function is used to show download popup
function showDownloadPopup(fileid,make,model,mobile_img_path)
{ 
  //var post_data = '&filename='+filename;
  document.getElementById('fileid').value=fileid;
  document.getElementById('makemodel').innerHTML=make + ' - '+model;
  document.getElementById('fileid').innerHTML=fileid;
  document.getElementById('path').innerHTML="<img src='"+mobile_img_path+"' width='50' height='100' border='0' alt='"+model+"' title='"+model+"'>";
  document.getElementById('download_popup').style.display='';
  YAHOO.example.share_container.share_popup.show(); 
  document.getElementById('error_alpha_mobile').style.display='none';
  document.getElementById('error_less_10_mobile').style.display='none';
  document.getElementById('error_start_9_mobile').style.display='none';
  document.getElementById('error_empty_mobile').style.display='none';
  document.getElementById('searched_keyword').focus();
  document.getElementById('mobile_no').value='';
}

// this function is used to ajax request 
function download_build()
{
  var post_data;
  YAHOO.util.Connect.asyncRequest('POST',system_base_url+'ajax/mobile/_final_download/',callback_downloadpopup,post_data);
  if(env_value == 'Online')
	{
	    var url = system_base_url+'ajax/mobile/_final_download/';
	    pageTracker._trackPageview(url);
	}
    
}

// this function is used to hide download build popup
function hidedownloadpopup()
{
  YAHOO.example.share_container.share_popup.hide();
  document.getElementById('download_popup').style.display='none';
}

// fucntion is used to validate mobile number
function download_submit(filename)
{
  valid_no = true;
  var x = document.getElementById('mobile_no').value
    empty_flag = false;
  
  if(x=='')
    {
      document.getElementById('error_empty_mobile').style.display='';
      document.getElementById('error_alpha_mobile').style.display='none';
      document.getElementById('error_less_10_mobile').style.display='none';
      document.getElementById('error_start_9_mobile').style.display='none';
      YAHOO.example.share_container.share_popup.show();
    }
  else
    {
      if(isNaN(x)||x.indexOf(" ")!=-1)
	{
	  document.getElementById('error_empty_mobile').style.display='none';
	  document.getElementById('error_alpha_mobile').style.display='';
	  document.getElementById('error_less_10_mobile').style.display='none';
	  document.getElementById('error_start_9_mobile').style.display='none';
	  YAHOO.example.share_container.share_popup.show();
	  valid_no = false;
	}
      else if (x.length>10)
	{
	  document.getElementById('error_empty_mobile').style.display='none';                                             
	  document.getElementById('error_alpha_mobile').style.display='none';                                           
	  document.getElementById('error_less_10_mobile').style.display='';                                           
	  document.getElementById('error_start_9_mobile').style.display='none';                                       
	  YAHOO.example.share_container.share_popup.show();
	  valid_no = false;
	}
      else if (x.length<10)
	{
	  document.getElementById('error_empty_mobile').style.display='none';
	  document.getElementById('error_alpha_mobile').style.display='none';
	  document.getElementById('error_less_10_mobile').style.display='';
	  document.getElementById('error_start_9_mobile').style.display='none';
	  YAHOO.example.share_container.share_popup.show();
	  valid_no = false;
	}
      else if (x.charAt(0)!="9")
	{
	  document.getElementById('error_empty_mobile').style.display='none';
	  document.getElementById('error_alpha_mobile').style.display='none';
	  document.getElementById('error_less_10_mobile').style.display='none';
	  document.getElementById('error_start_9_mobile').style.display='';
	  YAHOO.example.share_container.share_popup.show();
	  valid_no = false;
	}
      
      if(valid_no)
	{  
	  download_build();
	  hidedownloadpopup();
	}
    }

function submitForm()
{
	var keynum;
	if(window.event) // IE
  	{
  		keynum = e.keyCode;
  	}
	else if(e.which) // Netscape/Firefox/Opera
  	{
  		keynum = e.which;
  	}

	if(keynum==13)
	{
	 document_submit();
	}
}
}