function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function add_smiley(scode){
var scode;
document.frmsendsms.message.value+=scode;
document.frmsendsms.message.focus();
}
function switch_group(){
if(document.frmsendsms.sms_group.value!=0){
document.getElementById('or1').style.display="none";
document.getElementById('or2').style.display="none";
document.getElementById('to_contact').style.display="none";
document.getElementById('to_recipient').style.display="none";
}else{
	document.getElementById('or1').style.display="";
document.getElementById('or2').style.display="";
document.getElementById('to_contact').style.display="";
document.getElementById('to_recipient').style.display="";
	}
	}	
	function switch_contact(){
if(document.frmsendsms.sms_contact.value!=0){
document.getElementById('or1').style.display="none";
document.getElementById('or2').style.display="none";
document.getElementById('to_group').style.display="none";
document.getElementById('to_recipient').style.display="none";
}else{
	document.getElementById('or1').style.display="";
document.getElementById('or2').style.display="";
document.getElementById('to_group').style.display="";
document.getElementById('to_recipient').style.display="";
	}
	}
function switch_schedule_contact(){
if(document.frmsendsms.sms_contact.value!=0){

document.getElementById('or2').style.display="none";

document.getElementById('to_recipient').style.display="none";
}else{

document.getElementById('or2').style.display="";

document.getElementById('to_recipient').style.display="";
	}
	}
	
	
	
	
