/*
This Function chekc for require field and set focus on the controls.
Developed By Nikhil.27/12/2004
How to Use:
		  To Use this function you have to put required as starting of 
		  anf textbox field.
		  And put checkrquired(this) in submit button.	
*/
// Take user here after session timed out
timedouturl = "index.aspx";
function delmsg(mvl)
		{
		    return confirm('Are you sure to delete '+mvl+'?');
		}

function enlarge(LImg,stitle)
{
myWindow = window.open("","", 'width=1,height=1,top=100,left=100,toolbar=no,scrollbars=no')
myWindow.document.write("<html><head><title>photo</title></head>")
myWindow.document.write("<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onload='window.resizeTo(img.width+50,img.height+60);'>")
//myWindow.document.write("<table width=100% border=0><tr bgcolor=#ff6c00><td align=center><font color=white size=2px face=Tahoma><b>Photo</b></font></td></tr></table>")
myWindow.document.write("<div align=Center><img  src='"+ LImg +"'  id='img'></div></body></html>")
myWindow.document.close()
}
	
function Minutes(data)
{
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(0, i));
}
function Seconds(data)
{
for (var i = 0; i < data.length; i++)
if (data.substring(i, i + 1) == ":")
break;
return (data.substring(i + 1, data.length));
}
function Display(min, sec)
{
var disp;
if (min <= 9) disp = " 0";
else disp = " ";
disp += min + ":";
if (sec <= 9) disp += "0" + sec;
else disp += sec; 
return (disp);
}
function Down()
{ 
sec--;      
if (sec == -1) { sec = 59; min--; }
document.Form1.clock.value = Display(min, sec);
window.status = "Session will time out in: " + Display(min, sec);
if (min == 0 && sec == 0)
{
//alert("Your session has timed out.");
window.location.href = timedouturl;
}
else down = setTimeout("Down()", 1000); 
}
function timeIt()
{
min = 1 * Minutes(document.Form1.clock.value);
sec = 0 + Seconds(document.Form1.clock.value);
Down();
 
}

//cookie
function GetCookie (name) { 
var arg = name + "="; 
var alen = arg.length; 
var clen = document.cookie.length; 
var i = 0; 
while (i < clen) {
var j = i + alen; 
if (document.cookie.substring(i, j) == arg) 
return getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1; 
if (i == 0) break; 
} 
return null;
}
function SetCookie (name, value) { 
var argv = SetCookie.arguments; 
var argc = SetCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + 
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) { 
var exp = new Date(); 
exp.setTime (exp.getTime() - 1); 
var cval = GetCookie (name); 
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

//end cookie
function getURLParameters() 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}
	}
	else
	{
		alert("No parameters.");
	}
}
function checkrequired(which) {
var blneCheck=false;
var pass=true;
if (document.images) 
{
  
  for (i=0;i<which.length;i++) 
	{
	var tempobj=which.elements[i];	
	if (tempobj.name.substring(0,8)=="required") 
		{		
		if (((tempobj.type=="text"||tempobj.type=="textarea")&&
		tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
		tempobj.selectedIndex==0)) 
			{
				pass=false;
				break;
			}
		}
   
	if (tempobj.name.substring(0,8)=="erequire") 
		{			
			if(tempobj.type=="text" && tempobj.value=='')
			{
				pass=false;
				break;
			}			
			else 
			{
				
				if(echeck(tempobj.value)==false)
				{						
					blneCheck=true;
					pass=false;
					break;					
				}
			 }					        
		}
	}
 }  

if (!pass) 
{
   if (tempobj.name.substring(0,8)=="required")
   {			
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();		
		tempobj.focus();
		alert("Please make sure the "+shortFieldName+" field was properly completed.");
		return false;
	}
	if (tempobj.name.substring(0,8)=="erequire") 
	{
		if(!blneCheck)
		{
			shortFieldName=tempobj.name.substring(8,30).toUpperCase();
			tempobj.focus();
			alert("Please make sure the "+shortFieldName+" field was properly completed.");	
			return false;
		}
		else
		{
			shortFieldName=tempobj.name.substring(8,30).toUpperCase();
			tempobj.focus();
			alert("Please make sure email address in "+shortFieldName+" was properly completed.");	 
			return false;
		}
    }
}  
else
{
	return true;
}
	
}

