var isDirty=false;
var unloadmsg='You have changed data in this form.';

function fixsql(d){
    return d.replace("'","''");
}

function confirmExit(){
    if (document.forms[0])
    {
        if(document.forms[0].formaction)
        {
            if (document.forms[0].formaction.value!='')
                isDirty=false;
        }
        if(document.forms[0].FormAction)
        {
            if (document.forms[0].FormAction.value!='')
                isDirty=false;
        }   
        if(document.forms[0].formAction)
        {
            if (document.forms[0].formAction.value!='')
                isDirty=false;
        } 
        if(document.forms[0].Formaction)
        {
            if (document.forms[0].Formaction.value!='')
                isDirty=false;
        }  
        if(document.forms[0].Frmaction)
        {
            if (document.forms[0].Frmaction.value!='')
                isDirty=false;
        }          
                            
    }
    if (isDirty){
    return unloadmsg;
    }
}
function doDataChanged(){
    isDirty=true;
    if (document.getElementById('datachanged')){
        if (document.forms[0].datachanged)
            document.forms[0].datachanged.value=1
        }
}
function toggleRecent(id){
var now=new Date();
fixDate(now);
now.setTime(now.getTime()+365*24*60*60*1000);

    if (document.getElementById(id))
    {
        if (document.getElementById(id).style.display=='none')
        {
            document.getElementById(id).style.display='block'
            setCookie(id,'1',now,'/')
            
        }
        else
        {
            document.getElementById(id).style.display='none'
            setCookie(id,'0',now,'/')
        }
        
    }

}
function doprint(){ 
    self.focus() 
    self.print() 
} 

function isDefined(Obj)
{
    if( typeof(Obj)=='function'||typeof(obj)=='object')
        return true;
    else
        return false;

}

function setTitle()
{
    if (document.title!='')
        window.top.document.title=document.title;
}


function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}


function resize_iframe(iframeID)
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById(iframeID).style.height=parseInt(height-
	document.getElementById(iframeID).offsetTop-8)+"px";
	document.getElementById(iframeID).style.display='block';
}

function doRC(){
    window.open("setRC.asp","RC","toolbar=0,location=0,status=0,menubar=0,width=560,height=300,scrollbars=0,resizable=0");
}

function getCookie(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 setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function fixDate(date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function PreloadImages(){
var ImgArr=new Array();
for (i=0;i>PreloadImages.arguments.length;i++){
ImgArr[i]=new Image()
ImgArr[i].src=PreloadImages.arguments[i]
}


}

function onload_reloadme () {
  if (document.reloadme_form.reloadme_field.value == "reloadme" ) {
    self.location.reload(true)
  } else {
    document.reloadme_form.reloadme_field.value = "reloadme";
  }

}

function DisplayHelp(ID,ImagePath,Lang){
if (arguments.length>3)
{
    window.open(arguments[3],"DNAHelp","toolbar=0,location=0,status=0,menubar=0,width=800,height=600,scrollbars=0,resizable=1");


}
else
{
    if (Lang){
	    if (Lang=='')
		    Lang='EN';
	    window.open(ImagePath+"webhelp/"+Lang+"/Help_Desk.htm?introduction/welcome.htm","DNAHelp","toolbar=0,location=0,status=0,menubar=0,width=800,height=600,scrollbars=0,resizable=1");
        }
    else
	    {
	    window.open(ImagePath+"webhelp/EN/Help_Desk.htm?introduction/welcome.htm","DNAHelp","toolbar=0,location=0,status=0,menubar=0,width=800,height=600,scrollbars=0,resizable=1");
	    }

}
}


function displaysave(){
if (document.getElementById){
if (document.getElementById("MainPage") && document.getElementById("SaveImg"))
{
document.getElementById("MainPage").style.display="none"
document.getElementById("SaveImg").style.display="inline"


}
}


}


function NumbericTime(evnt) {
if (document.all){
keyCode=evnt.keyCode
}
else
{
keyCode=evnt.which
}
if (keyCode>31){
	if(keyCode<48 || keyCode>58)
	{

	return false;
	}
}
return true;
}
function HTMLColorCode(evnt) {
if (document.all){
keyCode=evnt.keyCode
}
else
{
keyCode=evnt.which
}

if (keyCode>64 && keyCode<71)
    return true;
if (keyCode>96 && keyCode<103)
    return true;
if (keyCode==35)
    return true;

if (keyCode>31){
	if(keyCode<48 ||keyCode>57)
	{

	return false;
	}
}
return true;
}

function Numberic(evnt) {
if (document.all){
keyCode=evnt.keyCode
}
else
{
keyCode=evnt.which
}
if (keyCode>31){
	if(keyCode<48 ||keyCode>57)
	{

	return false;
	}
}
return true;
}

function NumbericIP(evnt) {
if (document.all){
	keyCode=evnt.keyCode
	}
else
	{
	keyCode=evnt.which
	}
	
if (keyCode>31){
	if(keyCode<48 ||keyCode>58)
	{
	if(keyCode==46)
		return true;
	return false;
	}
}
return true;
}

function SimpleValidEmail(EmailAddress){

if (EmailAddress.indexOf("'")>0)
	return true;
	
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     if(regex.test(EmailAddress)){
    if(EmailAddress.length == (EmailAddress.indexOf("@")+1) ) {
       return false;
       }

    if(EmailAddress.length == 0) { 
      return false; 
      }     
     }
     else
     {
		return false;
     }
     return true;


}

function ValidateEmail(EmailAddress) {
	if (EmailAddress.toLowerCase()=="admin")
		return true
		
	EmailParts=EmailAddress.split("@")
	if (EmailParts.length!=2)
		return false;
		
	//check the MailboxName

var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4}|travel|museum)(\]?)$/; // valid
  if (!reg1.test(EmailAddress) && reg2.test(EmailAddress)) { // if syntax is valid

    if(EmailAddress.length == (EmailAddress.indexOf("@")+1) ) {
       return false;
       }

    if(EmailAddress.length == 0) { 
      return false; 
      }     
     }
     else
     {
		return false;
     }
     return true;
  }



