var isXHTML=0;
var bustcachevar =1;
var loadstatustext="<center><img height=10 src='images/loading.gif'><center>"
var bustcacheparameter=""
var http_request = false;

	function setCaretToEnd (el) {
		document.getElementById('SerachTxt').focus();
	  if (el.createTextRange) {
	    var v = el.value;
	    var r = el.createTextRange();
	    r.moveStart('character', v.length);
	    r.select();
	  }
	}

	function insertAtEnd (el, txt) {
	document.getElementById(el).value = txt;
	  setCaretToEnd (el);
	}

	function ChangeFocus(Text){
		elementsForms = document.getElementById('dddddd');
		len = elementsForms.length;
			for(i = 0; i<len; i++) {
	  			if ((elementsForms[i].value.indexOf(Text) == 0)) {
					elementsForms[i].focus();
					elementsForms[i].blur();
					break;
			      	}
			   }

	}


	function cheksmsform(FormId){
			elementsForms = document.getElementById('MobileLangForJavascript');
			MoArrayLeen = elementsForms.length;
			var MobileLangArray = new Array(MoArrayLeen) ;
				for (var intCounter = 0; intCounter < MoArrayLeen; intCounter++) {
					MobileLangArray[elementsForms[intCounter].name] = elementsForms[intCounter].value;
				}

		sendsmsform = document.getElementById(FormId);

		if (sendsmsform.gtek.value == 1){
		sendsmsform.Countryn.value = sendsmsform.mobile.value.substring(0,2) ;
		}
		var x1 = sendsmsform.Countryn.value
		var x2 = sendsmsform.OperatorID.value
		var x3 = sendsmsform.mobile.value
		var x4 = sendsmsform.sender.value

		if (sendsmsform.advmsg.value.length > 0){
//		var x5 = sendsmsform.msg.value + '\n' + sendsmsform.advmsg.value
		var x5 = sendsmsform.msg.value;
		} else {
		var x5 = sendsmsform.msg.value;
		}

		if (sendsmsform.gtek.value == 1){
		x1x2 = sendsmsform.mobile.value.substring(0,3) ;
		} else {
		x1x2 = sendsmsform.Countryn.value
		}

		var noc = x1x2.length
		var noc2 = noc + 1

	  	exp1 = /^[0-9]{10,16}$/
	  	exp2 = /^[0-9]{1,16}$/
	  	exp3 = /^[A-Za-z0-9.]{1,11}$/
		if (x1 == 0){
		alert (MobileLangArray['_YOUMUSTCHOSECONTRY']) ;
		sendsmsform.Countryn.style.color ='#FF0000';
		sendsmsform.Countryn.value='0';
		}else if(x2 == 0) {
		alert (MobileLangArray['_YOUMUSTCHOSEOPRATOR']) ;
		}else if ((x3.length < 1)||(x3.substring(0,noc)!= x1x2) ||(x3 == x1x2)){
		alert (MobileLangArray['_YOUMUSTADDMOBILEAFTERCAO']) ;
		sendsmsform.mobile.style.color ='#FF0000';
		sendsmsform.mobile.value= x1x2
		} else if (exp1.test(x3) != true){
		alert (MobileLangArray['_ERRMOBILENUM']) ;
		sendsmsform.mobile.style.color ='FF0000';
		} else if((exp3.test(x4) != true) & (exp2.test(x4) != true)){
		alert (MobileLangArray['_SENDERMUSTBE11']) ;
		sendsmsform.sender.style.color ='#FF0000';
		} else if(x5.length <1 || x5 =='xxxx' ) {
		alert (MobileLangArray['_YOUMUSTENTERTHEMSG']) ;
		sendsmsform.msg.style.color ='FF0000';
		sendsmsform.msg.value ='xxxx';
		} else {
		sendsmsform.msg.value = x5;
		sendsmsform.submit();
		}
	}


	function GetJavaScriptLang(){
			elementsForms = document.getElementById('MobileLangForJavascript');
			MoArrayLeen = elementsForms.length;
			var MobileLangArray = new Array(MoArrayLeen) ;
				for (var intCounter = 0; intCounter < MoArrayLeen; intCounter++) {
					MobileLangArray[elementsForms[intCounter].name] = elementsForms[intCounter].value;
				}
	}

	 function is_arabic(Text){
	  str = "دجحخهعغفقثصضطكمنتالبيسشظزوةىلارؤءئإلإألأآلآ";
	   for (i=0; i<Text.length; i++)
	   if (str.indexOf(Text.charAt(i)) != -1)
	   return 1;
	   return 0;
	 }

	function checkcount(FormId){
		// if (document.sendsmsform.msg.value.length > document.sendsmsform.ml11.value){
		// document.sendsmsform.msg.value = document.sendsmsform.msg.value.substring(0,document.sendsmsform.ml11.value);
		sendsmsform = document.getElementById(FormId);
		var FormText = sendsmsform.msg.value
		if (FormText.length > 0){
			var OldSmsC = sendsmsform.SMSCount.value;
			if (is_arabic(FormText)){
				sendsmsform.ml11.value=(70);
				sendsmsform.msg.dir='rtl' ;
				sendsmsform.advmsg.dir='rtl' ;
				sendsmsform.advmsg.value = sendsmsform.advmsgar.value ;
			} else {
			sendsmsform.ml11.value=(160);
			sendsmsform.msg.dir='ltr';
			sendsmsform.advmsg.dir='ltr' ;
			sendsmsform.advmsg.value = sendsmsform.advmsgen.value ;
			}


		if (sendsmsform.advmsg.value.length > 0){
		var chrcounter = sendsmsform.msg.value.length + sendsmsform.advmsg.value.length + 1
		var chradvcounter = sendsmsform.advmsg.value.length + 1
			} else {
		var chrcounter = sendsmsform.msg.value.length
		var chradvcounter = 0
			}

		MsgCount = Math.ceil((chrcounter) / (sendsmsform.ml11.value));
		sendsmsform.SMSCount.value = MsgCount ;
		var UserTotPointsNow = sendsmsform.UserNumberOfPoints.value;
		var needpoints1sms = sendsmsform.UserNeededPoints.value;
		var needpointsthissms = Math.ceil(needpoints1sms * MsgCount);

        if (needpointsthissms > UserTotPointsNow ){
        alert ('<?php echo _YOUNEEDMOREPOINTES ?>');
        maxsmslenth = Math.ceil((sendsmsform.ml11.value) * (MsgCount - 1)) - chradvcounter;
        sendsmsform.msg.value = sendsmsform.msg.value.substring(0,maxsmslenth);
        checkcount(FormId);
        }
		sendsmsform.Chars.value = sendsmsform.msg.value.length;
		}
	}


 	function ajaxpage(url, containerid){
		var page_request = false
			if (window.XMLHttpRequest) // if Mozilla, Safari etc
			page_request = new XMLHttpRequest()
				else if (window.ActiveXObject){ // if IE
						try {
						page_request = new ActiveXObject("Msxml2.XMLHTTP")
						}

						catch (e){
							try{
							page_request = new ActiveXObject("Microsoft.XMLHTTP")
							}
							catch (e){}
						}
				}
			else
			return false

					if (containerid.indexOf("StatTd")==-1){
						document.getElementById(containerid).innerHTML=loadstatustext
					} else {


						val = document.getElementById(containerid).innerHTML
						 if (z=val.match(/<SCRIPT>([^>]+)<\/SCRIPT>/g)){
								if (z.length) {
									var loopto = z.length;
								} else {
									var loopto = 1;
								}

						 		for(var i=0;i<loopto;i++) {
									val = (val.replace(z[i],""));
			        	   			//eval(z[i].replace(/<([/]{0,1})SCRIPT[^>]*>/g,""));
								}
			     			}

				document.getElementById(containerid).innerHTML= val;


					}

				page_request.onreadystatechange=function(){
				loadpage(page_request, containerid)
				}


			if (bustcachevar) //if bust caching of external page
			bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
			newUrl = url+bustcacheparameter;
			page_request.open('POST', newUrl, true)
	        page_request.setRequestHeader('Content-Type', 'text/html; charset:UTF-8');
			page_request.send(null)
	}

	function loadpage(page_request, containerid){
				if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
					document.getElementById(containerid).innerHTML=page_request.responseText

					val = document.getElementById(containerid).innerHTML
						 if (z=val.match(/<SCRIPT>([^>]+)<\/SCRIPT>/g)){
								if (z.length) {
									var loopto = z.length;
								} else {
									var loopto = 1;
								}

						 		for(var i=0;i<loopto;i++) {
			        	   			eval(z[i].replace(/<([/]{0,1})SCRIPT[^>]*>/g,""));
								}
			     			}


	}




