var objImgSrc="";

function EnsureNumeric( event )
{	
	if (event.keyCode>=48 && event.keyCode<=57)
	{
	}
	else
	{
		event.keyCode=null;
	}
}
function EnsureCharacter( event )
{	
	if (event.keyCode>=65 && event.keyCode<=90 || event.keyCode>=97 && event.keyCode<=122)
	{
	}
	else
	{
		event.keyCode=null;
	}
}

function OpenNewActivity(A,D,HH,MM,TM)
{
	if(!A) A='-1';
	if(!D) D='';
	if(!HH) HH='12';
	if(!MM) MM='00';
	if(!TM) TM='AM';
	window.open("Popup.aspx?pageId=233&A="+A+"&D="+D+"&HH="+HH+"&MM="+MM+"&TM="+TM,"Activity","status=0,menubar=no,scrollbars=1,width=700,height=525,left=150,top=150");
}
function refresh()
{
	__doPostBack('','');
}
function DisplayStage(objStage,objImage, objHdn)
{
	if (objHdn.value=='Close')
	{
		objImage.src='images/down.gif';
		objHdn.value='Open';
		objStage.style.visibility='hidden';
		objStage.style.display='none';
	}
	else
	{
		objImage.src='images/up.gif';
		objHdn.value='Close';
		objStage.style.visibility='visible';
		objStage.style.display='block';
		objStage.style.width='100%';
	}
}
function OnImage( objIm , objS , Height , Width )
{
	objImgSrc=objS.src;
	objS.src=objIm.src;	
	
	if( Height > 150 )
	{objS.height = (objIm.height * 2) ;}
	else
	{objS.height = Height ;}
	
	if( Width > 150 )
	{objS.width = (objIm.width * 2) ;}
	else
	{objS.width = Width ;}	
}	
function bookmarkme(sitetitle, url){
if (document.all)
window.external.AddFavorite(url, sitetitle);
else if (window.sidebar)
window.sidebar.addPanel(sitetitle, url, "")
}
function ConfirmDelete()
{
    var lRetVal = confirm('Are You Sure To Delete?');
    alert( lRetVal + '1' );
	return 	lRetVal;
}
var vImages;
var vCount=0;
function previous_image()
{
	if (vCount<vImages.length)
    {
		vCount++;
       //if last image is reached,display the first image
       if (vCount==vImages.length) 
			vCount=0;
		fcnEffects();
		//set the SRC attribute to let the browser load the preloaded images 
       document.images.imgImage.src=vImages[vCount];
       
    }
}
//function to get the next image in the array
function next_image()
{ 
	//code to execute only when the automatic slideshow is disabled   
	if (vCount<vImages.length)
	{
		vCount++
		//if last image is reached,display the first image
		if (vCount==vImages.length) 
			vCount=0
		fcnEffects();
		//set the SRC attribute to let the browser load the preloaded images 
		document.images.imgImage.src=vImages[vCount];
	}   
}
function fcnInit(strImageName,strCounter)
{
	eval("vImages= new Array("+ strImageName + " )");
	vCount=strCounter;
	document.images.imgImage.src=vImages[vCount];
}
function fcnEffects()
{
	document.images.imgImage.filters.revealTrans.Transition=23;
	document.images.imgImage.filters.revealTrans.apply();
	document.images.imgImage.filters.revealTrans.play();
}
function slideshow_automatic()
{ 	
	if (document.slideshow.checked)
	{
	
		if (vCount<vImages.length)
		{
       vCount++;
       //if last image is reached,display the first image
       if (vCount==vImages.length) 
       vCount=0;
       fcnEffects();
       //sets the timer value to 4 seconds,we can create a timing loop by using the setTimeout method
       timeDelay=setTimeout("slideshow_automatic()",4000) ;
       document.images.slideShow.src=image[vCount];
     }
   }  
   if (document.slideshow.checked==false)
   { 
     //Cancels the time-out that was set with the setTimeout method. 
      clearTimeout(timeDelay)
   }
}


	/********************** search engine *****************************/
	/*
	// Develop By : Harshad Modi
	// Date : 09-Dec-2006
	*/
	
    var contacttype=-1;	
    
    
    function openSearch(catid,query,displayfield,searchTitle,searchResultText,searchResultValue)
    {
		if (contacttype==-1)
		{
			alert('can not select contact type');
			return;
		}
		//alert("<script language=javascript>setQuery('" + query + "');setCatId('" +catid+ "');w.setTitle('" +searchTitle+ "');w.setResultId('" +searchResultText+ "','"+ searchResultValue+ "');<//script>");	
		w=window.open("search/frmSearch.aspx?query=" + query + "&displayfield="+displayfield+"&catid=" +catid+ "&searchTitle=" +searchTitle+ "&searchResultTextId=" +searchResultText+ "&searchResultValueId="+ searchResultValue,"","status=0,menubar=no,scrollbars=1,width=420,height=400,left=300,top=200");
		
		
		//w.document.write("<script language='javascript'>setQuery('" + query + "');setCatId('" +catid+ "');w.setTitle('" +searchTitle+ "');w.setResultId('" +searchResultText+ "','"+ searchResultValue+ "');<//script>");
		
    }
    function setSearchResult(textid,valueid,text,value)
    {
		
		var txt=document.getElementById(textid);
		txt.value=text;
		var hdn=document.getElementById(valueid);
		hdn.value=value;
		var refresh=hdn.getAttribute("refresh");
		if(refresh)
		{
			if(eval(refresh))
			__doPostBack('"+hdn.id+"','');
		}

    }
    
    function setContentTypeId(id)
	{
		var lst=document.getElementById(id);
		var op=lst.options[lst.selectedIndex];
		searchTitle="Search for " + op.text;
		contacttype=op.value;
		
	}
	
    function CatId()
    {
		
		return catid;
		
    }
    function SearchTitle()
    {
		return searchTitle;
		
    }
    
    /********************** end search engine *****************************/

