
//Javascript
//TO FETCH POLICY LIST
var xmlhttp;
function fn_fetchpolicy(str)
  {
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
    {
    alert ("Your browser does not support XML HTTP Request");
    return;
    }
  var url="fetchpolicy.php";
  url=url+"?q="+str;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }

function stateChanged()
  {
  if (xmlhttp.readyState==4)
    {
    document.getElementById("view").innerHTML=xmlhttp.responseText;
    }
  }
//FOR DETAILS
function fn_details(str)
  {
  xmlhttp=GetXmlHttpObject();
  if (xmlhttp==null)
    {
    alert ("Your browser does not support XML HTTP Request");
    return;
    }
  var url="ratepolicy_details.php";
  url=url+"?q="+str;
  url=url+"&sid="+Math.random();
  xmlhttp.onreadystatechange=stateChanged0;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }

function stateChanged0()
  {
  if (xmlhttp.readyState==4)
    {
    document.getElementById("details").innerHTML=xmlhttp.responseText;
    }
  }


//FOR ALPHABETICAL LISTING
function fn_alpha(pid,str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XML HTTP Request");
return;
}
  var url="ratepolicy_alpha.php";
  url=url+"?q="+str;
  url=url+"&pid="+pid;
  xmlhttp.onreadystatechange=stateChanged1;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }

