﻿ 
   window.init = ScrollIt;
   window.onscroll = setcoords;
   window.onkeypress = setcoords;
   window.onclick = setcoords;
 
 
 
 function HandleOnClose(id)
 {
    if(navigator.appName == 'Netscape')
	    {	
		    if (e.PageY < 0 && e.PageX < 0) 
			    {
			       
			        deleteCookie(id);
			    }
	    }
	    else
	    {
    	
	    //alert(event.clientY);
    	
		    if (event.clientY < 0 && event.clientX < 0) 
			    {
			        
			        deleteCookie(id); 
			    }
    			
	    }
	    
    } 
 
function deleteCookie(name)
{
    if (getCookie(name))
    {        
         
        document.cookie = name + "=" 
        window.location.reload( true );
        //showcss()  
    }
}
function ChangeColorAjax(id,flag)
{  
     
    if(flag==2)
    {
     if(document.getElementById('hidId').value==id)
        return;
          if(document.getElementById('spn' +id))
              document.getElementById('spn' +id).style.color='#ffffff';
    }
    else if(flag==3)
    {    
       if(document.getElementById('hidId').value==id)
         return;
        if(document.getElementById('spn' +id))
        document.getElementById('spn' +id).style.color='#99CC33';
    }
}

function ChangeColor(id,flag)
     {     
        
        if(flag==2)
        {
            document.getElementById(id).style.color='#ffffff';
        }
        if(flag==3)
        {
            document.getElementById(id).style.color='#99CC33';
        }
     }
function checkStyle(id)
	{
	
	
	    if( document.getElementById('spn' + document.getElementById('hidId').value))
	    {
	     document.getElementById('spn' + document.getElementById('hidId').value).style.color="#99CC33";	     
	     
	    }
	    document.getElementById('hidId').value=id;
	    if( document.getElementById('spn' + id))
	    {
	     document.getElementById('spn' + id).style.color="#ffffff";	
	    }
	}
function getCookie1(name)
{
    
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
    
}
function ScrollIt()
{   
getScroll();
//    var PageY;   
//    PageY=getcookie('Scroll');    
//    window.scrollTo(0, PageY);
    
}

function getScroll()
          {
       
          var xmlHttp =null;
           var url="checkcookie.aspx";
              
              // url=url+"?cid="+cid + "&current=" + document.getElementById("hidReset").value + "&region=" + region;               
               url=url+"?Rid="+Math.random();
              
          if(navigator.appName == "Microsoft Internet Explorer") 
          {
         
              xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
              // xmlHttp.open("GET",url,false);     
          }
           else
            {
             xmlHttp = new XMLHttpRequest();
           
            }
            
              xmlHttp.open("GET",url,true); 
               
     
   xmlHttp.onreadystatechange=function()
      {     
      if(xmlHttp.readyState==4)
        {
        
        if(xmlHttp.status==200)
        {   
       
            var xmlDoc=xmlHttp.responseXML;                     
            xmlDoc.async="true"; 
          // xmlDoc.loadXML(xmlHttp.responseText);
            var root = xmlDoc.getElementsByTagName('root'); 
           var PageY;   
           PageY=root[0].getElementsByTagName('scroll')[0].childNodes[0].nodeValue;     
           window.scrollTo(0, PageY);
           
        }
      }
      }
  
    xmlHttp.send(null);
  
  }