function CheckMessages(lblMsg)
{
	var objlblMessage = document.getElementById(lblMsg);
	if (objlblMessage)
	{
		if (trimAll(objlblMessage.innerHTML) != '')
		{
		    objlblMessage.innerHTML = "<div id='divError' class=\"ErrorMessage\">" + "<div style='width:97%;'><img src='images/error_16x16.jpg' align='absmiddle'/>&nbsp;&nbsp;" + objlblMessage.innerHTML + "</div><div style='float: right; width: 10px;margin-top:-21px;margin-right:2px;cursor:pointer;'><img src='images/Cancel.ico' align='absmiddle' onclick='ClearMessage();' /></div></div><div class='ShowError'><div>";
		    opacity('divError', 0, 1000, 1000);
		}
	}
}

function leftTrim(sString)
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

function rightTrim(sString)
{
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
return sString;
}

/*The allTrim() JavaScript function combines both leftTrim() and rightTrim() functions:*/

function trimAll(sString)
{
    /*while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }*/
    return rightTrim(leftTrim(sString));
}

/// VisibleControl
function VisibleControl(ctl)
{
  var objCtl = document.getElementById(ctl);

  if ( objCtl )
  { 
    objCtl.style.visibility = 'Visible';
    objCtl.style.display = 'block';

  }
}
/// END


/// Hide Control
function HideControl(ctl)
{

  var objCtl = document.getElementById(ctl);

  if ( objCtl )
  {
    objCtl.style.visibility = 'hidden';
    objCtl.style.display = 'none';
  }
}
/// END


/// Enable Control
function EnableControl(ctl)
{
  var objCtl = document.getElementById(ctl);
  if ( objCtl )
  {
    objCtl.removeAttribute( "disabled" , "" );
  }
}
/// END


/// Disabled Control
function DisabledControl(ctl)
{
  var objCtl = document.getElementById(ctl);
  if ( objCtl )
  {
    objCtl.setAttribute( "disabled" , "disabled" );
  }
}
/// END
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++;
		}
	}
}

function changeOpac(opacity, id) {
	var objectID = document.getElementById(id); 
	if ( objectID == null )
	{
	    return;
	}
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function GlowImage(image, lglow,DivPopup,CurretImagePath,ReplaceImagePath)
{
    var objDiv = document.getElementById(DivPopup);
    
    if(lglow=="True")
    {
      //  opacity(DivPopup, 0, 200, 1000);
        objDiv.style.visibility='visible';
        objDiv.style.display='block';
        objDiv.style.left= ( image.x - 10  ) + 'px';
        objDiv.style.top= image.y + 'px';
        objDiv.innerHTML="<img src='+image.src.replace(CurretImagePath,ReplaceImagePath)+'/>";
    }
    else
    { 
        objDiv.style.visibility='hidden';
        objDiv.style.display='none';    
        objDiv.innerHTML="";
    }
}


function DeleteConfirm()
{
    return confirm('Are you sure to want delete this record?');
}

function ClearMessage( lblMsg )
{
    var divErrorControl = document.getElementById(lblMsg);
    if ( divErrorControl != null )
    {
        divErrorControl.innerHTML = "";
    }
}

function FloatDiv(id, sx, sy,document)
{
    
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    var nLeftSide = 160;
    if ( screen.width == "1024" && screen.height == "768")
    {
        var nLeftSide = 30;
    }
    
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;

		if ( this.cy <= 380 )
		{
		    this.cy = 380
		}

		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);

	}
	return el;
}