function stateChanged1()
{
  if (xmlhttp.readyState==4)
  {
  document.getElementById("view").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject()
{
if(window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
} 

// VOTE RATING VALIDATION
function voting() {
 if((document.rate.vote[0].checked == false) && (document.rate.vote[1].checked == false) && (document.rate.vote[2].checked == false) && (document.rate.vote[3].checked == false) && (document.rate.vote[4].checked == false)) {
alert('Please Select Your Vote Option!');
return false;
 }
}

/***********************************************
*-* Popup Box
************************************************/
var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all
var dragswitch=0
var nsx
var nsy
var nstemp

function drag_dropns(name) {
 if (!ns4)
 return
 temp=eval(name)
 temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
 temp.onmousedown=gons
 temp.onmousemove=dragns
 temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}

function dragns(e){
 if (dragswitch==1){
 temp.moveBy(e.x-nsx,e.y-nsy)
 return false
 }
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

function drag_drop(e) {
 if (ie4&&dragapproved) {
 crossobj.style.left=tempx+event.clientX-offsetx
 crossobj.style.top=tempy+event.clientY-offsety
 return false
 }
 else if (ns6&&dragapproved) {
 crossobj.style.left=tempx+e.clientX-offsetx+"px"
 crossobj.style.top=tempy+e.clientY-offsety+"px"
 return false
 }
}

function initializedrag(e) {
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar") {
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")

function hidebox() {
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
if (ie4||ns6)
crossobj.style.visibility="hidden"
else if (ns4)
document.showimage.visibility="hide"
}

//Javascript FOR FILTER
function plus() {
if(document.getElementById("portfolio").value=="") {
alert('Please Select Portfolio');
return false;
}
document.getElementById("plus").style.display = "none";
document.getElementById("minus").style.display = "block";
document.getElementById("options").style.display = "block";
}

function minus() {
document.getElementById("plus").style.display = "block";
document.getElementById("minus").style.display = "none";
document.getElementById("options").style.display = "none";
}

//SMS,PLUGIN,EMAIL,URL TAB HIDE AND SHOW
function toggle_visibility(id) {
 var e = document.getElementById(id);
 if(e.style.display == 'block')
 e.style.display = 'none';
 else
 e.style.display = 'block';
	
	if (id == 'sms')
	{ 
		if(document.getElementById('locksms').value == "") {
			document.getElementById('sms').style.display = 'none';
			alert('Please Register or Login to send sms');
			return false;
			}
		else	{	
			document.getElementById('email1').style.display = 'none';
			document.getElementById('url1').style.display = 'none';
			document.getElementById('plugin1').style.display = 'none';  	 
			document.getElementById('emailinfo').style.display = 'none'; 
			document.getElementById('captcha').src = '/modules/captcha/securimage_show.php?' + Math.random();
		}
	}
	else if(id == 'email1')
	{ 
	document.getElementById('sms').style.display = 'none'; 
	document.getElementById('emailinfo').style.display = 'none';
	document.getElementById('url1').style.display = 'none';  	 
	document.getElementById('plugin1').style.display = 'none';  	  
	document.getElementById('captcha1').src = '/modules/captcha/securimage_show.php?' + Math.random();
	}
	else if(id == 'url1')
	{
	document.getElementById('sms').style.display = 'none'; 
	document.getElementById('emailinfo').style.display = 'none';
	document.getElementById('email1').style.display = 'none';  	  
	document.getElementById('plugin1').style.display = 'none';  	 
	document.getElementById('captcha2').src = '/modules/captcha/securimage_show.php?' + Math.random();
	}
	else 	
	{
	document.getElementById('sms').style.display = 'none'; 
	document.getElementById('emailinfo').style.display = 'none';
	document.getElementById('email1').style.display = 'none';  	  
	document.getElementById('url1').style.display = 'none';  	 
	document.getElementById('captcha3').src = '/modules/captcha/securimage_show.php?' + Math.random();
	}
}

function fn_smsnumber(e) {
var keycode;
 if(window.event) {
 keycode = window.event.keyCode;
 }
 else if(e) {  
 keycode = e.which;
 }
 if ((keycode==0)||(keycode==8)||(keycode==44)||(keycode >= 48 && keycode <= 57)||(keycode==127)) 
 {
 }
 else 
 {
 alert("Numbers Only");
 return false;
 }
}

function fn_usernamekey(e) {
 var keycode;
 if(window.event)
 {
 keycode = window.event.keyCode;
 }
 else if(e)
 { 
 keycode = e.which;
 }
 if ((keycode==0) || (keycode==8) || (keycode==44) || (keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122) || (keycode==127)) 
 {
 }
 else 
 {
 alert("Alphabets Only");
 return false;
 }
}

//JQUERY INCLUDED
document.write("<script type='text/javascript' src='/scripts/jquery/jquery/jquery.js'></script>");
//SHARE THROUGH SMS *****************************************************************************************
function sendsms()
{
if(document.sms_form.yourname.value == '')
	{ 
	alert('Please enter your name before sending the sms');
	document.sms_form.yourname.focus();
	return false;
	}
if(document.sms_form.yournumber.value == '')
	{ 
	alert('Please enter your mobile number before sending the sms');
	document.sms_form.yournumber.focus();
	return false;
	}
if(document.sms_form.smsnumber.value == '')
	{
	alert('Please enter the mobile number you like to sent');
	document.sms_form.smsnumber.focus();
	return false;
	}
if(document.sms_form.smsnumber.value != '')
	{
	var smso=document.sms_form.smsnumber.value;
	var smssplit=smso.split(",");
		for(k=0;k<smssplit.length;k++)
		{
			if(smssplit[k].length!=10)
			{
			alert('Please check the mobile numbers');
			return false;
			}
		}
	}
if(document.sms_form.security_code.value == '')
	{
	alert('Please Enter the Security Code');
	document.sms_form.security_code.focus();
	return false;
	}

 var scode = document.sms_form.security_code.value;
 var smsno = document.sms_form.smsnumber.value;
 var hidden = document.sms_form.hiddenid.value;
	
$.get("ratepolicy_sms.php",{security_code:scode,smsnumber:smsno,hiddenid:hidden},
function (resp)
{
 //alert(resp);
 if(resp == 1)
 {
 $('#sms').hide();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=green>SMS Sent Successfully</font></center>";
 document.sms_form.security_code.value='';
 //document.sms_form.yourname.value='';
 //document.sms_form.yournumber.value='';
 document.sms_form.smsnumber.value='';
 }
 else if(resp==2)
 {
 $('#sms').show();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>Invalid Code. Please try again!</font></center>";
 document.sms_form.security_code.value='';
 //document.sms_form.yourname.value='';
 //document.sms_form.yournumber.value='';
 //document.sms_form.smsnumber.value='';
 }
 else
 {
 $('#sms').show();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>SMS Not Sent. Please try again!</font></center>";
 document.sms_form.security_code.value='';
 //document.sms_form.yourname.value='';
 //document.sms_form.yournumber.value='';
 //document.sms_form.smsnumber.value='';
 }
 }
 );
}

//SHARE THROUGH EMAIL *******************************************************************************************
function sendemail()
{
if(document.email_form.sname.value == '') {
 alert('Please Enter Your name before sending the email');
 document.email_form.sname.focus();
 return false;
}
if(document.email_form.senderemail.value == '') {
 alert('Please Enter your email id');
 document.email_form.senderemail.focus();
 return false;
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.email_form.senderemail.value))
{ }
else
{
alert("Invalid E-mail Address! Please re-enter.");
document.email_form.senderemail.focus();
return false;
}
if(document.email_form.emailid.value == '') {
 alert('Please enter to email');
 document.email_form.emailid.focus();
 return false;
}
if(document.email_form.emailid.value != '') {
 var emailo=document.email_form.emailid.value;
 var emailsplit=emailo.split(",");
 //alert(emailsplit.length);
 	for(p=0;p<emailsplit.length;p++)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailsplit[p])) { 
		}
		else {
		alert('Please check the To email');
		return false;
		}
	}
}
if(document.email_form.security_code.value == '') {
alert('Please Enter the Security Code');
document.email_form.security_code.focus();
return false;
}

  var scode = document.email_form.security_code.value;
  var state = document.email_form.statevalue.value;
  var mail = document.email_form.emailid.value;
  var hidden = document.email_form.hiddenid.value;
  var sendername = document.email_form.sname.value;
 $.get("ratepolicy_email.php",{security_code:scode,stateid:state,hiddenid:hidden,emailid:mail,sentname:sendername},
function (resp)
{
 //alert(resp);
 if(resp == 1)
 {
 $('#email1').hide();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=green>Mail Sent Successfully</font></center>";
 document.email_form.security_code.value='';
 //document.email_form.sname.value='';
 //document.email_form.senderemail.value='';
 document.email_form.emailid.value='';
 }
 else if(resp == 2)
 {
 $('#email1').show();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>Invalid Code. Please try again!</font></center>";
 document.email_form.security_code.value='';
 //document.email_form.sname.value='';
 //document.email_form.senderemail.value='';
 document.email_form.emailid.value='';
 }
 else
 {
 $('#email1').show();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>Not Sent. Please try again!</font></center>";
 document.email_form.security_code.value='';
 //document.email_form.sname.value='';
 //document.email_form.senderemail.value='';
 //document.email_form.emailid.value='';
 }
}
);
}

//SHARE THROUGH URL ******************************************************************************************** 
function sendurl()
{
if(document.url_form.sname.value == '') {
 alert('Please Enter Your name before sending the email');
 document.url_form.sname.focus();
 return false;
}
if(document.url_form.senderemail.value == '') {
 alert('Please Enter your email id');
 document.url_form.senderemail.focus();
 return false;
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.url_form.senderemail.value))
{ }
else {
alert("Invalid E-mail Address! Please re-enter.");
document.url_form.senderemail.focus();
return false;
}
if(document.url_form.emailid.value == '') {
 alert('Please enter to email');
 document.url_form.emailid.focus();
 return false;
}
if(document.url_form.emailid.value != '') {
 var emailo=document.url_form.emailid.value;
 var emailsplit=emailo.split(",");
 //alert(emailsplit.length);
  for(p=0;p<emailsplit.length;p++)
  {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailsplit[p])) { 
  }
  else {
  alert('Please check the To email');
  return false;
  }
  }
}
if(document.url_form.security_code.value == '') {
 alert('Please Enter the Security Code');
 document.url_form.security_code.focus();
 return false;
}

 var uscode = document.url_form.security_code.value;
 var ustate = document.url_form.statevalue.value;
 var umail = document.url_form.emailid.value;
 var sname = document.url_form.sname.value; 
 var uhidden = document.url_form.hiddenid.value;
 var url = document.url_form.urlid.value;	
      