function SelFill(SelObj,aValues,aText){
var x
SelObj.disabled=false
for (i=0;i<aValues.length;i++){
	x=new Option(aText[i],aValues[i]);
	SelObj.options[SelObj.options.length]=x;
	}
}

function ClearSel(SelObj){
var x=SelObj.options.length;
for (i=0;i<x;i++){
	SelObj.options[0]=null;
	}
}

function DisplayMenu(){
var imagepath="";
if (arguments[0] != null){
		imagepath=arguments[0];

		}
if (document.getElementById){
if (document.getElementById("MenuDiv").style.display=="none"){
document.getElementById("MenuDiv").style.display="block"
document.getElementById("MenuDivImg").className='menudivimgopen';
//document.getElementById("MenuDivImg").src=imagepath+'images/menuup.gif'
document.getElementById("menutd").bgcolor="#8cbdef"
if (window.parent.frames){
window.parent.frames[0].menuVisiable=true;
}
}
else
{
document.getElementById("MenuDiv").style.display="none"
document.getElementById("MenuDivImg").className='menudivimgclosed';
//document.getElementById("MenuDivImg").src=imagepath+'images/menudown.gif'
document.getElementById("menutd").bgcolor="#c0c0c0"
if (window.parent.frames){
window.parent.frames[0].menuVisiable=false;
}
}
}

}
function ChangePassword(){
window.open("/Helpdesk/Changepass.asp","ChangePass","toolbar=0, ststus=0, location=0, menubar=0,resizable=0, width=450,height=200,scrollbars=0",false)
}


function buttonOver(btnObj){
btnObj.className=btnObj.className+"Hover"
}
function buttonOut(btnObj){

btnObj.className=btnObj.className.substr(0,btnObj.className.indexOf("Hover"))
}

function navBack()
{
if (arguments[0] != null){
        window.history.go(-arguments[0])
		//window.history.back();
		return;
		}
window.history.back();
}


function setStatus(msg){
window.status=msg
}
function Logout(path){
if (window!=top){
 window.parent.location.href=path+"logout.asp"
}
else
{
 window.location.href=path+"logout.asp"
}

}

function PopPage(Url,pName,pWidth,pHeight,modal){
    var OpenArgs='';
    if (arguments.length>5)
        OpenArgs=arguments[5]
    
	var pTop=(screen.availHeight -pHeight)/2
	var pLeft=(screen.availWidth  -pWidth)/2
	if (modal){
		if (window.showModalDialog){
		    return window.showModalDialog(Url,OpenArgs,"dialogWidth:"+pWidth/16+" ; dialogHeight:"+pHeight/16)
		}
		else {
		    window.open(Url,pName,"top="+pTop+",left="+pLeft+",toolbar=0,location=0,status=0,menubar=0,width="+pWidth+",height="+pHeight+",scrollbars=0,resizable=0")
		    return ;
		}
	}
	else
	{
	window.open(Url,pName,"top="+pTop+",left="+pLeft+",toolbar=0,location=0,status=0,menubar=0,width="+pWidth+",height="+pHeight+",scrollbars=0,resizable=1")
	return ;
	}
}

function OpenProblem(ID,newwindow){
    if (arguments.length>2)
        {
       var  e=arguments[2]
    e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
    }

if (newwindow)
	window.open("Problem.asp?TicketId="+ID,"DNAHD"+ID)
else
	window.location.href="Problem.asp?TicketId="+ID

}

function setMenuItem(ItemNo){
if (window.parent.frames){
	if (window.parent.frames[0]){
		if (window.parent.frames[0].SelectedStatusItem || window.parent.frames[0].SelectedStatusItem==0){
			window.parent.frames[0].SelectedMenuItem=ItemNo;
		}
	}
}

}

function SetStatusItem(StatusId){

if (window.parent.frames){
//if (window.parent.frames[0].SelectedStatusItem)
window.parent.frames[0].SelectedStatusItem=StatusId;
}
}



function FormatString(Msg){
	var ii=1
	
	for (ii=1;ii<FormatString.arguments.length;ii++){
		Msg=doReplace(Msg,FormatString.arguments[ii])
	}
	return Msg
}

function doReplace(strVal,RepVal){
  var r, re;
  re = /%j/i;
  r = strVal.replace(re, RepVal);
  return(r);
}

function FixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = FixEvent.preventDefault;
	event.stopPropagation = FixEvent.stopPropagation;
	return event;
};
FixEvent.preventDefault = function() {
	this.returnValue = false;
};
FixEvent.stopPropagation = function() {
  this.cancelBubble = true;
}

function sortlist(lb) {
sortOptions(lb)
}

function sortOptions(optionList){ 
var arrToSort = new Array(); 
for(i = 0; i < optionList.options.length; i++){ 
arrToSort[i] = new Array(); 
arrToSort[i][0] = optionList.options[i].text.toLowerCase(); 
arrToSort[i][1] = optionList.options[i]; 
} 

arrToSort.sort(); 

optionList.length = 0; 
for(i = 0; i < arrToSort.length; i++){ 
optionList.options.add(arrToSort[i][1]); 
} 
}


addEvent(window, 'load',setTitle);