/**
	* @author			:	Swapnil Bedekar <swapnil@nyasasoftec.com>
	* @version			:	1.0
	* @access				:	private to nyasasoftec pvt. ltd.
	* @copyright		:	Copyright (c) 2007 nyasasoftec pvt. ltd.
									http://www.nyasasoftec.com
	* @File Name		:	global.js. This page used to store Global javascript function.
*/

//var ImagePath='http://apache/javed/tristatedrugs/images/'  // For Local
var ImagePath='https://www.tristatedrugs.com/images/' //  For Online

function makeRequest(url, successfunc, uiElement, method, params) {
	// this is a extra code added by the dhananjay
	
	if(method='POST')
	   method='post';
		 
	if(typeof(method) == "undefined")
		method = "get";
	
	if(typeof(params) == "undefined")
		params = null;

	if (typeof(params) == "undefined") {
		params="isajax=yes";
	}
	else {
		params=params + "&isajax=yes";
	}

	var http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		http_request = new XMLHttpRequest();

		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	}
	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('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	// DM
	error_obj = getObject(uiElement);
	if(error_obj!=null)
	{
	error_obj.innerHTML="<div style='background-color:#FFFFFF;' width='150px'><center><br /><br /><span class='RedText14'>Please Wait ...........</span><br /><br /><img src='" + ImagePath + "processing.gif' border='0' /><br /><br /></center></div>";
                     }
	http_request.onreadystatechange = function() { FillResponse(http_request, successfunc, uiElement, url); };
	http_request.open(method, url, true);

	if(method == "post") {
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", params == null? 0: params.length);
		http_request.setRequestHeader("Connection", "close");
	}

	http_request.send(params);
}

function FillResponse(http_request, successfunc, uiElement, url) { 

	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if(successfunc == null || successfunc == "")
				successfunc = "NormalFillResponse";

			// evaluate the success function
			eval(successfunc +'(http_request,\''+uiElement+'\');');
		}
		else {
			// set error handler
			if(getObject(uiElement) != null) {
				getObject(uiElement).innerHTML="<br /><br /><div align='center' class='botHeadderRed'>" + ErrorHandling(http_request.status) + "</div>";
			}

			if(http_request.status == 408)
				makeRequest(url, successfunc, uiElement);// if request time out then re call same url
		}
	}
}

// function to set the error messages for different http errors
// error messages are self explaining
function ErrorHandling(temp_error_code) {
	switch(temp_error_code) {
		case 400 : temp_error_code="Bad Request"; break;
		case 401 : temp_error_code="Unauthorized Request made"; break;
		case 403 : temp_error_code="Forbidden: You don't have permission to access"; break;
		case 404 : temp_error_code="Requested Page Not Found"; break;
		case 405 : temp_error_code="The method specified in the Request-Line is not allowed"; break;
		case 500 : temp_error_code="Unable to send response due to Internal Server Error."; break;
		default :  temp_error_code="Trying to reach the Server. " + temp_error_code; break;
	}
	return temp_error_code;
}

function getObject(name) {
	var ns4 = (document.layers) ? true : false;
	var w3c = (document.getElementById) ? true : false;
	var ie4 = (document.all) ? true : false;

	if (ns4) return eval('document.' + name);
	if (w3c) return document.getElementById(name);
	if (ie4) return eval('document.all.' + name);

	return false;
}