$.get("ratepolicy_email.php",{usecurity_code:uscode,ustateid:ustate,uhiddenid:uhidden,uemailid:umail,urlid:url,uname:sname},
function (resp)
{
 //alert(resp);
 if(resp == 1)
 {
 $('#email1').hide();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=green>Mail Sent Successfully</font></center>";
 document.url_form.security_code.value='';
 document.url_form.emailid.value='';
 document.getElementById('url1').style.display="none";
 }
 else if(resp == 2)
 {
 $('#email1').hide();//hides body content
 $('#emailinfo').show();//shows spinner
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>Invalid Code. Please try again!</font></center>";
 document.url_form.security_code.value='';
 //document.url_form.sname.value='';
 //document.url_form.senderemail.value='';
 document.url_form.emailid.value='';
 }
 else   
 {
 document.getElementById('emailinfo').innerHTML = "<center><font color=red>Mail Not Sent. Please try again!</font></center>";
 document.url_form.security_code.value='';
 //document.url_form.sname.value='';
 //document.url_form.senderemail.value='';
 document.url_form.emailid.value='';
 } 
}
);
}


// Plugin Validation
function sendplugin()
{
if(document.plugin_form.sname.value == '') {
alert('Please Enter Your name before sending the email');
document.plugin_form.sname.focus();
return false;
}
if(document.plugin_form.senderemail.value == '') {
alert('Please Enter your email id');
document.plugin_form.senderemail.focus();
return false;
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.plugin_form.senderemail.value))
{ }
else {
alert("Invalid E-mail Address! Please re-enter.");
document.plugin_form.senderemail.focus();
return false;
}
if(document.plugin_form.emailid.value == '') {
alert('Please enter to email');
document.plugin_form.emailid.focus();
return false;
}
if(document.plugin_form.emailid.value != '') {
var emailo=document.plugin_form.emailid.value;
var emailsplit=emailo.split(",");
//alert(emailsplit.length);
 for(p=0;p<emailsplit.length;p++) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailsplit[p])) { 
 }
 else {
 alert('Please check the To email');
 return false;
 }
 }
}
if(document.plugin_form.security_code.value == '') {
 alert('Please Enter the Security Code');
 document.plugin_form.security_code.focus();
 return false;
}

 var pscode = document.plugin_form.security_code.value;
 var pstate = document.plugin_form.statevalue.value;
 var pmail = document.plugin_form.emailid.value;
 var psname = document.plugin_form.sname.value; 
 var phidden = document.plugin_form.hiddenid.value;
 var plugin = document.plugin_form.pluginid.value;	
 
