var isNS = (navigator.appName.indexOf("Netscape")!=-1); 

// n: id of object(string)
// d: document which will be searched for
// Examples:
// 1. FindObject('txtName');
// 2. FindObject('txtName',window.opener.document);
function FindObject(n, d)
{
	var p,i,x;  if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; 
		for (i=0;!x&&i<d.forms.length;i++) 
			x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
			x=FindObject(n,d.layers[i].document);
	if(!x && document.getElementById) 
		x=document.getElementById(n); 
	return x;
}
	

	
	function checkHtmlTags(control)
	{
		var invalidControls = "";
		
		if(control.value.indexOf('<') > -1)
		{
			invalidControls = "< ";
			control.value = control.value.replace("<",'')
		}
		else if(control.value.indexOf('/>') > -1)
		{
			invalidControls += "/> "
			control.value = control.value.replace("/>",'')
		}
		else if(control.value.indexOf('>') > -1)
		{
			invalidControls += "> "
			control.value = control.value.replace(">",'')
		}
						
		if(invalidControls.length != 0)
		{
			//alert("Please dont use characters like " + invalidControls);
			return;
		}		
	}
	
	function Trim(s) 
	{
   			// Remove leading spaces and carriage returns
   			while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
   			{ s = s.substring(1,s.length); }
		     
   			// Remove trailing spaces and carriage returns
			while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
   			{ s = s.substring(0,s.length-1); }
		     
   			return s;
	}
	
	
   
	function IsAlphanumeric(alphane)
	{
		var numaric = alphane;
		for(var j=0; j<numaric.length; j++)
		{
			var alphaa = numaric.charAt(j);
			var hh = alphaa.charCodeAt(0);
			if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || (hh == 32))
			{
			}
			else	
			{
				return false;
			}
		}
		return true;
	}

    function AutoRedirectToFrame()
	{
		var url = top.location.href.substring(top.location.href.indexOf('Admin/') + 6);
		
		if (top.location.href.lastIndexOf("Frames.aspx") < 0) 
		{
			top.location.href = "Frames.aspx?MainFrameURL=" + url
		}
	}
	
	
function leapYear(Year)
{
	return (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) ? 1 : 0;
}

function getDaysInMonth(month, year) {
	var days;
	if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
		days=31;
	else if (month==4 || month==6 || month==9 || month==11)
		days=30;
	else if (month==2){
		if (leapYear (year)==1)
			days=29;
		else
			days=28;
	}
	return (days);
}

function validateDate(d, m, y,errorMsg,changedOne)
{
	var day = FindObject(d);
	var month = FindObject(m);
	var year = FindObject(y);
	var changed = FindObject(changedOne);
	
	var myDate = day.value;
	var myMonth = month.selectedIndex +1 ;
	var myYear = year.value;

	if(parseInt(myDate) > getDaysInMonth(myMonth, myYear))
	{
		alert(errorMsg);
		changed.selectedIndex = 0;
		return false;
	}
	return true;
}
   

// w: dialog width
// h: dialogheight
// rs:1/0 resizable
// sc:1/0 scrollable
// mn:1/0 menuvisible
// Examples:
// <a href="myUrl" onclick="return Popup(this.href,400,300,0,0,0);">click to popup</a>
function Popup(url,w,h,rs,sc,mn)
{
	t = (screen.height/2)-(h/2);
	l = (screen.width/2)-(w/2);
	newwindow = window.open(url,'bsh','toolbar=0, status=1, menubar=' + mn + ', location=0, resizable=' + rs + ', scrollbars=' + sc + ', width=' + w + ', height=' + h + ', top=' + t + ', left=' + l);
	if (window.focus) { newwindow.focus() }
	return false;
}

function Popup1(url,rs,sc,mn)
{
	// return Popup(url,600,400,rs,sc,mn);
	w = 600;
	h = 400;
	t = (screen.height/2)-(h/2);
	l = (screen.width/2)-(w/2);
	newwindow = window.open(url,'bsh','toolbar=0, status=1, menubar=' + mn + ', location=0, resizable=' + rs + ', scrollbars=' + sc + ', width=' + w + ', height=' + h + ', top=' + t + ', left=' + l);
	if (window.focus) { newwindow.focus() }
	return false;
}

function Popup2(url,target,properties)
{		
			if (target == '_self')
			{	
				window.open(url, '_self');
			}
			else
			{
				var strwidth = 'width';
				var strheight = 'height';
				var strStatus = 'status';
				var startIndex ;
				var endIndex ;
				var width ;
				var height ;
				
				
				startIndex = properties.indexOf(strheight);
				strheight = strheight + '=';
				startIndex = startIndex + strheight.length;
				endIndex = properties.indexOf(strwidth);
				height = properties.substring(startIndex,endIndex-1);	
				
				
				startIndex = properties.indexOf(strwidth);
				strwidth = strwidth + '=';
				startIndex = startIndex + strwidth.length;
				endIndex = properties.indexOf(strStatus);				
				width = properties.substring(startIndex,endIndex-1);
				
				var leftDim = (screen.width - width) / 2;
				var topDim = (screen.height - height) / 2;
				var hwString = 'left=' + leftDim + ',top=' + topDim + ',' + properties;				
				window.open(url, '_blank', hwString);							
			}	
			return false;	
}		

// base page function for Admin
function AvoidHistoryBack__()
{
	if (window.history.length > 0)
		window.history.forward();
}

function emailCheck (emailStr) 
{
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
		
	if (matchArray==null) {
	return false;
	}
		
	var user=matchArray[1];
	var domain=matchArray[2];
		
	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	return false;
	}
	}
		
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	return false;
	}
	}
		
	if (user.match(userPat)==null) {
	return false;
	}
		
	var IPArray=domain.match(ipDomainPat);
		
	if (IPArray!=null) {
	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
		return false;
	}
	}
	return true;
	}
		
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
		
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	return false;
	}
	}
		
	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	return false;
	}
		
	if (len<2) {
	return false;
	}
		
	return true;
}

//PROGRESS LAYER CODES START
///////////////////////////////////////////////////////////////////////////////////////
function ActivateProgressArea()
{
	for(i = 0; i < document.forms[0].elements.length; i++) 
	{
		elm = document.forms[0].elements[i];
		if(elm.type == 'select-one' || elm.type == 'select-multiple')
		{
			elm.style.visibility = "HIDDEN";
		}
	}
	
	var progressBar = 'progressBar';
	var progressBarUnSeen = 'progressBarUnSeen';
	
	document.getElementById(progressBar).style.visibility = '';
	document.getElementById(progressBar).style.zIndex = 1001;
	document.getElementById(progressBarUnSeen).style.visibility = '';
	document.getElementById(progressBarUnSeen).style.zIndex = 1000;
	document.getElementById(progressBarUnSeen).style.height = document.body.scrollHeight;
	document.getElementById(progressBarUnSeen).style.width = document.body.scrollWidth;
}

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset)
	{
		yScrolltop = self.pageYOffset;
	} 
	else if (document.documentElement && document.documentElement.scrollTop)
	{	 
		yScrolltop = document.documentElement.scrollTop;
	} 
	else if (document.body) 
	{
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
}

function getPageSize()
{
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}
///////////////////////////////////////////////////////////////////////////////////////
//PROGRESS LAYER CODES END


//Copyrights Management Crosscut, used in news
function linkClick(width, height, pageId)
{
	 x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }

    window.open('ExpiredPage.aspx?pageId='+pageId,'newWin', 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
}
///Copyrights Management Crosscut, used in news