function doNothing(e){return true;}
function doNothing1(e)
{
	nodename=(e)?e.target.nodeName:(event)?event.srcElement.nodeName:'';
	if(nodename=="TEXTAREA" || nodename=="INPUT")
		return true;
	if(document.selection)
	{
		if(document.selection.type!='None')
		return true;
	}

	else if(document.getSelection)
	{
		x=document.getSelection();
		if(x.length>0)
			return true;
	}	
return false;
}
//window.onerror=doNothing;
//document.oncontextmenu=doNothing1;

function OpenLinkedDocs(type,pk)
{
	window.open(BaseDir + 'common/tmalinkeddocuments.aspx?itemtype=' + type +'&itemfk='+ pk,'popup','top='+((self.screen.availHeight/2)-250)+',left='+((self.screen.availWidth/2)-275)+',width=630, height=550,resizable=yes,status=yes');	
}
function TMAOpenWindow(url,wWidth,wHeight,targetFrame,windowOptions)
{	if(!wWidth) wWidth=870;
	if(!wHeight) wHeight=620;
	wTop=((self.screen.availHeight/2)-(wHeight/2));
	wLeft=((self.screen.availWidth/2)-(wWidth/2));
	if(!targetFrame || targetFrame.length<1)
		targetFrame="_blank";
	options='top=' + wTop +',left=' + wLeft + ',width=' + wWidth + ',height=' + wHeight +',status=yes,resizable=yes,scrollbars=yes';
	if(targetFrame.toLowerCase()=="_self")
	{
		location.replace(BaseDir + url);
		if(wHeight==620)
			wHeight=660;
		window.moveTo(wTop,wLeft);
		window.resizeTo(wWidth,wHeight);				
		return;
	}
	if(windowOptions && windowOptions.length>0)
		options += ',' + windowOptions;
	var win=window.open(BaseDir + url, targetFrame,options)
	return win;
}
function mask2DP(value)
{
	value=value+"";
	if(!value.match(/^[-+]?\d*\.\d{2}$/))
	{
		if(value.match(/^[-+]?\d*\.\d{1}$/))
		{
			value=value+"0"
		}
		else
		{
			if(value.indexOf('.')<0)
			{
				value=value+".";
			}
			value=value+"00";
		}
	}
	
	
	if(value.length>(value.indexOf('.')+3))
	{
		value=value.substring(0,(value.indexOf('.')+3));
	}
	//else if(value='.00') value='0'+value;
	
	return value;
}
function mask3DP(value)
{
	value=value+"";
	if(!value.match(/^[-+]?\d*\.\d{3}$/))
	{
		if(value.match(/^[-+]?\d*\.\d{2}$/))
		{
			value=value+"0"
		}
		else if(value.match(/^[-+]?\d*\.\d{1}$/))
		{
			value=value+"00"
		}
		else
		{
			if(value.indexOf('.')<0)
			{
				value=value+".";
			}
			value=value+"000";
		}
	}
	
	
	if(value.length>(value.indexOf('.')+4))
	{
		value=value.substring(0,(value.indexOf('.')+4));
	}
	return value;
}
function CreateWorkorder(type,pk)
{	
	TMAOpenWindow('workorder/workorder.aspx?mode=1&eqpk=' + pk + '&eqtype=' + type,898,608,'workorder');
	//PCR: 28382 adjusted the window size. JH:10/6/2006
	//TMAOpenWindow('workorder/workorder.aspx?mode=1&eqpk=' + pk + '&eqtype=' + type,false,false,'workorder');
}
function GetQueryString(key)
{
	var srch=location.search;
	if(srch.length<1)
		return '';
	srch=srch.substring(1);
	var keys=srch.split("&");
	for(i=0;i<keys.length;i++)
	{
		var x=keys[i].split("=");
		if(x[0].toLowerCase()==key.toLowerCase())
			return x[1];		
	}
	return '';
}
function getIndexOf(array,value,caseSensitive)
{
	if(!caseSensitive)
	{
		array=array.join("$#$").toLowerCase().split("$#$");
		value=value.toLowerCase();
	}
	for(i=0;i<array.length;i++)
	{
		if(array[i]==value)
			return i;				
	}	
	return -1;
}
function SendEmail(mailBody,mailTo,mailSubject,htmlFormat,newWindow,targetFrame,windowOptions) 
{

	if(!windowOptions || windowOptions==null || windowOptions.length<1)
	windowOptions="top=100,left=100, width=720, height=500,status=yes,resizable=yes"
	if(!targetFrame || targetFrame==null)
		newWindow=true;
	if(newWindow && targetFrame==null)
		targetFrame="webTMAEmailWin";
	if(newWindow)
		emailWin=window.open(BaseDir + "common/TMASetMail.aspx",targetFrame,"top=100,left=100, width=720, height=500,status=yes,resizable=yes");
	else
	{
		emailWin=targetFrame;
		targetFrame.location.replace(BaseDir + "common/TMASetMail.aspx");
	}
	emailWindow=emailWin;
	if(!mailTo) mailTo='';
	if(!mailSubject) mailSubject='';
	TMASendMailNow(escape(mailBody),mailTo,mailSubject,htmlFormat);
}
var emailWindow=null;
function TMASendMailNow(mailBody,mailTo,mailSubject,htmlFormat)
{
	if(!emailWindow)return;
	if(!emailWindow.MailLoaded)
	{
		setTimeout("TMASendMailNow('" + mailBody  + "','" + mailTo + "','" + mailSubject+ "',"+ htmlFormat +");",10);
		return;
	}
	emailWindow.SendMail(unescape(mailBody),mailTo,mailSubject,htmlFormat)	
}
function GetUniqueValue()
{
	return top.UniqueValue();
}
if(self==top && typeof(cswmT)=='undefined')
{
	cswmT=new Function("return null;");
	cswmST=new Function("return null;");
	theDate = new Date();
	window.myUniqueVal = theDate.getYear().toString() + ":" + theDate.getMonth().toString() + ":" + theDate.getDate().toString() + ":" + theDate.getTime();
	window.GetUniqueValue=new Function("return myUniqueVal");		
}
function CloseWhenNoActivity()
{
	setTimeout('window.close();',120000);
}



