//By: Dexter Zafra www.ex-designz.net

//Handle popup window
function Start(page) 
{
OpenWin = this.open(page,'CtrlWindow', 'width=650,height=500,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes')
}
function openWindow(url) 
{
  popupWin = window.open(url,'new_page','width=400,height=400')
}

//Handle clear field
function clearDefault(el) 
{
  if (el.defaultValue==el.value) el.value = ""
}

//Handle textarea comment and URL description character count 
function textCounter(field, countfield, maxlimit) 
  {
     if (field.value.length > maxlimit) 
         field.value = field.value.substring(0, maxlimit);
     else 
         countfield.value = maxlimit - field.value.length;
}

//Handle ckeck keyword for search
function doSubmit(obj) 
 {

   if (obj.find.value != '' && obj.find.value != 'Enter keyword') 
       {
          var keywords = obj.find.value.split(' ');
          var validKeyword = 0;

             for(key in keywords) 
                  {
	        keyword = keywords[key];
	        keyword = keyword.replace(/^\\s+|\\s+$/g,'');

	            if (keyword.length >= 3) 
                              {
		        validKeyword += 1;
		     }
	     }
			
                        if (validKeyword <= 0) 
                             {
		       alert('Your keywords used must contain at least 3 characters!\n\nPlease try again...');
		       return false;
		    } 
                              else 
                              {
		       return true;
		    }

      } 
      else 
      {
         alert('You must enter at least ONE keyword!\n\nPlease try again...');
          return false;
      }
}

//Handle right panel toggle hide/show
function togswitch(idnum)
{
   if(document.getElementById)
      {
          if(document.getElementById("togdiv"+idnum))
             {
	   var elem = document.getElementById("togdiv"+idnum);
	   
	      if(elem == null) 
                      { 
                        return; 
                      }
			
                   if(elem.style.display == "none")		
                      {
	            elem.style.display = "block";

	            if(document.getElementById("togplus"+idnum))
                            {
                              document.getElementById("togplus"+idnum).style.display = "none";
                            }

	            if(document.getElementById("togminus"+idnum))
                            {
                              document.getElementById("togminus"+idnum).style.display = "";
                            }
			
                }
	      else
	   {
	          elem.style.display = "none";

                       if(document.getElementById("togplus"+idnum))
                           {
                             document.getElementById("togplus"+idnum).style.display = "";
                           }
                       if(document.getElementById("togminus"+idnum))
                           {
                             document.getElementById("togminus"+idnum).style.display = "none";
                           }
	    }

            }		
             window.event.cancelBubble = true;
	return false;
     }

}

var panes = new Array();

function setupPanes(containerId, defaultTabId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible
  
    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;    
}


function selectLink(activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible
  
    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con] != null) { // tab and pane are members of this container
    //  var pane = document.getElementById(paneId);
    //  pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
    //  for (var i in panes[con]) {
    //    var pane = panes[con][i];
    //    if (pane == undefined) continue;
    //    if (pane.id == paneId) continue;
    //    pane.style.display = "none"
     // }
    }
  }
  return false;    
}


function highlightCurrentLink(activeLink) {

  activeLink.blur();
  activeLink.className = "actived";
 
  var nav = document.getElementById("navigation");

  //alert ("currentLocation" + currentLocation);
  links = nav.getElementsByTagName("a");
  
  for (i=0; i<links.length; i++) {
        var tab = links[i];
        if (tab != activeLink) tab.className = "tab-disabled";
  }

    
}



function turnBackBold (speclink) {
	 var anchors = document.links;
	 for (i=0; i<anchors.length; i++) {
       anchors[i].style.fontWeight = '300';
        anchors[i].style.background = ''; 
    }
	 speclink.style.fontWeight = '900';
	 speclink.style.background = '#c3ebf9';
}

function turnBackBold2 (speclink, colors) {
	 
	 //speclink.style.background = '#c3ebf9';
	 
	 document.getElementById(speclink).style.background = '#c3ebf9';
}



function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function Void(d) {
if(document.getElementById(d).style.display == "none") 
{ document.getElementById(d).style.display = "block";
     
 }
else { document.getElementById(d).style.display = "none"; }
}


function addClass( el, c )
{
    var re = new RegExp('\b' + c + '\b');
    if ( el.className && !re.test( el.className ) ){
    el.className += ' ' + c;
    }
}

function handlelink(aobject){
    selectedtablink=aobject.href
    tcischecked=(document.tabcontrol && document.tabcontrol.tabcheck.checked)? true : false
    if (document.getElementById && !tcischecked){
    var tabobj=document.getElementById("meuderived")
    var tabobjlinks=tabobj.getElementsByTagName("LI")
    for (i=0; i<tabobjlinks.length; i++)
    tabobjlinks[i].className=""
    aobject.className="active"
    return false
}
else
return true
}

function handlelink2(aobject){
selectedtablink=aobject.href
tcischecked=(document.tabcontrol && document.tabcontrol.tabcheck.checked)? true : false
if (document.getElementById && !tcischecked){
var tabobj=document.getElementById("meuderived")
var tabobjlinks=tabobj.getElementsByTagName("LI")
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className=""
return false
}
else
return true
}



function doSwap(d) {
//c == 'vis' ? c = 'invis' : c = 'vis';
var ids = new Array('togdiv1', 'divPK');
for (var i=0; i<ids.length; i++) {
if (document.getElementById(ids[i]).id == d)
{
	if (document.getElementById(ids[i]).style.display == "block")
	{
		document.getElementById(ids[i]).style.display == "none";
	}
	else
	{
		document.getElementById(ids[i]).style.display = 'block';
	}
}
else
{
	document.getElementById(ids[i]).style.display = 'none';
}
}
}