$.get("ratepolicy_email.php",{psecurity_code:pscode,pstateid:pstate,phiddenid:phidden,pemailid:pmail,pluginid:plugin,uname:psname},

function (resp)
{
	//alert(resp);
    if(resp == 1)
    {
	$('#email1').hide();//hides body content
  	$('#emailinfo').show();//shows spinner
    document.getElementById('emailinfo').innerHTML = "<center><font color=green>Mail Sent Successfully</font></center>";
	document.plugin_form.security_code.value='';
	document.plugin_form.emailid.value='';
	document.getElementById('plugin1').style.display="none";
    }
	else if(resp == 2)
	{
	$('#email1').hide();//hides body content
    $('#emailinfo').show();//shows spinner
    document.getElementById('emailinfo').innerHTML = "<center><font color=red>Security code is invalid</font></center>";
	document.plugin_form.security_code.value='';
	//document.plugin_form.sname.value='';
	//document.plugin_form.senderemail.value='';
	document.plugin_form.emailid.value='';
	}
    else   
    {
    document.getElementById('emailinfo').innerHTML = "<center><font color=red>Mail Not Sent. Please try again!</font></center>";
    document.plugin_form.security_code.value='';
	//document.plugin_form.sname.value='';
	//document.plugin_form.senderemail.value='';
	document.plugin_form.emailid.value='';
    } 
 }
 );
}

//TO DISPLAY COMMENT POSTING FORM
function disp1() {
 document.getElementById('dispcomm').style.display = 'none';
 document.getElementById('showform').style.display = '';
 document.getElementById('loginspan').style.display='';
 document.getElementById('entercomm').style.display = '';
 document.getElementById('captcha4').src = '/modules/captcha/securimage_show.php?' + Math.random();
}