function confirm_delete(msg,turl)
  {
   var r=confirm(msg)
  if (r==true)
    {
	window.location=turl;
    }
  else
    {
    javascript:void(0);
    }
  }



	function mediacns(pagename){
		mediacns_window=window.open(pagename,'mediacns_window','toolbar=no,location=no,borders=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=0,top=0,width=600,height=400');
	}

	function refer_win(pagename){
		mediacns_window=window.open(pagename,'mediacns_window','toolbar=no,location=no,borders=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=0,top=0,width=530,height=550');
	}


	function test(obj,msg) {
		  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		  if (regex.test(obj.value))
		  {
			return true;
		  }
		  else{
			alert(msg);
			obj.focus();
			return false;
		  }
		}
	function checkint(obj,msg)
	{
	 if(isNaN(obj.value))
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	function checkempty(obj,msg)
	{
	 if(obj.value=="")
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	
	function checklength(obj,objlength,msg)
	{
	 if(obj.value.length<objlength)
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	
	function check_cell_no(obj,msg)
	{
	 if(obj.value.length<11 || obj.value.length>18 || isNaN(obj.value.substring(1)) || obj.value.substring(0,1)!='+' || (obj.value.substring(0,3)=='+92' && obj.value.length!=13))
	 {
	  alert("Please enter a valid cell#\n\nCell no. must start with + following your country code\n\n e.g. +923006101010\n\n where +92 is country code and 3006101010 is your cell no. with carrier code");
	  obj.focus();
	  return false;
	 }
	}
	
	function check_cell_no_wo_code(obj,msg)
	{
	 if(obj.value.length<7 || isNaN(obj.value))
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}
	
	
	function checkequal(obj,obj1,msg)
	{
	 if(obj.value!==obj1.value)
	 {
	  alert(msg);
	  obj1.focus();
	  return false;
	 }
	}


	function checkboxcheck(obj,msg)
	{
	 if(!obj.checked)
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}

	function restrictemail(obj,msg)
	{
	var hotmailobj = obj.value.match("hotmail.com");
	var yahooobj = obj.value.match("yahoo.com");
	var gmailobj = obj.value.match("gmail.com");
		
	if(hotmailobj || yahooobj || gmailobj)
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}


function checkemptysearch(obj,msg)
	{
	 if(obj.value<3)
	 {
	  alert(msg);
	  obj.focus();
	  return false;
	 }
	}



function check_search_Form()
	{
		if (checkempty(document.search_form.txtsearch,"Please Enter something to Search")==false) return false;

		return true;
	}



	


	function checkloginForm()
	{

		if (checkempty(document.login_form.username,"Please Enter User ID")==false) return false;
	if (checkempty(document.login_form.userpass,"Please Enter Password")==false) return false;

if (checkempty(document.login_form.scode,"Please Enter displayed Security Code")==false) return false;	

	
return true;
	}



	function validate_register(){

		if (checkempty(document.frmregister.txtname,"Please Enter Your Name")==false) return false;	
		if (checkempty(document.frmregister.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmregister.txtnumber)==false) return false;
			
		if (checkempty(document.frmregister.txtpassword,"Please Enter Password")==false) return false;
		if (checklength(document.frmregister.txtpassword,6,"Minimum password length is 6 characters")==false) return false;	
		if (checkempty(document.frmregister.txtpassword2,"Please confirm your Password")==false) return false;	
		if (checkequal(document.frmregister.txtpassword,document.frmregister.txtpassword2,"Both Passwords didn't match")==false) return false;
		if(test(document.frmregister.email, "Please enter a valid email address")==false) return false;
		if (checklength(document.frmregister.city,3,"Please enter a valid City Name")==false) return false;	
if (checkboxcheck(document.frmregister.chkaccept,"You must accept Fair Use Policy, Privacy Policy and Disclaimer to register with us")==false) return false;
if (checkempty(document.frmregister.scode,"Please Enter displayed Anti-Spam Code")==false) return false;	
	if (checklength(document.frmregister.scode,5,"Please enter a valid Anti-Spam Code")==false) return false;	

var r=confirm('You are registering '+document.frmregister.txtnumber.value+' \nPlease review and proceed if you want to register');
  if (r==true)
    {
	document.frmregister.submit();
    }
  else
    {

	return false;
    }
	

return true;
	}
	
	
	
	function validate_edit_account(){

		if (checkempty(document.frmregister.txtname,"Please Enter Your Name")==false) return false;	
			
		if (checkempty(document.frmregister.txtpassword,"Please Enter Password")==false) return false;
		if (checklength(document.frmregister.txtpassword,6,"Minimum password length is 6 characters")==false) return false;	
		if (checkempty(document.frmregister.txtpassword2,"Please confirm your Password")==false) return false;	
		if (checkequal(document.frmregister.txtpassword,document.frmregister.txtpassword2,"Both Passwords didn't match")==false) return false;
		if (checklength(document.frmregister.city,3,"Please enter a valid City Name")==false) return false;	
if (checkempty(document.frmregister.scode,"Please Enter displayed Anti-Spam Code")==false) return false;	
	if (checklength(document.frmregister.scode,5,"Please enter a valid Anti-Spam Code")==false) return false;	

var r=confirm('Do you want to save changes?');
  if (r==true)
    {
	document.frmregister.submit();
    }
  else
    {

	return false;
    }
	

return true;
	}
	
	
	
	
	function validate_register_intl(){

		if (checkempty(document.frmregister.txtname,"Please Enter Your Name")==false) return false;	
		if (checkempty(document.frmregister.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_intl_cell_no(document.frmregister.txtnumber,"Invalid Cell no.")==false) return false;
			
		if (checkempty(document.frmregister.txtpassword,"Please Enter Password")==false) return false;
		if (checklength(document.frmregister.txtpassword,"Minimum password length is 6 characters")==false) return false;	
		if (checkempty(document.frmregister.txtpassword2,"Please confirm your Password")==false) return false;	
		if (checkequal(document.frmregister.txtpassword,document.frmregister.txtpassword2,"Both Passwords didn't match")==false) return false;
			
if (checkboxcheck(document.frmregister.chkaccept,"You must accept Fair Use Policy & Privacy Policy to register with us")==false) return false;
if (checkempty(document.frmregister.scode,"Please Enter displayed Anti-Spam Code")==false) return false;	

var r=confirm('You are registering '+document.frmregister.txtnumber.value+' \nPlease review and proceed if you want to register');
  if (r==true)
    {
	document.frmregister.submit();
    }
  else
    {

	return false;
    }
	

return true;
	}
	
	
	function validate_contact(){

		if (checkempty(document.frmcontact.txtname,"Please Enter Your Name")==false) return false;	
		if (test(document.frmcontact.email,"Please Enter Your Valid Email")==false) return false;	
		if (checkempty(document.frmcontact.txtnumber,"Please Enter Your Cell No.")==false) return false;		
if (checkempty(document.frmcontact.detail,"Please Enter Detail")==false) return false;	
if (checkempty(document.frmcontact.scode,"Please Enter Anti-Spam Code")==false) return false;	


return true;
	}



function validate_login(){

		if (checkempty(document.frmlogin.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmlogin.txtnumber,"Cell No. can be only of 7 Characters and only numbers")==false) return false;
			
		if (checkempty(document.frmlogin.txtpassword,"Please Enter Password")==false) return false;
		if (checklength(document.frmlogin.txtpassword,"Minimum password length is 6 characters")==false) return false;	
return true;
	}
	
	function validate_login_intl(){

		if (checkempty(document.frmlogin1.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmlogin1.txtnumber)==false) return false;
			
		if (checkempty(document.frmlogin1.txtpassword,"Please Enter Password")==false) return false;
return true;
	}
	
	
	function validate_chpass(){

		
		if (checkempty(document.frmchpass.txtpassword,"Please Enter Password")==false) return false;
		if (checklength(document.frmchpass.txtpassword,"Minimum password length is 6 characters")==false) return false;	
		if (checkempty(document.frmchpass.txtpassword2,"Please confirm your Password")==false) return false;	
		if (checkequal(document.frmchpass.txtpassword,document.frmchpass.txtpassword2,"Both Passwords didn't match")==false) return false;
return true;
	}
	
	
	
	function validate_verify(){

		if (checkempty(document.frmverify.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmverify.txtnumber,"Cell No. can be only of 7 Characters and only numbers")==false) return false;
			
		if (checkempty(document.frmverify.vcode,"Please Enter Code")==false) return false;
		
return true;
	}
	
		function validate_verify_intl(){

		if (checkempty(document.frmverify.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmverify.txtnumber)==false) return false;
			
		if (checkempty(document.frmverify.vcode,"Please Enter Verification Code that you got on your cell")==false) return false;
		if (checkempty(document.frmverify.scode,"Please Enter Anti-Spam Code")==false) return false;
		
return true;
	}
	
	
		function validate_resend(){

		if (checkempty(document.frmverify.txtnumber,"Please Enter Your Cell No.")==false) return false;		
		if (check_cell_no(document.frmverify.txtnumber)==false) return false;
			
		if (checkempty(document.frmverify.scode,"Please Enter Anti-Spam Code")==false) return false;
		
return true;
	}
	
	
		function validate_frmaddgroup(){

		if (checkempty(document.frmaddgroup.group_name,"Please Enter Group Name")==false) return false;	
		
return true;
	}
	
	
		function validate_frmaddcontact(){

		if (checkempty(document.frmaddcontact.contact_name,"Please Enter Contact Name")==false) return false;
		if (checkempty(document.frmaddcontact.txtnumber,"Please Enter Cell No.")==false) return false;		
		if (check_cell_no_wo_code(document.frmaddcontact.txtnumber,"Cell No. can be only of 7 Characters and only numbers")==false) return false;
		
return true;
	}
	
	
			function validate_sendsms(){

if(document.frmsendsms.sms_group.value==0){
if(document.frmsendsms.sms_contact.value==0){
	
	if (checkempty(document.frmsendsms.txtnumber,"Please Enter Recipient Cell No. OR Select from Group OR Contacts")==false) return false;		
	if (check_cell_no_wo_code(document.frmsendsms.txtnumber,"Recipient Cell No. can be only of 7 Characters and only numbers")==false) return false;
	}
}
	
	if (checkempty(document.frmsendsms.message,"Please enter your message")==false) return false;	
	
	if(document.frmsendsms.sms_group.value!=0){
	
	var c_group = document.frmsendsms.sms_group.selectedIndex;
var selected_group = document.frmsendsms.sms_group.options[c_group].text;


	var r=confirm('You are sending sms to whole group \' ' +selected_group+ ' \' want to continue...?');
  if (r!=true)
    {
	return false;
    }
 	
	}

	
return true;
	}
	
	
	
	
	function validate_schedulesms(){


if(document.frmsendsms.sms_contact.value==0){
	
	if (checkempty(document.frmsendsms.txtnumber,"Please Enter Recipient Cell No. OR Select from Group OR Contacts")==false) return false;		
	if (check_cell_no_wo_code(document.frmsendsms.txtnumber,"Recipient Cell No. can be only of 7 Characters and only numbers")==false) return false;
	}

	
	if (checkempty(document.frmsendsms.message,"Please enter your message")==false) return false;	
	
		
return true;
	}
	
	
	
	
	

function animationdiv(id){
document.getElementById(id).style.visibility="visible"
}
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

function FP_swapImgRestore() {
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function FP_swapImg() {
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_preloadImgs() {
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_getObjectByID(id,o) {
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}




function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}



function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}



function confirmlink(msg,links) {

var checkin = confirm(msg);
if(checkin) {
window.location = links;
}else {
return false;
}

}




var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var calunits=document.layers? "" : "px"

var bouncelimit=32 
var direction="up"

function initbox(targetbox){
if (!dom&&!ie&&!ns4)
return

crossobj=(dom)?document.getElementById(targetbox).style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-250+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"
dropstart=setInterval("dropin()",50)
}

function dropin(){
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
if (parseInt(crossobj.top)<100+scroll_top)
crossobj.top=parseInt(crossobj.top)+40+calunits
else{
clearInterval(dropstart)
bouncestart=setInterval("bouncein()",50)
}
}

function bouncein(){
crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
if (bouncelimit<0)
bouncelimit+=8
bouncelimit=bouncelimit*-1
if (bouncelimit==0){
clearInterval(bouncestart)
}
}

function dismissbox(){
if (window.bouncestart) clearInterval(bouncestart)
crossobj.visibility="hidden"
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function togglediv(id) {
var e = document.getElementById(id);
if(e.style.display == 'none') {
e.style.display = 'block';
}
else
{
e.style.display = 'none';
}
}


function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}





function bookmark_bestsms(){
	var title = 'Best SMS - Send Free SMS to Pakistan, to any network Mobilink, Warid, Telenor, Ufone, Zong, vptcl';
	var url = 'http://www.bestsms.pk';
	
if (window.sidebar) 
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ 
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)
	window.external.AddFavorite(url, title);
}





var newImage = new Image();
var i=0;
newImage.src = "http://googleads.g.doubleclick.net/intl/en_com/images/logo_plain.png";
newImage.onerror = function(){
	for(i=0; i<=2; i++){
alert("Ooopss! It seems you are using some Ad Blocking Plugins in browser\nPlease disable it to smoothly use TextPK.com");
	}
};


var memoryduration="1 days"

function setformobjects(){
var theforms=document.forms
memorizearray=new Array()
for (i=0; i< theforms.length; i++){
for (j=0; j< theforms[i].elements.length; j++){
if (theforms[i].elements[j].className.indexOf("memorize")!=-1 && theforms[i].elements[j].type=="text")
memorizearray[memorizearray.length]=theforms[i].elements[j]
}
}
var retrievedvalues=get_cookie("mvalue"+window.location.pathname)
if (retrievedvalues!=""){
retrievedvalues=retrievedvalues.split("|")
if (retrievedvalues[retrievedvalues.length-1]!=parseInt(memoryduration)) //reset cookie if var memoryduration has changed
resetcookie("mvalue"+window.location.pathname)
else{
for (i=0; i<memorizearray.length; i++){
if (retrievedvalues[i]!="empty_value")
memorizearray[i].value=retrievedvalues[i]
}
}
}
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      end = document.cookie.indexOf(";", offset);
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function resetcookie(id){
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()-10)
document.cookie = id+"=;path=/;expires=" + expireDate.toGMTString()
}

function saveformvalues(){
var formvalues=new Array(), temp
for (i=0; i<memorizearray.length; i++){
temp=memorizearray[i].value!=""? memorizearray[i].value : "empty_value"
formvalues[formvalues.length]=escape(temp)
}
formvalues[formvalues.length]=parseInt(memoryduration)
formvalues=formvalues.join("|")
var expireDate = new Date()
expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
document.cookie = "mvalue"+window.location.pathname+"="+formvalues+"; path=/;expires=" + expireDate.toGMTString()
}

if (window.addEventListener)
window.addEventListener("load", setformobjects, false)
else if (window.attachEvent)
window.attachEvent("onload", setformobjects)
else if (document.getElementById)
window.onload=setformobjects
if (document.getElementById)
window.onunload=saveformvalues



function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) 
field.value = field.value.substring(0, maxlimit);

else
cntfield.value = maxlimit - field.value.length;
}