function ChangeLvwUTCtoLocal(itemidentity,thedatevalue, thenewdateformat)
{
	var theUTCtime = new Date(thedatevalue + " UTC"); 
	var returndatetime=" ";
	var theUTCYear = theUTCtime.getFullYear();
	var monthforUTC = theUTCtime.getUTCMonth() + 1;
	if (monthforUTC < 10)
	    monthforUTC = '0' + monthforUTC;
	var dateforUTC = theUTCtime.getUTCDate();
	if (dateforUTC < 10)
	    dateforUTC = '0' + dateforUTC;
	var theUTCMonth = theUTCtime.getMonth()+1;
	if (theUTCMonth < 10)
	    theUTCMonth = '0' + theUTCMonth;
	var theUTCDate = theUTCtime.getDate();
	if (theUTCDate < 10)
	    theUTCDate = '0' + theUTCDate;
	if(thenewdateformat != "")
	{
	    if(thenewdateformat.indexOf('/') >= 0 || thenewdateformat.indexOf('.') >= 0)
	    {
		    var dateandtime = thenewdateformat.split(' '); 
		    var datesplitter = " "; 
		    var monthdayyear= " "; 
		    if(dateandtime[0].indexOf('/') > 0) 
		    {
			    monthdayyear = dateandtime[0].split('/');datesplitter='/';
		    } 
		    else 
		    {
			    monthdayyear = dateandtime[0].split('.');datesplitter='.';
		    } 
		    if(monthdayyear[0].indexOf('y')==0)
		    {
			    if(monthdayyear[1].indexOf('M')==0)
			    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = theUTCtime.getUTCFullYear()+datesplitter+monthforUTC+datesplitter+dateforUTC; 
			        else
    				    returndatetime = theUTCtime.getFullYear()+datesplitter+theUTCMonth+datesplitter+theUTCDate; 
			    }
			    else
			    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = theUTCtime.getUTCFullYear()+datesplitter+dateforUTC+datesplitter+monthforUTC; 
                    else
    				    returndatetime = theUTCtime.getFullYear()+datesplitter+theUTCDate+datesplitter+theUTCMonth; 
			    }
		    } 
		    else
		    { 
			    if(monthdayyear[0].indexOf('M')==0)
			    {
				    if(monthdayyear[1].indexOf('d')==0)
				    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = monthforUTC+datesplitter+dateforUTC+datesplitter+theUTCtime.getUTCFullYear(); 
                    else
                        returndatetime = theUTCMonth+datesplitter+theUTCDate+datesplitter+theUTCtime.getFullYear(); 
				    } 
				    else
				    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = monthforUTC+datesplitter+theUTCtime.getUTCFullYear()+datesplitter+dateforUTC; 
                    else
					    returndatetime = theUTCMonth+datesplitter+theUTCtime.getFullYear()+datesplitter+theUTCDate; 
				    }
			    }
			    else
			    {
				    if(monthdayyear[1].indexOf('M')==0)
				    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = dateforUTC+datesplitter+monthforUTC+datesplitter+theUTCtime.getUTCFullYear(); 
                    else
					    returndatetime = theUTCDate+datesplitter+theUTCMonth+datesplitter+theUTCtime.getFullYear(); 
				    } 
				    else
				    {
			        if(theUTCtime.getUTCHours() == 0 && theUTCtime.getUTCMinutes() == 0 && theUTCtime.getUTCSeconds()== 0 && thenewdateformat.indexOf(':')<0)
			            returndatetime = dateforUTC+datesplitter+theUTCtime.getUTCFullYear()+datesplitter+monthforUTC; 
                    else
					    returndatetime = theUTCDate+datesplitter+theUTCtime.getFullYear()+datesplitter+theUTCMonth;
				    }
			    }
		    }
		}
		if(thenewdateformat.indexOf(':')>0) 
		{
		    if (theUTCtime.getHours() < 10 && theUTCtime.getMinutes() < 10)		
			    returndatetime+= ' 0' + theUTCtime.getHours()+ ':0'+ theUTCtime.getMinutes();
		    else if (theUTCtime.getHours() < 10 && theUTCtime.getMinutes() >= 10)		    
			    returndatetime+= ' 0' + theUTCtime.getHours()+ ':'+ theUTCtime.getMinutes();
		    else if (theUTCtime.getHours() >= 10 && theUTCtime.getMinutes() < 10)		    
			    returndatetime+= ' ' + theUTCtime.getHours()+ ':0'+ theUTCtime.getMinutes();
		    else 	    
			    returndatetime+= ' ' + theUTCtime.getHours()+ ':'+ theUTCtime.getMinutes();
	    }
	}
	document.getElementById(itemidentity).value= returndatetime;
	document.getElementById(itemidentity).innerText= returndatetime;
}