function drawExDiv(element,whichDiv){
     var x = document.getElementById(whichDiv);
     x.style.position='absolute';
     x.style.display = 'block';
     var dime=new Dimension(element);
     var dimdoc=new Dimension(x);

//     alert(x.offsetHeight)
//     alert(x.offsetWidth)
//alert(dimdoc.w);
//alert(dimdoc.h);

     x.style.left = (dime.x>dimdoc.w)? (dime.x-20):dime.x-16;
     x.style.top = (dime.y>dimdoc.h)?dime.y+16:dime.y+16;
     //show the div


}

function hiderEx(whichDiv){
     document.getElementById(whichDiv).style.display = 'none';
}


	function chosename(un){
					var xsn1 = document.all.mobile.value
					var mobilenu = document.all.mobile.value
					xsn3 = xsn1.substring(0,3)
					xsn2 = xsn1.substring(0,2)
					xsn1 = xsn1.substring(0,1)
					document.all.Countryn.value = xsn3 ;
					if (document.all.Countryn.selectedIndex > 0){
					    pn = 1
					    cnts = 3
					} else {
					     document.all.Countryn.value = xsn2 ;
					    if (document.all.Countryn.selectedIndex > 0){
					          pn = 1
					          cnts = 2
					    } else {
					            document.all.Countryn.value = xsn1 ;
					          if (document.all.Countryn.selectedIndex > 0){
					                        pn = 1
					                         cnts = 1
					          } else {
					              pn = 0
					          }

					    }
					}
					csn1 = un;
					csn2 = document.all.mobile.value;

					if ((pn == 0)){
						alert ("'._SMSFTXT002.' \n\n"+ csn1 +"\n\n '._SMSFTXT003.' \n\n"+ csn2 )
						document.all.Countryn.selectedIndex = 0
						document.all.mobile.value = ""
					} else if (document.all.mobile.value == 0) {
						document.all.mobile.value = "" ;
						document.all.Countryn.selectedIndex = 0
					} else {
						document.all.mobile.value = csn2 ;
						if (window.chosecuntry){
						chosecuntry();
						cheknumoprator(mobilenu, cnts)
						}
						document.all.mobile.value = csn2 ;
						cheknumoprator(mobilenu, cnts)
					}
	}

		function cheknumoprator(mobilenu, xsn3){
			var xnet= new Array(4);
			    xnet[0] = mobilenu.substring(xsn3,4+xsn3)
			    xnet[1] = mobilenu.substring(xsn3,3+xsn3)
			    xnet[2] = mobilenu.substring(xsn3,2+xsn3)
			    xnet[3] = mobilenu.substring(xsn3,1+xsn3)
			var xnum =document.getElementById("OperatorID")
			var xnum2 = xnum.length
			for (myi = 0; myi<4; myi++){
			var cntck = xnet[myi]
			for (myi2 = 1; myi2<xnum2; myi2++){
			var ctitl = document.all.OperatorID.options[myi2].title
			if (ctitl == cntck){
			document.all.OperatorID.value = document.all.OperatorID.options[myi2].value
			}}}
		}

	function Dimension(element){
	     this.x=-1;
	     this.y=-1;
	     this.w=0;
	     this.h=0;
	     if (element==document){
	          this.x=element.body.scrollLeft;
	          this.y=element.body.scrollTop;
	          this.w=element.body.clientWidth;
	          this.h=element.body.clientHeight;
	     }else if (element!=null){
	          var e=element;
	          var left=e.offsetLeft;
	          while ((e=e.offsetParent)!=null) {
	               left+=e.offsetLeft;
	          }
	          var e=element;
	          var top=e.offsetTop;
	          while((e=e.offsetParent)!=null) {
	               top+=e.offsetTop;
	          }
	          this.x=left;
	          this.y=top;
	          this.w=element.offsetWidth;
	          this.h=element.offsetHeight;
	     }
	}

	function drawDiv(element,whichDiv){
	     var x = document.getElementById(whichDiv);
	     x.style.position='absolute';
	     x.style.display = 'block';
	     var dime=new Dimension(element);
	     var dimdoc=new Dimension(x);

	//     alert(x.offsetHeight)
	//     alert(x.offsetWidth)

	     x.style.left = (dime.x>dimdoc.w)? (dime.x+ dime.w)-(dimdoc.w):dime.x-16;
	     x.style.top = (dime.y>dimdoc.h)?dime.y-dimdoc.h:dime.y+16;
	     //show the div


	}

	function show_hide(div_id)
	{
		if(document.getElementById(div_id).style.display == 'none')
			document.getElementById(div_id).style.display = '';
		else
	     document.getElementById(div_id).style.display = 'none';
	}
	function show_hide2(div_id)
	{
		if(document.getElementById(div_id).style.display == 'none')
		{
			document.getElementById(div_id).style.display = '';
			document.getElementById("plus"+div_id).src = 'images/-.gif';
		}
		else
		{
			document.getElementById("plus"+div_id).src = 'images/+.gif';
	     	document.getElementById(div_id).style.display = 'none';
		}
	}
	
	function hider(whichDiv){
	     document.getElementById(whichDiv).style.display = 'none';
	}

    function hide_div(whichDiv){
	     document.getElementById(whichDiv).style.display = 'none';
	}
    function show_div(whichDiv){
	     document.getElementById(whichDiv).style.display = '';
	}


	function viewcardnumber(){
	document.all.cardngray.src='modules/Mobile/cards/gray.gif';
	document.all.viewcardnum.disabled = true ;
	document.all.cardb2.disabled = false ;
	document.all.cardb3.disabled = false ;
	}

	function printCard(taName) {
	document.all.cardngray.src='modules/Mobile/images/pixel.gif';
	var printScript = frames['printit'];
	printScript.document.open();
	printScript.document.write('<html dir=rtl><head></head><body>');
	printScript.document.write(taName.innerHTML);
	printScript.document.write('</body></html>');
	printScript.document.close();
	printScript.focus();
	printScript.print();
	}




	function saveImageAs(cardnumber, cardpic) {
	var sdfsdf = "modules.php?name=Mobile&file=cards&func=makecard2&card_num="+cardnumber+"&cardpic="+cardpic+"" ;
	window.location = sdfsdf;
	}

	function viewselpic(){
	var xx = document.addnewc.site_image.value
	document.all.viepictd.innerHTML = "<img src=images/clintwebpic/"+xx+">"
	}


 function get(id) {
	elementsForms = document.getElementById(id);
	if (id =='bulk_add_mobiles_confirm_form'){
				if (elementsForms.PostAction.value.indexOf('bulk_mobiles_add') !=-1){
						if (CheckAddConfirm(id)){
						} else {
							return;
						}
				}
	}
		window.scrollTo(0, 0);

		if (id =='EditSerchSmsUsers' || id.indexOf('EditMsgsForm') == 0 || id.indexOf('EditMobilesForm') == 0 || id.indexOf('GroupsMangForm') == 0){
		} else {
		centerDiv.rePos
		opacity('centerDiv', 0, 90, 1000);
  		}



 		var poststr ='';
        	for (var intCounter = 0; intCounter < elementsForms.length; intCounter++) {


				if (elementsForms[intCounter].type =='submit'){
				} else if (elementsForms[intCounter].name =='PostAction'){
				} else if (elementsForms[intCounter].type =='radio' && elementsForms[intCounter].checked==0){
				} else if (elementsForms[intCounter].type =='checkbox' && elementsForms[intCounter].checked==0){
				} else if (elementsForms[intCounter].type =='button'){
				} else {
			      poststr = poststr + elementsForms[intCounter].name + '=' + elementsForms[intCounter].value + '&'
				}
			}

		poststr =  poststr + '&ajaxmode=1';
		PostAction = elementsForms.PostAction.value

	if (id =='EditSerchSmsUsers' || id.indexOf('EditMsgsForm') == 0 || id.indexOf('EditMobilesForm') == 0 || id.indexOf('GroupsMangForm') == 0){
		url = PostAction + '?' + poststr;
		ShowIndiv = elementsForms.ShowIndiv.value
		ajaxpage(url, ShowIndiv)
		} else {
    	 makePOSTRequest(PostAction, poststr);
  		}



    }

	function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }

      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

	document.getElementById('centerDiv').innerHTML = loadstatustext
    http_request.onreadystatechange = alertContents;
    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('centerDiv').innerHTML = result;
			var z = result.match(/<SCRIPT[^>]*>([^<]+)<\/SCRIPT>/g);
       		opacity('centerDiv', 90, 0, 3000);
         } else {
     	document.getElementById('centerDiv').innerHTML = 'There was a problem with the request.'
  		opacity('centerDiv', 90, 0, 3000);
         }
      }


	 if (z && (typeof(z)=='array' || typeof(z)=='object' )){
			 for(var i=0;i<z.length;i++) {
			eval(z[i].replace(/<([/]{0,1})SCRIPT[^>]*>/g,""));

				}
      }

   }







w=250   // width of the div
h=100   // height of the div
function rePos() {
	// compute center coordinate
	if(NN4||NN6) {
		xc=Math.round((window.innerWidth/2)-(w/2))
		yc=Math.round((window.innerHeight/2)-(h/2))
	} else {
		xc=Math.round((document.body.clientWidth/2)-(w/2))
		yc=Math.round((document.body.clientHeight/2)-(h/2))
	}
	// reposition div
	if(this.NN4) {
		myObj.moveTo(xc,yc)
	} else {
		myObj.left = xc + "px"
		myObj.top = yc + "px"
	}
}


function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}


	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

	//change the opacity for different browsers
	function changeOpac(opacity, id) {
		if (opacity == 0) {
		document.getElementById(id).style.visibility  = 'hidden';
		} else {
		document.getElementById(id).style.visibility  = 'visible';
		}
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}


