﻿function checknum(e){
   if(!e) { e = window.event; } if(!e) { return; }
    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else if( typeof( e.keyCode ) == 'number'  ) {
        e = e.keyCode;
    } else if( typeof( e.charCode ) == 'number'  ) {
        e = e.charCode;
    }
     if((e >= 48&& e<= 57)||(e==8)||(e==0)){
         return true;
     }else{
        return false; 
     }
}

function KeypressEnter(e,buttonid){
    if(!e) { e = window.event; } if(!e) { return; }
    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else if( typeof( e.keyCode ) == 'number'  ) {
        e = e.keyCode;
    } else if( typeof( e.charCode ) == 'number'  ) {
        e = e.charCode;
    }
    var bt = document.getElementById(buttonid);   
    if(bt){ 
       if(e==13){bt.click();return false;}//else{return true;}
    }
}   

function ConfirmToDeleteGroup(obj){
    var xState=obj.checked;
    var foundCheck =0;
    var theBox=obj;	   
      
    var elm = theBox.aspnetForm.elements
 	for(i=0;i<elm.length;i++){	
	    if(elm[i].type=="checkbox" && elm[i].id!=theBox.id){			
		    if(elm[i].checked==true)
		   foundCheck++;			
        }
   }
   if (foundCheck>0){ 
      if(confirm("Are you sure you want to delete this? This will be deleted immediately, and there is no undo facility. Please click OK to delete or Cancel.") == true)
         { return true;  }
      else
         { return false;}
   }else{
         return false;
   }
}	

function createXMLHttpRequest(objXMLHttpRequest){
	if(window.XMLHttpRequest){
		objXMLHttpRequest = new XMLHttpRequest();
	}else if(window.ActiveXObject){ //IE
		objXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		objXMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");		
	}
	return objXMLHttpRequest;
}
function clearChildCombo(childObj){
    for (var ci = childObj.options.length - 1; ci >= 0; ci--) childObj.options[ci] = null;
	 childObj.selectedIndex = -1;
}

function bookmark(){
    var url=window.location.href;
    var title = document.title;
    if (window.sidebar) window.sidebar.addPanel(title, url, "");// firefox
    else if(window.opera && window.print){ // opera
        var mbm = document.getElementById("bookmark")//createElement('a');
            mbm.rel = "sidebar";
            mbm.target = "_search";
            mbm.title = title;
            mbm.href = url;
            mbm.click()
    }else if(document.all)  window.external.AddFavorite(url, title);// ie
    
    else alert('Please press Ctrl+D to bookmark this page');
   

}


function isEmail(string) {

   if (!string) return false;
   var iChars = "*|,\"<:>[]{}`\';()&$#%";

   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
         return false;
   }
   return true;
}   

function SelectOne(rdo,gridName)
{
/* Getting an array of all the "INPUT" controls on the form.*/
all=document.getElementsByTagName("input");
 for(i=0;i<all.length;i++)
 {
  if(all[i].type=="radio")/*Checking if it is a radio button*/
  {
/*I have added '__ctl' ASP.NET adds '__ctl' to all 
    the controls of DataGrid.*/
   var count=all[i].id.indexOf(gridName+'__ctl'); 
   if(count!=-1)
   {
    all[i].checked=false;
   }
  }
 }
 rdo.checked=true;/* Finally making the clicked radio button CHECKED */
}