function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
	
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}


function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
    		// Try ActiveX
		try { 
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) { 
			// first method failed 
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				 // both methods failed 
			} 
		}
 	}
   	return xmlreq;
} 


function AjaxJSServer( cQryString, cReturnType )
{
	var req = newXMLHttpRequest();
	
    req.open("POST", cQryString , false);
	
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	
	req.setRequestHeader("content-length", "0");req.send('');
	
	if (req.readyState == 4) 
	{
		if (req.status == 200) 
		{
		    if ( cReturnType == "X" ) // XML
		    {
		        return req.responseXML;
		    }
		    else		            // Text
		    {
		        return req.responseText;
		    }
		} 
		else 
		{
		    document.write("ERROR: "+ req.status)
	    }
	}
}

function AjaxJSServerXML( cQryString )
{
    return AjaxJSServer( cQryString, "X" )
}

function AjaxJSServerText( cQryString )
{
	return AjaxJSServer( cQryString, "T" )
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}

function ClearMessage( lblMsg )
{
    var divErrorControl = document.getElementById(lblMsg);
    if ( divErrorControl != null )
    {
        divErrorControl.innerHTML = "";
    }
}
function RedirectPath(cRedirectPath)
{
    window.location.href=cRedirectPath;
}

function NewWindow(mypage,myname,w,h,pos,infocus)
 {
    // when use this function define var win=null on Master page or when use that function
    if(pos=="random")
    {
        myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
        mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;               
    }
    if(pos=="center")
    {
        myleft=(screen.width)?(screen.width-w)/2:100;
        mytop=(screen.height)?(screen.height-h)/2:100;
    }
    else if((pos!='center' && pos!="random") || pos==null)
    {
        myleft=0;
        mytop=20
    }
    settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
    win=window.open(mypage,myname,settings);
    win.focus();
}

function NewWindowWithScroll(mypage,myname,w,h,pos,infocus)
 {
    // when use this function define var win=null on Master page or when use that function
    if(pos=="random")
    {
        myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
        mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;               
    }
    if(pos=="center")
    {
        myleft=(screen.width)?(screen.width-w)/2:100;
        mytop=(screen.height)?(screen.height-h)/2:100;
    }
    else if((pos!='center' && pos!="random") || pos==null)
    {
        myleft=0;
        mytop=20
    }
    settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
    win=window.open(mypage,myname,settings);
    win.focus();
}
function FixDiv(id, sx, sy,document)
{
    
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    var nLeftSide = 160;
    if ( screen.width == "1024" && screen.height == "768")
    {
        var nLeftSide = 30;
    }
    
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y)
	{
	    //this.style.left=x+px;
	    //this.setAtribute("position" , "absolute");
	    //this.setAtribute("overflow" , "visible");
	    this.style.top=y+px;
    };

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		
		
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		//this.cx += (pX + this.sx - this.cx)/8;
		this.cy += (pY + this.sy - this.cy)/8;

		if ( this.cy <= 200 )
		{
		    this.cy = 200
		}

		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);

	}
	return el;
	return;
}

function findPosX(obj)
{

  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
     
    }
   }
  else if (obj.x)
    curleft += obj.x;
        return curleft;
}

function findPosY(obj)
{

  var curtop = 0;
  if (obj.offsetParent)
  {
    curtop += obj.offsetHeight;
    while (obj.offsetParent)
    {
      curtop += obj.offsetTop;
      obj = obj.offsetParent;
     }
   }
   else if (obj.y)
   {
     curtop += obj.y;
     curtop += obj.height;
   }
   return curtop;
}

function getGooglePath()
{	
    var objZip = document.getElementById('tbZipCode');
    var objVar = document.getElementById('divZipCode');
    var objDesAdd = objVar.getAttribute("value");
    window.open("http://maps.google.com/maps?f=d&hl=en&saddr=" + objZip.value + "&daddr=" + objDesAdd + "");
}