function GetInteger(s){ 
	var i;
	for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

//Check email Validation//
function checkEmail(vai) {
	var remail=/^([_&a-zA-Z0-9-]+(\.[_&a-zA-Z0-9-]+)*@[&a-zA-Z0-9-]+\.+[&a-zA-Z0-9-]+)/;
	if(remail.test(vai))
		return false;
	else
		return true;
}

function open_this (url) {
	window.open(url,'','width=620, height=450, top=100, left=200, scrollbars=1, statusbar=0, toolbars=0, resizable=no');
}

/*  This function is used to Increase or Decrease Font Size in site - Start */
var zxcBlankImg='images/Space.gif';
var zxcOOPCnt=0;

function zxcZoomText(zxcobj,zxcssz,zxcfsz,zxcspd) {
	if (typeof(zxcobj)=='string') { zxcobj=document.getElementById(obj); }
	if (!zxcobj.oopct) {
		zxcspd=zxcspd||100;
		if (zxcBlankImg){ zxcobj.style.backgroundImage='url('+zxcBlankImg+')'; }
		zxcobj.oopct=new zxcOOPTxtZoom(zxcobj,zxcssz,zxcfsz,zxcspd);
	}
	clearTimeout(zxcobj.oopct.to);
	zxcobj.oopct.minmax[4]*=-1;
	zxcobj.oopct.cngtxt();
}

function zxcOOPTxtZoom(zxcobj,zxcssz,zxcfsz,zxcspd){
	this.obj=zxcobj;
	if (zxcobj.style.position) {
		if (zxcobj.style.position='absolute') {
			this.abs=[zxcobj.offsetLeft,zxcobj.offsetWidth];
		}
	}
	this.ref='zxcoopct'+zxcOOPCnt++;
	window[this.ref]=this;
	this.minmax=[zxcssz,Math.min(zxcssz,zxcfsz),Math.max(zxcssz,zxcfsz),zxcspd,(zxcssz<zxcfsz)?-1:1];
	this.to=null;
}

zxcOOPTxtZoom.prototype.cngtxt=function() {
	if ((this.minmax[4]>0&&this.minmax[0]<this.minmax[2])||(this.minmax[4]<0&&this.minmax[0]>this.minmax[1])) {
		this.obj.style.fontSize=(this.minmax[0]+=this.minmax[4])+'px';
		if (this.abs) {
			this.obj.parentNode.style.width=(this.obj.offsetWidth+parseInt(this.obj.style.fontSize))+'px';
			this.obj.parentNode.style.left=(parseInt(this.obj.style.fontSize)/2)+'px';
		}
		this.to=this.setTimeOut('cngtxt();',this.minmax[3]);
	}
}

zxcOOPTxtZoom.prototype.setTimeOut=function(zxcf,zxcd) {
	this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}
/*  This function is used to Increase or Decrease Font Size in site - End */

function chkformat(temp1) {
	var temp2;
	l_i=temp1.length;
	f_i=temp1.lastIndexOf('.');
	temp2=temp1.substring(f_i+1,l_i);
	return temp2;
}
 
function isDigit(num) {
	if(num.length>1) {
		return false;
	}
	var string="1234567890";
	if(string.indexOf(num)!=-1) {
		return true;
	}
	return false;
}   

function isInteger(val) {
	if(""==val)
	return 0;
	else { 
		for(var i=0;i<val.length;i++) {
			if(!isDigit(val.charAt(i)))
				return 0;
		}
		return 1;
	}
}

function GetURLParams() {
	var is_input = document.URL.indexOf('?');

	if (is_input != -1)
		url = document.URL.substring(is_input+1, document.URL.length);
	else
		url="";

	return url;
}

/*------------------------------------------------------------
	Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
	Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
	Web Site: http://txkang.com
	Script featured on Dynamic Drive (http://www.dynamicdrive.com)
	
	Please retain this copyright notice in the script.
	License is granted to user to reuse this code on 
	their own website if, and only if, 
	this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr','a');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
//	sz += inc;
    sz = inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

function MakeEmpty(uiElement) {
	getObject(uiElement).className="";
	getObject(uiElement).innerHTML="";
}

function user_pre(userid) {
	window.open("viewmedical.php?UserID="+userid,"","resizable=no,scrollbars=yes,width=600,height=800,left=200,top=100,screenX=0,screenY=100"); 
}

function ShowPrescription(OrderID){	
window.open("showprescription.php?id="+OrderID,"","resizable=no,scrollbars=yes,width=600,height=800,left=200,top=100,screenX=0,screenY=100"); 
}
function showmisspelledform(id)
{
	document.getElementById(id).style.display='';
}


// This function is used in whole application to make ajax calls
function myRequest(url, successfunc, uiElement, method, params){
	document.getElementById(uiElement).innerHTML='<img src="../images/dots-white.gif">';
 	if(typeof(method) == "undefined")method = "GET";
 	if(typeof(params) == "undefined")params = null;
	var http_request = false;
	if (window.XMLHttpRequest){
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType){
			http_request.overrideMimeType('text/xml');
		}
	}else if(window.ActiveXObject){
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
				try{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e){}
            }
        }
		if (!http_request){
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange=function(){try{
			if (http_request.readyState == 4){
				if(http_request.status == 200){if(successfunc!=null)successfunc(http_request,uiElement);}
			else if(http_request.status==401){
				//if(successfunc!=null)successfunc(http_request,document.getElementById(uiElement),'athn');
			}else{					
				    if(document.getElementById(uiElement)!=null){
						document.getElementById(uiElement).style.display="block";
                  		document.getElementById(uiElement).innerHTML="&nbsp;"+error_handling(http_request.status)+"&nbsp;";}
                  	if(http_request.status==408){
                  		myRequest(url, successfunc, uiElement);
                  	}
                 }
		}
}catch(uiu){} 
			
			};
        http_request.open(method,url, true);
        if(method == "POST")
        {
        	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        	http_request.setRequestHeader("Content-length", params == null? 0: params.length);
      		http_request.setRequestHeader("Connection", "close");
        }
        http_request.send(params);
   }
    function error_handling(temp_error_code)
	{
		switch(temp_error_code)
		 {
			case 400 : temp_error_code="Bad Request"; break;
			case 401 : temp_error_code="Unauthorized"; break;
			case 404 : temp_error_code="Page Not Found"; break;
			default :  temp_error_code="Trying to reach server"; break;
		 }
       return temp_error_code;
	}

// function to handle the addition of new feed
function empty_msg_box(err_element)
{
		document.getElementById(err_element).innerHTML='';
}

function EcheckRefundStatus(echeck_transid)
{
	window.open(echeck_transid,"More",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=120,left = 262,top = 134');
}