/*
This Function check for valide emaill address.
Developed By Nikhil.27/12/2004
How to Use:
		   Just pass the string that has to be check for required email address.	
		  
*/


function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){		   
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){		   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){		    
		    return false
		 }
 		 return true					
	}	


function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal) 
{
        re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon
        for(i = 0; i < document.forms[0].elements.length; i++) {
            elm = document.forms[0].elements[i]
            if (elm.type == 'checkbox') {
                if (re.test(elm.name)) {
                    elm.checked = checkVal
                }
            }
        }
	}
function SelectDeselectAll(aspCheckBoxID, checkVal) 
{
    re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon
    for(i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'checkbox') {
            //if (re.test(elm.name)) {
                elm.checked = checkVal
            //}
        }
    }
}	
function CheckDeleteCheckBoxes(aspCheckBoxID, checkVal,recType) 
{	
	re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon				
	var strcount="1";
	for(i = 0; i < document.forms[0].elements.length; i++) 
		{
			elm = document.forms[0].elements[i]
			if (elm.type == 'checkbox') 
			   {						
				if(elm.checked==true)
					{							
						strcount =strcount + "11" ;
					}
				}
		}				
	
	if(strcount=="1")
		{
					alert('No record selected.');
					return false;
		}
	else
		{
					return confirm('Are you sure to delete '+ recType + ' ?')
					//return true;				
		}
				
	}	
function CheckCheckBoxes(aspCheckBoxID, checkVal) 
{	
	re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon				
	var strcount="1";
	for(i = 0; i < document.forms[0].elements.length; i++) 
		{
			elm = document.forms[0].elements[i]
			if (elm.type == 'checkbox') 
			   {						
				if(elm.checked==true)
					{							
						strcount =strcount + "11" ;
					}
				}
		}				
	
	if(strcount=="1")
		{
					alert('No record selected.');
					return false;
		}
	else
		{
					return confirm('Are you sure to delete?')
					//return true;				
		}
				
	}	
	function CheckCheckBoxes1(aspCheckBoxID, checkVal) 
{	
	re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon				
	var strcount="1";
	for(i = 0; i < document.forms[0].elements.length; i++) 
		{
			elm = document.forms[0].elements[i]
			if (elm.type == 'checkbox') 
			   {						
				if(elm.checked==true)
					{							
						strcount =strcount + "11" ;
					}
				}
		}				
	
	if(strcount=="1")
		{
					alert('No record selected.');
					return false;
		}
	else
		{
					//return confirm('Are you sure to delete Record?')
					return true;				
		}
				
	}	

function CheckEditCheckBoxes(aspCheckBoxID, checkVal) 
{	
	re = new RegExp(':' + aspCheckBoxID + '$')  //generated control name starts with a colon				
	var strcount="1";
	for(i = 0; i < document.forms[0].elements.length; i++) 
		{
			elm = document.forms[0].elements[i]
			if (elm.type == 'checkbox') 
			   {						
				if(elm.checked==true)
					{							
						strcount =strcount + "11" ;
					}
				}
		}				
	
	if(strcount=="1")
		{
					alert('No record selected.');
					return false;
		}
	else
		{
					
					return true;				
		}
				
	}		

function popcat(sURL)
	{
		window.open(sURL,'popup','width=450, height=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
	}	
function pophelp(sURL)
	{
		window.open(sURL,'popup','width=800, height=600, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
	}	
function popchanel(sURL)
	{
		window.open(sURL,'popup','width=450, height=500, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, directories=no, status=no')
	}		
