var return_check='';
var form_content=null;
var mobile_num=null;
var advt_id=null;
var validate_myname=null;
function show_sms_form(e,compname,comid,pre_ad)
{
	var date=new Date();
	var time=date.getTime();	
	hideall_div();
	var posi = new Array();
	posi=trackClick(e);
	//Added for Dual SMS - myname field validation by Ramesh
	validate_myname=pre_ad;
	
	//End
	var sms_form='<form name="sms_form" onsubmit="return validatemobile(this);">';
		sms_form+='<table cellpadding="0" cellspacing="0" border="0" width="361" height="138" bgcolor="#F0F8FB" style="border:3px solid #018BCC;">';
		sms_form+='<tr><td colspan="2" height="20" style="padding-left:15px; line-height:20px;"><font class="mediumtxt"><b>SMS '+compname+' details to my mobile</b><br />(Only in india)</font></td><td valign="top" style="padding-right:4px;"><a href="javascript:;"  class="mediumtxt" onclick="javascript:hide_sms_div(\'div_sms\');" style="font-size:12px;" title="Close"><b>x</b></a></td></tr>';
		sms_form+='<tr><td valign="top" style="padding-left:25px; line-height:20px;" colspan="3"><div id="div_error"></div></td></tr>';
		//Added for Dual SMS option by Ramesh
		if(pre_ad==1){
			sms_form+='<tr><td valign="top" style="padding-left:20px; line-height:20px;"><font class="mediumtxt"><b>My Name &nbsp;:&nbsp;</b></font></td><td style="padding-left:20px; line-height:20px;"><input type="text" name="my_name" class="textfield" style="width:180px;"/></td><td>&nbsp;</td></tr>';
			sms_form+='<tr><td colspan="3"><img src="images/trans.gif" width="215" height="10" /></td></tr>';
		}
		//end
		sms_form+='<tr><td valign="top" style="padding-left:20px; line-height:20px;"><font class="mediumtxt"><b>My Mobile No&nbsp;:&nbsp;</b></font></td><td style="padding-left:20px; line-height:20px;"><input type="text" maxlength="10" name="mobile_no" class="textfield" style="width:180px;"/></td><td>&nbsp;</td></tr>';
		sms_form+='<tr><td valign="top" style="padding-left:20px; line-height:25px;" colspan="2"><font class="mediumtxt"><b>Enter the text as it is shown in the box below&nbsp;:&nbsp;</b></font></td><td>&nbsp;</td></tr>';
		sms_form+='<tr><td style="padding-left:30px;line-height:30px;"><img align="center" src="create_image.php?time='+time+'" alt="test" border="0" ></td><td style="padding-left:20px; line-height:20px;"><input type="text" maxlength="5" name="security_number" class="textfield" style="width:180px;"/></td><td>&nbsp;</td></tr>';
		//Added for Dual SMS by Ramesh
		if(pre_ad==1){
			sms_form+='<tr><td colspan="3"><img src="images/trans.gif" width="215" height="10" /></td></tr>';
			sms_form+='<tr><td colspan="3" class="mediumtxt" style="padding:5px 15px;">Would you like your details to be provided to the advertiser to further contact you regarding offers and promotions?&nbsp;&nbsp;</td></tr>';
			sms_form+='<tr><td colspan="3" class="mediumtxt" style="padding:0px 15px;"><input type="radio" name="pread_option" value="1" checked="checked" />Yes&nbsp;&nbsp;<input type="radio" name="pread_option" value="0" />No</td></tr>';
		}
		//End
		sms_form+='<tr><td colspan="3"><img src="images/trans.gif" width="215" height="10" /></td></tr>';
		sms_form+='<tr><td>&nbsp;</td><td style="padding-left:20px;"><input type="image" src="images/blue-smsbutton.gif"/></td><td>&nbsp;</td></tr>';
		sms_form+='<tr><td colspan="3"><img src="images/trans.gif" width="215" height="10" /></td></tr>';
		sms_form+='<input type="hidden" name="comp_id" id="comp_id" value="'+comid+'"></table>';
		sms_form+='</form>';
	document.getElementById("div_sms").style.visibility="visible";
	document.getElementById("div_sms").style.left=posi[0]+"px";	
	document.getElementById("div_sms").style.top=posi[1]+"px";	
	document.getElementById("div_sms").innerHTML=sms_form;
}
function hide_sms_div(div_name)
{
	document.getElementById("div_sms").style.visibility="hidden";
}

function hideall_div()
{
	document.getElementById("div_sms").style.visibility="hidden";
	document.getElementById("div_forwardtofriend").style.visibility="hidden";
	document.getElementById("div_reportspam").style.visibility="hidden";
}