//ADD AND VIEW COMMENTS ************************************************************************************
var comtype = "ratepolicy";
function post_comment(pid)
{
if(document.vote.comment_text.value == '') {
alert('Please Enter your Comments');
document.vote.comment_text.focus();
return false;
}
if(document.vote.comment_text.value.substring(0,1) == ' ') {
alert('First letter should not be space in your name');
document.vote.comment_text.value = "";
document.vote.comment_text.focus();
return false;
}
if(document.vote.name.value == '') {
alert('Please Enter your Name');
document.vote.name.focus();
return false;
}
if(document.vote.name.value.substring(0,1) == ' ') {
alert('First letter should not be space in your name');
document.vote.name.value = "";
document.vote.name.focus();
return false;
}
if(document.vote.email.value == '') {
alert('Please Enter your email');
document.vote.email.focus();
return false;
}
if(document.vote.email.value.substring(0,1) == ' ') {
alert('First letter should not be space in your name');
document.vote.email.value = "";
document.vote.email.focus();
return false;
}
if(document.vote.email.value != '') {
if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.vote.email.value))
{ }
else {
alert("Invalid Email Id ! Please Enter again");
document.vote.email.value= ""; 
return false;
}	   
}
if(document.vote.security_code.value == "") {
alert('Please enter the security code');
document.vote.security_code.focus();
return false;
}

 var comm = document.vote.comment_text.value;
 var myname = document.vote.name.value;
 var mail = document.vote.email.value;
 var pqid = pid;
 var secode = document.vote.security_code.value;

$.get("/modules/comments/add_comments.php",{comment:comm,name:myname,email:mail,pid:pqid,security_code:secode,type:comtype},
function (resp)
{
//alert(resp);
if(resp == 404)
{
 alert('Invalid Security Code');
 return false;
}
else if(resp == 1)   
{
$.get("/modules/comments/view_comments.php",{pqid:pid,type:comtype},
function (resp)
{
 document.getElementById('dispcomm').innerHTML = resp;
 $('#showform').hide();//hides body content
 $('#dispcomm').show();//shows spinner
 document.vote.comment_text.value='';
 //document.vote.name.value='';
 //document.vote.email.value='';
 document.vote.security_code.value='';
 document.getElementById('errmsg').style.display = "none";
 });
}
else { 
}
}
);
}

function disp(pid) {
$.get("/modules/comments/view_comments.php",{pqid:pid,type:comtype},
function(resp)
{
 document.getElementById('dispcomm').innerHTML = resp;
 document.getElementById('loginspan').style.display='';
}
);
 document.getElementById('dispcomm').style.display = '';
 document.getElementById('entercomm').style.display = '';
 document.getElementById('showform').style.display = 'none';
 document.getElementById('loginspan').style.display='';
}

///COMMENTS pagination
function load_page(pno,pid)
{
$.get("/modules/comments/view_comments.php",{pqid : pid,page : pno,type:comtype},
function(resp)
{
 document.getElementById('dispcomm').innerHTML = resp;
 docuemnt.getElementById('loginspan').style.display='';
 document.getElementById('entercomm').style.display = '';
}
);
}