function ScrollIt1()
{
    var PageY=0;
   
    //PageY=getcookie('Scroll');
   // alert(PageY);
    window.scrollTo(0, PageY);
    
}
function setcoords()
{

   var myPageX;
    var myPageY;
     if (document.all)
      {
         if (!document.documentElement.scrollLeft)
            myPageX = document.body.scrollLeft;
         else
            myPageX = document.documentElement.scrollLeft;
               
         if (!document.documentElement.scrollTop)
            myPageY = document.body.scrollTop;
         else
            myPageY = document.documentElement.scrollTop;
      }   
      else
      {
         myPageX = window.pageXOffset;
         myPageY = window.pageYOffset;
      }    

//    document.getElementById('PageX').value = myPageX;
//    document.getElementById('PageY').value = myPageY;
    
    //--Create Cookies
    //putcookie('Scroll',myPageY,'1') 
    var img="checkcookie.aspx?cookie=" + myPageY;
    if( document.getElementById('imgCookie'))
  document.getElementById('imgCookie').src=img;  
  
    }
 
 function putcookie(c_name,value,expiredays) 
 {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate);
    
    
     document.cookie = "testcook=qq" + ((expiredays==null) ? "" : ";expires="+exdate+";");
  // alert(document.cookie.length);
     
 }
 function getcookie(c_name) {
 //alert(document.cookie.length);
 
    if(document.cookie.length > 0) {
        var c_start = document.cookie.indexOf(c_name + "=");
        if(c_start != -1) {
            c_start = c_start + c_name.length + 1;
            var c_end = document.cookie.indexOf(";",c_start);
            if(c_end == -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return null;
}
function SetnHide(div1)
{

document.getElementById(div1).style.top='0';
document.getElementById(div1).style.left='0';


document.getElementById(div1).style.display='none';
}
function test()
{
var x;
x=25;
}



 function checkMaxLimit(clt,maxLen)
 {
  var len=document.getElementById(clt).value.length;
  var str=document.getElementById(clt).value;
  if(len>=maxLen)
  {
  document.getElementById(clt).value= str.substring(0,maxLen);
  return false;
  }
  else
  {
  return true;
  }
  
 }
function chk(a,b,c)
{
var a=document.getElementById(a);
var b=document.getElementById(b);
var c=document.getElementById(c);
a.className ="contenttype-selected";
b.className ="tabDSelected";
c.className ="tabDSelected";
tabLower('spnL1','spnL3','spnL2');
}
function tabLower(a,b,c)
{
var a=document.getElementById(a);
var b=document.getElementById(b);
var c=document.getElementById(c);
if(a.id=='spnL3')
{
a.className ="contenttype-selectedLast"; //selected for tab 3
b.className ="tabDSelected";
}
else
{
a.className ="contenttype-selected";
b.className ="contenttype-DefaultLast";  //default
}
c.className ="tabDSelected";
}
function showFloatDiv(name)
{    
	if (!e)
       {
        var e=window.event || arguments.callee.caller.arguments[0];            	 
       }

      var	scrolledV=scrollV() ;
   
       var	scrolledH = (navigator.appName == 'Netscape') ? document.body.scrollLeft : document.body.scrollLeft;
      tempX = (navigator.appName == 'Netscape') ? e.clientX : event.clientX;
      tempY = (navigator.appName == 'Netscape') ? e.clientY : event.clientY;
	
 
	document.getElementById(name).style.left=(tempX-220)+'px';
			document.getElementById(name).style.top=(tempY+scrolledV)+'px';
      document.getElementById(name).style.display="";
      

	}
	function scrollV()
{
var scrolledV;
if (window.pageYOffset)
{
	   	scrolledV  = window.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
{
	 	scrolledV  = document.documentElement.scrollTop;
}
else if (document.body)
{
	   	scrolledV  = document.body.scrollTop;
}
return scrolledV;
}
/*var newwindow = '';

function popitup(url) {

	if (!newwindow.closed && newwindow.location) {
	
		newwindow.location.href = url;
	}
	else {
	
		newwindow=window.open(url);
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}
*/
 function countChar(ctlTest,len,ctlResult)
    {  
    var length=document.getElementById(ctlTest).value.length;   
    if(length==0)  
    {
     document.getElementById(ctlResult).innerHTML=len + " chrs left";
    }
    else
    {
    document.getElementById(ctlResult).innerHTML=(len-length) + " chrs left";
    }    
    }
function ImageRefresh(w)
  { 
  document.getElementById('imgTuring').src=w + "?" +Math.random() +"=3" ;
  }

function setimage(id)
{
 window.open('gemStoneImages.aspx?gemid=' + id,'newwindow','width=500px,height=470px;');
}


function HideDiv(id)
{
   
    if(document.getElementById(id))
  document.getElementById(id).style.display="none" ;
  
    if(document.getElementById('dvSecond'))
  document.getElementById('dvSecond').style.display="" ;
}
function ClientValidate(source, arguments)
       {
        
          if( document.getElementById("ctl00_ContentPlaceHolder1_lstbxdealin").value=="1")
          {
          var trimvalue=trim(arguments.Value);
          if(trimvalue.length==0)
          {
          arguments.IsValid = false;
          }
          else
             arguments.IsValid = true; 
          }
          else
            arguments.IsValid = true;
         
            
       }


function openIndex(id)
{

  
     window.open("index.aspx?content=" + id,'newwindow','width=690px','height=420px;');
     
     
}



function openSubscription(id)
{

  
     window.open("addSubfeeforPublication.aspx?bookid=" + id,'newwindow',"toolbar=no,menubar=no,scrollbars=no,width=450px,height=300px");
     
     
}
function Redirect(id,ctl)
{
  var id  =document.getElementById(id).value;
 
 ctl.href="searchDatabase.aspx?keyword=" + id;
 // window.open("searchDatabase.aspx?keyword=" + id);

}




function ShowName()
{
  /*this code commentise but it is useful for other work dont delete it*/
//var i,text;

//i=document.getElementById('lstbxUsers')
//var trimvalue=trim(i.value);

// if(trimvalue.length==0)
//		{
//		 alert("Please Select user from the list.");
//   return;
//		}

//var t=i.getElementsByTagName("option");



//for(count=0;count<t.length;count++)
//{
//if(t[count].value==i.value)
//text=t[count].innerText;
//}
//var splitArray=new Array();
//   splitArray=text.split('-');
//   if(splitArray.length>0)
//      text=splitArray[0];
//      
//    document.getElementById('spnName').innerHTML= text;
 
 var now = new Date();
var hour = now.getHours();

var minute = now.getMinutes();
var time= hour +":"+ minute
//

document.getElementById('spnTime').innerHTML=time;
   
   }

function enterPressed(e,ctrlname)
{

  if (e.keyCode==13)
  {
	document.getElementById(ctrlname).click();
  }	

}
function clearText(ctl1)
{
document.getElementById("ctl00_ContentPlaceHolder1_" +ctl1).value="";
}
function ShowDiv(id)
{

   if(document.getElementById(id))
   document.getElementById(id).style.display="";
}
function HideDiv1(id)
{
  document.getElementById('divDetails').style.display="none" ;
  
}
function OpenWindow(url)
{
var i,text;

i=document.getElementById('lstbxUsers')
var trimvalue=trim(i.value);

 if(trimvalue.length==0)
		{
		 alert("Please Select user from the list.");
   return;
		}
 
   // opener.location.close();
 //  opener.location.href=url + i.value;
  
    window.open(url + i.value,"_parents","toolbar=no,menubar=no,resizable=1,scrollbars=yes,width=600,height=700");
 // window.close();
}

function OpenNewWindow(flag,url)
{
var i,text;

i=document.getElementById('lstbxUsers')
var trimvalue=trim(i.value);

 if(trimvalue.length==0)
		{
		 alert("Please Select user from the list.");
   return;
		}
		if(flag=="0")
   window.open(url + i.value,"_parents","toolbar=no,menubar=no,scrollbars=yes,width=750px,height=700px");
   else
   window.open(url + i.value,"_parents","toolbar=no,menubar=no,scrollbars=no,width=380px,height=320px");
}


function ShowDiv1()
{
   document.getElementById('divDetails').style.display='';
}

function window_onload() {
 window.name =''
} 

    function window_onfocus() {

  if (window.name == 's') 
  { 
  document.aspnetForm.submit();
  window.name ='' 
  }
}



	
function previewimage(path,imgid,err,errimg)
{
var strpath;

strpath=document.getElementById(path).value;
 var trimvalue=trim(strpath);


 if(trimvalue.length==0)
		{
		//	document.getElementById(err).innerHTML='Input required, cannot leave blank';
			document.getElementById(err).style.color = '#fff200';
			document.getElementById(err).style.display = '';
			document.getElementById(err).style.fontWeight ='bold';
			document.getElementById(errimg).style.display = 'none';
			return false;
		}
		else
		 {
		 var imgtype = new Array();
		 imgtype=strpath.split(".");
		 if(imgtype.length > 1)
		 {
		 var len=imgtype.length;
		 len++;
		 len--;
		  var type=imgtype[len-1].toLowerCase();

		 if(type =='bmp' || type =='jpg' ||type =='jpeg' || type =='png' || type =='gif')
		 {
		 
		  document.getElementById(imgid).src=strpath;	
	
		  document.getElementById(imgid).style.display = '';
		  document.getElementById(err).style.display = 'none';
		  document.getElementById(errimg).style.display = 'none';	
		  
		 	 
		 return true;
		 }
		 else
		 {
		 document.getElementById(errimg).style.color = '#fff200';
		 document.getElementById(errimg).style.fontWeight ='bold';
		 document.getElementById(errimg).style.display = '';
		  document.getElementById(err).style.display = 'none';
		 
		  return false;
		 }
		 
		 }
		else
		{
	    	document.getElementById(errimg).style.color = '#fff200';
	    	document.getElementById(errimg).style.fontWeight ='bold';
		  document.getElementById(errimg).style.display = '';
		   document.getElementById(err).style.display = 'none';
		   return false;
		}
		
		 }

}
//============================= Function to trim value in text box ===================================
 function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}
//================================ Function to validate blank text box =================================
function checkblank(txt,err)
{
 var txtvalue=document.getElementById(txt).value;
 var trimvalue=trim(txtvalue);
 if(trimvalue.length==0)
		{
		//	document.getElementById(err).innerHTML='Input required, cannot leave blank';
			document.getElementById(err).style.color = 'red';
			document.getElementById(err).style.display = '';
			return false;
		}
		else
		 {
		 document.getElementById(err).style.display = 'none';
		 return true;
		 }
}
function validateInteger( strValue,isdecimal) 
{

if(isdecimal==0)
{

  var objRegExp  = /(^-?\d\d*$)/;
    return objRegExp.test(strValue);
    }
    else
    {

   // var objRegExp  =   '[0-9]*' ; 
   //  objRegExp + = '\\.?[0-9]{0,'3'}';
     
  //  var reg0 = new RegExp(objRegExp) ;
    return true;// reg0.test(strValue);
   }
}
function HideAll()
{

}
function toggle(trigger, el,ex,colapse )
{

  var element = document.getElementById(el);
 // var element1 = document.getElementById('a' + el);
  if(element.style.display=="none")
  {
    element.style.display="";
   // element1.style.display="";
     trigger.src= '../gfx/minus.gif';
     trigger.alt=colapse;
  }
  else
  {
    element.style.display="none";
   //  element1.style.display="none";
    trigger.src=  '../gfx/plus.gif';
     trigger.alt=ex;
  }
}


 


//--Code for size fixing of image
function image_resize()
       {
       
       window.name =''
         if(document.getElementById("tblFixImg"))
           {

            var pix=document.getElementById("tblFixImg").getElementsByTagName('img');
  
            for (i=0; i<pix.length; i++) 
             {
              if(pix[i].name!='no')
             {
            if(pix[i].height>80)
            pix[i].height=80;
            if(pix[i].width>80)
            pix[i].width=80;
            }      
            }
            }
         if(document.getElementById("tblFixImg1"))
           {

            var pix=document.getElementById("tblFixImg1").getElementsByTagName('img');
    
            for (i=0; i<pix.length; i++) 
             {
              if(pix[i].name!='no')
             {
            if(pix[i].height>100)
            pix[i].height=100;
            if(pix[i].width>100)
            pix[i].width=100;
            }      
            }
            }   
       }