﻿
/*Page Struture*/;



function NavigateTo(url){
window.location = url;
}

function SearchOnEnter(e)
{

     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     if(key == 13){
     
     
     var textField = $('ctl00_txtQuery');

     if(textField==null) return;
     if(Trim(textField.value)=='') return;
     
     
     
    var btn = $('ctl00_btnSearch');
    if (btn) btn.click();
     return false;
     
     }
}





function LimitField(field,maxlimit) {
    if (field.value.length > maxlimit) 
     field.value = field.value.substring(0, maxlimit);
}

var PageControler = {

    CurrentSelectedPage:0,
    SetSelectedPage:function(pageData){
    $("mi_" + pageData).className = "SelectedItem";
       // if(this.CurrentSelectedPage){
       //   this.UnSelectPage(this.CurrentSelectedPage);
        //}
        this.CurrentSelectedPage = pageData;
    },
    UnSelectPage:function(pageData){
    $("mi_" + pageData).className = "Item";
    }
   
}




/**
*
*  AJAX IFRAME METHOD (AIM)
*  http://www.webtoolkit.info/
*
**/

AIM = {

    frame : function(c) {
        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}




    var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




function ChangeImage(imageElem,newImage){
imageElem.src = newImage.src;
}

function AddtoFavorites(){

var BookmarkURL="http://www.ViaCactus.com";
var BookmarkTitle="Dojit";
 
// If the browser is Internet Explorer
if(BrowserDetect.browser=="Explorer")
{
        // Add to Favorites (Internet Explorer)
        window.external.AddFavorite(BookmarkURL,BookmarkTitle);
}
else if(BrowserDetect.browser=="Firefox")
{
        // Add to Bookmarks (Mozilla Firefox)
        window.sidebar.addPanel(BookmarkTitle, BookmarkURL, ''); 
}


}



  

function setHome()
{
   document.body.style.behavior='url(#default#homepage)';
   document.body.setHomePage(window.location.href);
}



function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}








function removeItems(array, item) {
var i = 0;
while (i < array.length) {
if (array[i] == item) {
array.splice(i, 1);
} else {
i++;
}
}
return array;
}

function containsItem(array,item) {
var i = 0;
while (i < array.length) {

if (array[i] == item) {
return true;
} 

i++;

}

return false;

}


  function Trim(str) {
   while (str.substring(0,1) == ' ') str = str.substring(1, str.length);
   while (str.substring(str.length-1, str.length) == ' ')str = str.substring(0,str.length-1);
   return str;
   }


function SelectItem(listBox, item) 
{

        for(index1 = 0 ; index1 < listBox.options.length; index1++){ 
          
            if(listBox.options[index1].value == item)
            {
            listBox.options[index1].selected=true;break; 
            }
        }
}

function DeleteValue(listBox, value) 
{

        for(index1 = 0 ; index1 < listBox.options.length; index1++){ 
      

            if(listBox.options[index1].value == value)
            {
            
            listBox.remove(index1);
            break;
            }
        }
}





 function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  

var viewportwidth;
 var viewportheight;
 
function GetViewPort(){
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


var severity =  {error:"error",info:"info",success:"success"};


function ApplyElemMessage(elem_name,msg,elem_class){
    var elem = $(elem_name);
    elem.innerHTML = msg;
    elem.className = elem_class;
}


       function ScrollFixBarPosition(){
       StatusBar.style.top = (viewportheight+getScrollXY()[1]-20) +"px";

       }
       

       
         function ShowMessage(message,msgSeverity,elemName){
         var elem = $(elemName);
         
            switch(msgSeverity){
                   
                   case severity.error :
                   elem.style.color = "red";
                   break;
                   
                   case severity.info :
                   elem.style.color = "black"; 
                   break;
                   
                   
                   case severity.success :
                   elem.style.color = "green"; 
                   break;
           
            }
           
            elem.innerHTML = message;
         }
         
        function StatusBarShowMessage(message,msgSeverity){
           
           switch(msgSeverity){
           
           case severity.error :
           StatusSpan.style.color = "red";
           break;
           
           case severity.info :
           StatusSpan.style.color = "black"; 
           break;
           
           }
           StatusSpan.innerHTML = message;
           StatusBar.fade(1);
           setTimeout(StatusBarFadeMessage ,6000);
       }
       
       function StatusBarFadeMessage(){
       StatusBar.fade(0);
       }
       
 
       
       
       
function GetDemmisonANumber(prop){

return parseInt(prop.substring(0,prop.length-2));


}

function GetToday(){
var today = new Date();
return (today.getFullYear() +"/"+ (today.getMonth()+1) +"/"+ today.getDate());
}


    
var CurrentEditor;
var itemEditor;
function ShowItemEditor(elementToDisplayId){

GetViewPort();
itemEditor = $('ItemEditor');
    if(document.body.clientWidth<viewportwidth){
    itemEditor.style.width = viewportwidth + "px";
    }else{
    itemEditor.style.width = document.body.clientWidth + "px";
    }
    
    if(document.body.clientHeight<viewportheight){
    itemEditor.style.height = viewportheight + "px";
    }
    else{
    itemEditor.style.height = document.body.clientHeight + "px";
    }
itemEditor.style.display = 'block';

elementToDisplay = $(elementToDisplayId);
var ScrollXY = getScrollXY();
elementToDisplay.style.left = (ScrollXY[0]  + ((viewportwidth -GetDemmisonANumber(elementToDisplay.style.width))/2))+"px";

if(viewportheight<GetDemmisonANumber(elementToDisplay.style.height)){
elementToDisplay.style.top = (ScrollXY[1] + 20)+"px";
}else{
elementToDisplay.style.top = (ScrollXY[1] + ((viewportheight -GetDemmisonANumber(elementToDisplay.style.height))/2))+"px";
}
elementToDisplay.style.display = 'block';
CurrentEditor = elementToDisplay;

if(GetDemmisonANumber(itemEditor.style.height)<GetDemmisonANumber(elementToDisplay.style.height)){
//alert((GetDemmisonANumber(elementToDisplay.style.height)+40)); 
itemEditor.style.height = (GetDemmisonANumber(elementToDisplay.style.height)+40)+"px";
}


}


function CloseItemEditor(){
    if(itemEditor){
        itemEditor.style.display = 'none';
        CurrentEditor.style.display = 'none';
    }
}

 
 function RequireConnection(){
     if(currentUserId==-1){ 
       window.location='Login.aspx';
     }
 }
 
function PrintPage(pageURL){                                            
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(pageURL, windowName, 'left=50000,top=50000,width=0,height=0');
  
}






function GetUrlParam( name ){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
  var regexS = "[\\?&]"+name+"=([^&#]*)";  
  var regex = new RegExp( regexS );  
  var results = regex.exec( window.location.href );  
  if( results == null )    return "";  
  else   
  return results[1];
  }