function SelectAllCheckboxes(spanChk){

   // Added as ASPX uses SPAN for checkbox
   var oItem = spanChk.children;
   var theBox= (spanChk.type=="checkbox") ? 
        spanChk : spanChk.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;

   for(i=0;i<elm.length;i++)
     if(elm[i].type=="checkbox" && 
              elm[i].id!=theBox.id)
     {
       //elm[i].click();
       if(elm[i].checked!=xState)
         elm[i].click();
       //elm[i].checked=xState;
     }
 }
 
 function changeColor(obj) 

{       

    var rowObject = getParentRow(obj); 
    var parentTable = document.getElementById("Gridview1");   
    var color;
    if(color == '') 
    {
        color =  getRowColor();      
    }    
    if(obj.checked) 
    {              
        rowObject.style.backgroundColor = '#c3ebf9';            
    }
    else 
    {
       rowObject.style.backgroundColor = '#fdfbe7'; 
        color = '';                 
    }
    // private method

    function getRowColor() 

    {
        if(rowObject.style.backgroundColor == '') return parentTable.style.backgroundColor; 
        else return rowObject.style.backgroundColor; 

    }

}


// This method returns the parent row of the object

function getParentRow(obj) 

{ 
    do 
    {
        if(isFireFox()) 
        {
            obj = obj.parentNode; 
        }
        else {
        obj = obj.parentElement; 
        }
    }
    while(obj.tagName != "TR") 
   return obj;   
}

function isFireFox() 
{
    return navigator.appName == "Netscape"; 
}


var oldgridSelectedColor;

function setMouseOverColor(element)
{
    oldgridSelectedColor = element.style.backgroundColor;
    element.style.backgroundColor='#d9f1f9';
    element.style.cursor='pointer';
    //element.style.textDecoration='underline';
}

function setMouseOutColor(element)
{
    element.style.backgroundColor=oldgridSelectedColor;
    element.style.textDecoration='none';
}

var oldgridSelectedColor2;

function setMouseOverColor2(element)
{
    oldgridSelectedColor2 = element.style.backgroundColor;
    element.style.backgroundColor='#3a4a6e';
    element.style.cursor='pointer';
    element.style.textDecoration='underline';
    element.style.color = '#FFF';
}

function setMouseOutColor2(element)
{
    element.style.backgroundColor=oldgridSelectedColor2;
    element.style.textDecoration='none';
    element.style.color = '#000';
}

function ColorRow(CheckBoxObj)
{   
    if (CheckBoxObj.checked == true) {
    CheckBoxObj.parentElement.parentElement.style.backgroundColor='#88AAFF';
    }
    else
    {
    CheckBoxObj.parentElement.parentElement.style.backgroundColor='#FFFFFF';
    }
}
 
function HighlightSelected(colorcheckboxselected)
{ 
    if (colorcheckboxselected.checked) colorcheckboxselected.parentElement.parentElement.style.backgroundColor='#FFAA63';
    
 }

function SelectRow()
{
    		var obj = window.event.srcElement;
    		if(obj.tagName=="INPUT")    //this is a checkbox
    		{
    		    checkRowOfObject(obj);
    		}
    		else if (obj.tagName=="TD") //this a table cell
    		{
    		    //get a pointer to the tablerow
    		    var row = obj.parentNode;
    		    var chk = row.cells[0].firstChild;
    		    chk.checked = !chk.checked;
    		    if (chk.checked)
    		    {
    		        row.style.backgroundColor = '#c3ebf9';  
    		        oldgridSelectedColor = '#c3ebf9'; 
    		    }
    		    else
    		    {
    		       row.style.backgroundColor = '#fdfbe7'; 
    		       oldgridSelectedColor = '#fdfbe7';   
    		    }
    		}
}

function checkRowOfObject(obj)
    	{
    	    if (obj.checked)
		    {
		        obj.parentNode.parentNode.style.backgroundColor = '#c3ebf9'; 
		        oldgridSelectedColor = '#c3ebf9';   
		    }
		    else
		    {
		       obj.parentNode.parentNode.className="#fdfbe7";
		       oldgridSelectedColor = '#fdfbe7';  
		    }
    	}

function SelectRow2()
{
    		var obj = window.event.srcElement;
    		if(obj.tagName=="INPUT")    //this is a checkbox
    		{
    		    checkRowOfObject2(obj);
    		}
    		else if (obj.tagName=="TD") //this a table cell
    		{
    		    //get a pointer to the tablerow
    		    var row = obj.parentNode;
    		    var chk = row.cells[0].firstChild;
    		    chk.checked = !chk.checked;
    		    if (chk.checked)
    		    {
    		        row.style.backgroundColor = '#c3ebf9';  
    		        oldgridSelectedColor = '#c3ebf9'; 
    		    }
    		    else
    		    {
    		       row.style.backgroundColor = '#FFF'; 
    		       oldgridSelectedColor = '#FFF';   
    		    }
    		}
}

function checkRowOfObject2(obj)
    	{
    	    if (obj.checked)
		    {
		        obj.parentNode.parentNode.style.backgroundColor = '#c3ebf9'; 
		        oldgridSelectedColor = '#c3ebf9';   
		    }
		    else
		    {
		       obj.parentNode.parentNode.className="#FFF";
		       oldgridSelectedColor = '#FFF';  
		    }
    	}
    	
function openIFrame(IFrameID, id)
{
    ifId=gmobj('showPage');
    ifId.location.href='welcome.aspx'; // Opera Bug Fix. ifId.src=URL
}

function showMessage(id)
{
    myMessage.location.href = id;
}

function showMessage3(id)
{
    self.location.href = id;
}

function showMessage2(id)
{
    var ids = id;
    //frames['showPage'].location.href=id;
    Windows.location.href=id;
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) 
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}