var xmlHttp
function GetHttp(XX)
{	var XX = null;
	try 
	{  XX = new XMLHttpRequest(); }
	catch (e)
	{  try
		{  XX = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e)
		{  XX = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return XX;
}

function ShowData(DivN,Sta,ypos,Id ,e)
{  
var Obj =  document.getElementById(DivN);
      xmlHttp = GetHttp(xmlHttp)
      if (xmlHttp == null)
      {	alert("not support");
  	    return ;
      }
      var url = "../GetData.ashx?Status="+Sta+"&Id="+Id ;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);  
      
        var Obj =  document.getElementById(DivN);

       Obj.style.display = 'block';
        var posx = 0;
        var posy = 0;
//        if (!e) var e = window.event;
//        if (e.pageX || e.pageY) 	{
//            posx = e.pageX;
//            posy = e.pageY;
//        }
//        else if (e.clientX || e.clientY) 	{
            posx = e.clientX //+ document.body.scrollLeft
//                + document.documentElement.scrollLeft;
//            
            posy = e.clientY //+ document.body.scrollTop
//                + document.documentElement.scrollTop;
//           if (posy + 150 > e.pageX ) { posy = e.pageX - 150}
//        }
          posx -= (ypos +12)
          posy -= 3
          
          Obj.style.left = (posx)+'px' ;
          Obj.style.top = (posy)+'px' ;      
          xmlHttp.onreadystatechange = function(){
          if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
          {    
              Obj.innerHTML = xmlHttp.responseText;
          }
       }
}

function gettrailobj(){
if (document.getElementById)
return document.getElementById("Datas").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
	if (document.getElementById)
		return document.getElementById("Datas")
	else if (document.all)
		return document.all.trailimagid
}



if (document.getElementById || document.all){
	document.write('<div id="trailimageid">');
	document.write('</div>');
}

var offsetfrommouse=[-50,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight =100;	// maximum image size.

function showtrail(imagename,ypos,showthumb,height,width,e)
{
	var imgheight
	var nwidth 
	var imgheight

	if (height > 0){
		
		if(height > 450)
		{
			imgheight=450
			nwidth = width * 450 / height

		}
		else
		{
		    imgheight=height
		    nwidth =  width
		}	
	}
	nwidth=nwidth+20;
	newHTML = '<div style="padding: 5px 5px 5px 5px; width:'+ nwidth +'px; ">';
	if (showthumb > 0)
	{
		newHTML = newHTML + '<div align="center" ><img src="' + imagename + '" height="'+imgheight+'"></div>';
	}
	newHTML = newHTML + '<br></div>';
    var Obj = gettrailobjnostyle()
	Obj.style.display = 'block';
    gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible"
}

function showtrail2(imagename,title,ypos,showthumb,height,width,e)
{
	var imgheight
	var nwidth 
	var imgheight

	if (height > 0)
	{
		
		if(height > 450)
		{
			imgheight=450
			nwidth = width * 450 / height

		}
		else
		{
		    imgheight=height
		    nwidth =  width
		}		
	}
    document.onmousemove=followmouse;
//	nwidth=nwidth+20;
	
	newHTML = '<div style="padding: 0px 0px 0px 0px; width:'+ nwidth +'px; ">';
	newHTML = newHTML + '<span class="Title"><center>' + title + '</center></span><div class="borderbot"></div>';

	if (showthumb > 0){
		newHTML = newHTML + '<div align="center" ><img src="' + imagename + '"></div>';
	}
	newHTML = newHTML + '<br></div>';
    var Obj = gettrailobjnostyle()
	Obj.style.display = 'block';
	Obj.onmousemove=followmouse;
    gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().visibility="visible"
}

function hidetrail(e)
{
	gettrailobj().visibility="hidden"
	//document.getElementById("DdlPrice").visibility = "hidden"
	document.onmousemove=""
//	gettrailobj().left="-500px"
}

function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function followmouse(e){

	var xcoord=offsetfrommouse[1]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)



	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 450){
			xcoord = e.pageX - xcoord - 486 - 60; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}
		

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 450){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 486 - 60; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
    ycoord -= 150
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)

	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

function closeDisplay()
{
    gettrailobj().display = "none";
}