//For Getting Email Address Book value
var xmlHttps1;
function fn_sent_ajax(fname,val)
{
   xmlHttps1=GetXmlHttpObject();
	if (xmlHttps1==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
   var url="sent_qus_ajax.php?uid="+val+"&fname="+fname;
  	xmlHttps1.onreadystatechange=function() { stateChanged_email()};
	xmlHttps1.open("GET",url,true);
	xmlHttps1.send(null);
    
}
function stateChanged_email() 
{
	if(xmlHttps1.readyState==4) 
	{
		document.getElementById("select_mail").innerHTML=xmlHttps1.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttps1=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttps1=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttps1=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttps1=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttps1;
}
//For Getting Email Address Book value Ends

//For SMS address book
var xmlHttps2;
function fn_sent_sms(fname,val)
{
   xmlHttps2=GetXmlHttpObject();
	if (xmlHttps2==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
   var url="sent_qus_ajax.php?uid="+val+"&fname="+fname;
  	xmlHttps2.onreadystatechange=function() { stateChanged_sms()};
	xmlHttps2.open("GET",url,true);
	xmlHttps2.send(null);
    
}
function stateChanged_sms() 
{
	if(xmlHttps2.readyState==4) 
	{
		document.getElementById("select_msg").innerHTML=xmlHttps2.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttps2=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttps2=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttps2=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttps2=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttps2;
}
//For SMS address book Ends

//For Getting Plugin Address Book value
var xmlHttps3;
function fn_sent_plugin(fname,val)
{
   xmlHttps3=GetXmlHttpObject();
	if (xmlHttps3==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
   var url="sent_qus_ajax.php?uid="+val+"&fname="+fname;
  	xmlHttps3.onreadystatechange=function() { stateChanged_plugin()};
	xmlHttps3.open("GET",url,true);
	xmlHttps3.send(null);
}

function stateChanged_plugin() 
{
	if(xmlHttps3.readyState==4) 
	{
		document.getElementById("select_plugin").innerHTML=xmlHttps3.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttps3=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttps3=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttps3=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttps3=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttps3;
}
//For Getting Plugin Address Book value Ends

//For Getting URL Address Book value
var xmlHttps4;
function fn_sent_url(fname,val)
{
   xmlHttps4=GetXmlHttpObject();
	if (xmlHttps4==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
   var url="sent_qus_ajax.php?uid="+val+"&fname="+fname;
  	xmlHttps4.onreadystatechange=function() { stateChanged_url()};
	xmlHttps4.open("GET",url,true);
	xmlHttps4.send(null);
    
}
function stateChanged_url() 
{
	if(xmlHttps4.readyState==4) 
	{
		document.getElementById("select_url").innerHTML=xmlHttps4.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttps4=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttps4=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttps4=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttps4=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttps4;
}
//For Getting URL Address Book value Ends

// To load Email Address Book
$(document).ready(function() {
var uid = document.getElementById('user_id').value;
var fname = "email";
fn_sent_ajax(fname,uid);
});

// To load Plugin Address Book
$(document).ready(function() {
var uid = document.getElementById('user_id').value;
var fname = "plugin";
fn_sent_plugin(fname,uid);
});

// To load URL Address Book
$(document).ready(function() {
var uid = document.getElementById('user_id').value;
var fname = "url";
fn_sent_url(fname,uid);
});
//To load SMS address book
$(document).ready(function() {
var uid = document.getElementById('user_id').value;
var fname = "sms";
fn_sent_sms(fname,uid);
});

//code for address book add
function fn_add_url(count,values)
{
 	var i,to_addr="";
 	if(values == "url_all"){
	for(i=0;i<count;i++)
	{
	    var uemt="uaddr"+i;
	    if(document.getElementById(uemt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(uemt).value)+",";
	    }
	}
    if(count != "0")
	    document.url_form.emailid.value=document.url_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	    
	}
	
	if(values == "url_alls"){
		for(i=0;i<count;i++)
	{
	    var uemt="uaddress"+i;
	    if(document.getElementById(uemt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(uemt).value)+",";
	    }
	}
    if(count != "0")
	    document.url_form.emailid.value=document.url_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	}
}

function chk_all_url(count,values)
{

  if(values == "url_all") {
  if(document.getElementById('url_all').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var uemt = "uaddr"+i;
  	document.getElementById(uemt).checked = true;
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var uemt="uaddr"+i;
		document.getElementById(uemt).checked=false;
	}
  }
  }
  
  if(values == "url_alls") {
  if(document.getElementById('url_alls').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var uemt = "uaddress"+i;
  	document.getElementById(uemt).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var uemt="uaddress"+i;
		document.getElementById(uemt).checked=false;
	}
  }
  }
  
}

//Address Book code ends-->

//code for address book add
function fn_add_bk(count,values)
{
 	var i,to_addr="";
 	if(values == "all"){
	for(i=0;i<count;i++)
	{
	    var emt="addr"+i;
	    if(document.getElementById(emt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(emt).value)+",";
	    }
	}
    if(count != "0")
	    document.email_form.emailid.value=document.email_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	    
	}
	
	if(values == "alls"){
		for(i=0;i<count;i++)
	{
	    var emt="address"+i;
	    if(document.getElementById(emt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(emt).value)+",";
	    }
	}
    if(count != "0")
	    document.email_form.emailid.value=document.email_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	}
}

function chk_all(count,values)
{

  if(values == "all") {
  if(document.getElementById('all').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var emt = "addr"+i;
  	document.getElementById(emt).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var emt="addr"+i;
		document.getElementById(emt).checked=false;
	}
  }
  }
  
  if(values == "alls") {
  if(document.getElementById('alls').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var emt = "address"+i;
  	document.getElementById(emt).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var emt="address"+i;
		document.getElementById(emt).checked=false;
	}
  }
  }
  
}

function fn_addmorecheck(){
    document.getElementById('mail5').style.display = 'none';
    document.getElementById('mailall').style.display = 'block';
}
function fn_addmoreplugincheck(){
    document.getElementById('plugin5').style.display = 'none';
    document.getElementById('pluginall').style.display = 'block';
}
function fn_addmoreurlcheck(){
    document.getElementById('url5').style.display = 'none';
    document.getElementById('urlall').style.display = 'block';
}
//Address Book code ends-->

//code for plugin address book add
function fn_add_plug(count,values)
{
 	var i,to_addr="";
 	if(values == "plugin_all"){
	for(i=0;i<count;i++)
	{
	    var pemt="paddr"+i;
	    if(document.getElementById(pemt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(pemt).value)+",";
	    }
	}
    if(count != "0")
	    document.plugin_form.emailid.value=document.plugin_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	    
	}
	
	if(values == "plugin_alls"){
		for(i=0;i<count;i++)
	{
	    var pemt="paddress"+i;
	    if(document.getElementById(pemt).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(pemt).value)+",";
	    }
	}
    if(count != "0")
	    document.plugin_form.emailid.value=document.plugin_form.emailid.value+to_addr.substring(0,((to_addr.length)-1));
	}
}

function chk_all_plugin(count,values)
{

  if(values == "plugin_all") {
  if(document.getElementById('plugin_all').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var pemt = "paddr"+i;
  	document.getElementById(pemt).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var pemt="paddr"+i;
		document.getElementById(pemt).checked=false;
	}
  }
  }
  
  if(values == "plugin_alls") {
  if(document.getElementById('plugin_alls').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var pemt = "paddress"+i;
  	document.getElementById(pemt).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var pemt="paddress"+i;
		document.getElementById(pemt).checked=false;
	}
  }
  }
  
}

//plugin Address Book code ends-->

//address book sms add-->
function fn_add_num(count,values)
{
 	var i,to_addr="";
 	if(values == "sms_all"){
	for(i=0;i<count;i++)
	{
	    var sms="sms_addr"+i;
	    if(document.getElementById(sms).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(sms).value)+",";
	    }
	}
    if(count != "0")
	    document.getElementById('smsnumber').value=document.getElementById('smsnumber').value+to_addr.substring(0,((to_addr.length)-1));
	    
	}
	
	if(values == "sms_alls"){
		for(i=0;i<count;i++)
	{
	    var sms="sms_address"+i;
	    if(document.getElementById(sms).checked==true)
	    {
	       to_addr=to_addr+(document.getElementById(sms).value)+",";
	    }
	}
    if(count != "0")
	    document.getElementById('smsnumber').value=document.getElementById('smsnumber').value+to_addr.substring(0,((to_addr.length)-1));
	}
}

function chk_all_sms(count,values)
{

  if(values == "sms_all") {
  if(document.getElementById('sms_all').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var sms = "sms_addr"+i;
  	document.getElementById(sms).checked = true;

	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var sms="sms_addr"+i;
		document.getElementById(sms).checked=false;
	}
  }
  }
  
  if(values == "sms_alls") {
  if(document.getElementById('sms_alls').checked == true)
  {
	for(i=0;i<count;i++)
	{
  
   	var sms = "sms_address"+i;
  	document.getElementById(sms).checked = true;

		
	}
  }
  else
  {
	for(i=0;i<count;i++)
	{
		var sms="sms_address"+i;
		document.getElementById(sms).checked=false;
	}
  }
  }
}

function fn_addmoresmscheck(){
    document.getElementById('sms5').style.display = 'none';
    document.getElementById('smsall').style.display = 'block';
}
//address book code ends-->