function validatemobile(frm)
{
	//Added for Dual SMS- myname validation by Ramesh
	if(validate_myname==1){
		my_name=frm.my_name.value; 
			 
		var radioGrp = frm['pread_option'];
		for(i=0; i < radioGrp.length; i++){
			if (radioGrp[i].checked == true) {
				var radioValue = radioGrp[i].value;
				pread_option=radioValue;
			}
		}
		if(frm.my_name.value=="")
		{
			alert("Please enter your name.");
			frm.my_name.focus();
			return false;
		}
	}
	else{
	   my_name='';
	   pread_option=0;
	}
	//End		
	if(frm.mobile_no.value=="")
	{
		alert("Please enter your mobile number.");
		frm.mobile_no.focus();
		return false;
	}
	if(isNaN(frm.mobile_no.value))
	{
		alert("Please enter a valid mobile number.");
		frm.mobile_no.focus();
		return false;
	}
	if (frm.mobile_no.value.length < 10 )
	{
		alert ("Please enter 10 digit Mobile number.");
		frm.mobile_no.focus();
		return false;	
	}
	if (frm.mobile_no.value.length > 10 )
	{
		alert ("Please enter a valid mobile number.");
		frm.mobile_no.focus();
		return false;	
	}
	if((frm.mobile_no.value).substr(0,1)!="9")
	{
		alert ("Mobile number starts with '9' only.");
		frm.mobile_no.focus();
		return false;
	}
	if(frm.security_number.value=="")
	{
		alert("Please enter given security text.");
		frm.security_number.focus();
		return false;
	}
	if(frm.security_number.value!=''){
		//alert(frm.security_number.value);
		//alert(security_code);
		form_content=document.getElementById("div_sms").innerHTML;
		mobile_num=frm.mobile_no.value;
		advt_id=frm.comp_id.value;
		var sec_num=frm.security_number.value;
		//alert(form_content);
		var loading_form='<table cellpadding="0" cellspacing="0" border="0" width="361" height="138" bgcolor="#F0F8FB"               style="border:3px solid #018BCC;">';
	loading_form+='<tr><td width="100%" align="center"><img src="http://www.indiapages.com/images/loading.gif" height="32" width="32" /><br /><font class="mediumtxt">Please wait.. the data is being transferred.</font></tr>';
	loading_form+='</table>';
	document.getElementById("div_sms").innerHTML=loading_form;
		//document.all.sms_form.mobile_no.value,document.all.sms_form.comp_id.value
		check_security(sec_num);
	}
	//send_sms(frm.mobile_no.value,frm.comp_id.value);
	return false;
}
function check_security(c_id){
	var check_url="check_security.php?c_id="+c_id;
	http = new getHTTPObject();
	if (http) 
	{
		http.open("GET", check_url, true);
		http.send(null);
		http.onreadystatechange = handlersendsmsHttpResponse1;
	}	
}
function handlersendsmsHttpResponse1()
{
	
	if(http.readyState == 4)
	{
		return_check=http.responseText;
		if(parseInt(return_check)!=0)
		{
			send_sms(mobile_num,advt_id);
		}
		else
		{
			document.getElementById("div_sms").innerHTML=form_content;
			document.getElementById("div_error").innerHTML="<font class='errtxt'>Please enter correct security text</font>";
		}
		//document.getElementById("div_sms").innerHTML=http.responseText;
		
	}
}
function send_sms(mobile_num, ad_id)
{
	var loading_form='<table cellpadding="0" cellspacing="0" border="0" width="361" height="138" bgcolor="#F0F8FB" style="border:3px solid #018BCC;">';
	loading_form+='<tr><td width="100%" align="center"><img src="http://www.indiapages.com/images/loading.gif" height="32" width="32" /><br /><font class="mediumtxt">Please wait.. the data is being transferred.</font></tr>';
	loading_form+='</table>';
	document.getElementById("div_sms").innerHTML=loading_form;
	var smsurl="http://www.indiapages.com/send_sms.php?mobile_num="+mobile_num+"&ad_id="+ad_id+"&my_name="+my_name+"&pread_option="+pread_option;
	http = new getHTTPObject();
	if (http) 
	{
		http.open("GET", smsurl, true);
		http.send(null);
		http.onreadystatechange = handlersendsmsHttpResponse;
	}
}

function handlersendsmsHttpResponse()
{
	if(http.readyState == 4)
	{
		var return_str=http.responseText;
		document.getElementById("div_sms").innerHTML=return_str;
	}
}

function trackClick(e) {
	var posi = new Array();
	//if (arguments.length == 0) e = event;
	/*if(navigator.appName.indexOf("Internet Explorer") != -1)
	{
		e=event;
	}
	else
	{
		e=window.event;
	}*/
	if (document.layers)
	{
		posi[0]=e.pageX;
		posi[1]=e.pageY;
	}
	else
	{
		posi[0]=e.clientX+document.body.scrollLeft;
		posi[1]=e.clientY+document.body.scrollTop;
	}
	return posi;
}

function getHTTPObject()
{
	var xmlhttp;
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	
		}
		catch (E)
		{
			xmlhttp = false;
		}
	
	}
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp = false;
		}
	}
	
	return xmlhttp;
}

//preloader starts


 // Time in seconds to wait before giving up on preload (broken 
  // images can cause the load to never get to 100%).
  
  var bt_timeout = 8;
  
  
  // Array of images to load; feel free to make this as long or
  // as short as you want. First element is filename (include path
  // to file), second is size of images in kB.
  
  var bt_preimages = [
	['http://www.indiapages.com/images/blue-smsbutton.gif',20],
	['http://www.indiapages.com/images/submit-button.gif',20],
	['http://www.indiapages.com/images/cancel-button.gif',20],	
	['http://www.indiapages.com/images/blue_submitbutton.gif',20]
    ];
  
  // Text to use for when loading has finished
  var bt_text_finished = '';
  
  // Text to prefix the percentage
  var bt_text_prefix = '';
  
  
  function bt_done() {
    // stub function called when script is finished, put your JS here.
    // (you could use a javascript to redirect the user)
    
    }
//preloader ends