function preview(CId, tableName,height,width,e)
{
    followmouse;
    var newHTML  
    newHTML = '<div style="padding: 0px 0px 0px 0px; width:650px; ">';
    newHTML = newHTML + '<table width="100%" border="0" cellpadding="0" cellspacing="0">'
//    newHTML = newHTML + '<tr><td style="text-align:right; padding-right:5px;"><img src="../Images/close.gif" onclick="closeDisplay()"></td></tr>'
    newHTML = newHTML + '<tr><td style="padding: 10px 10px 10px 10px;" align="center"><img src="../ShowImages.aspx?Id=' + CId + '&Status=' + tableName + '"></td></tr>'
//    newHTML = newHTML + '<br>'
    newHTML = newHTML + '</table>'
//	newHTML = newHTML + '<span class="Title"><center></center></span><div class="borderbot"></div>';
//    newHTML = newHTML + '<div style="text-align:right;" "><img src="../Images/close.gif" onclick="closeDisplay()></div>'
//	newHTML = newHTML + '<div align="center" ><img src="../ShowImages.aspx?Id=' + CId + '&Status=' + tableName + '"></div>';
//	newHTML = newHTML + '<br></div>'
	var Obj = gettrailobjnostyle()
	Obj.style.display = 'block';
    gettrailobjnostyle().innerHTML = newHTML;
}

function preview2(CId,TxtMessageId,height,width,e)
{
//    var imgheight
//	var nwidth 
//	var imgheight

//	if (height > 0)
//	{
//		
//		if(height > 450)
//		{
//			imgheight=450
//			nwidth = width * 450 / height

//		}
//		else
//		{
//		    imgheight=height
//		    nwidth =  width
//		}
//			
//	}
	
    var t = document.getElementById(TxtMessageId);
    var newHTML  
    newHTML = '<div style="padding: 0px 0px 0px 0px; ">';
	newHTML = newHTML + '<span class="Title"><center></center></span><div class="borderbot"></div>';

////	if (showthumb > 0){
	newHTML =  newHTML + '<div align="center" ><img src="../ShowImages.aspx?Id=' + CId + '&Status=ECard&Text=' + convert(t.value) + '"></div>';
//	//}
	newHTML = newHTML + '<br></div>'
	var Obj = gettrailobjnostyle()
	Obj.style.display = 'block';
    gettrailobjnostyle().innerHTML = newHTML;
}


var symbol = new Array();
symbol[0] = "&";
symbol[1] = "\"";
symbol[2] = "<";
symbol[3] = ">";
symbol[4] = "\n";
symbol[5] = "\#";

var toCh = new Array();
toCh[0] = "&amp;";
toCh[1] = "&quot;";
toCh[2] = "&lt;";
toCh[3] = "&gt;";
toCh[4] = "<br\>";
toCh[5] = "<sharp\>";

function convert(_value)
{
    for(var i=_value.length; i!=0; i=i-1)
    {
        for(var j=0; j < symbol.length; j++)
        {
            if(_value.substr(i-1, 1) == symbol[j])
            {
                // replace current character with "_x00" hex_value "_"
                _value = _value.substring(0,i - 1) + toCh[j] + _value.substring(i);
                break;
            }
        }
    }
    return _value;
} // ends convert(String)


function keydownEnter(e){
   if(!e) { e = window.event; } if(!e) { return; }
    if( typeof( e.which ) == 'number' ) {
        e = e.which;
    } else if( typeof( e.keyCode ) == 'number'  ) {
        e = e.keyCode;
    } else if( typeof( e.charCode ) == 'number'  ) {
        e = e.charCode;
    }
      var obj = document.getElementsByTagName("input") ;           
     for(var ic=0;ic<obj.length;ic++){
    
     if(obj[ic].type=='submit'){  
     
       var buttonid = obj[ic].id ;

        var bt = document.getElementById(buttonid);
 
       if(e==13){bt.click();return false;}//else{return true;}
      }
   } 
}

function testRdb(rdb,hideControl,hideNumber,CardId)
{
    var rdbControl = document.getElementById(rdb);
    var hide1 = document.getElementById(hideControl);
    var hideNum = document.getElementById(hideNumber);
    
    if(hide1.text != null)
    {
        var rdbControlTemp2 = document.getElementById(hide1.text);
      //  rdbControlTemp2.checked = true;
    }
    hide1.value = rdb;
    hideNum.value = CardId;
}

function getNum(hideControl,hideNumber,e)
{
    var hideNum = document.getElementById(hideNumber);
    var num = trim(hideNum.value)
    if(num == "")
    {
        alert('Please select e-Card');
        return false;
    }
    else
    {
        return true;
    }
    
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

