/**
   +----------------------------------------------------------------------+
   | InternetServices                	            	    			  |
   +----------------------------------------------------------------------+
   | Copyright (c) 2000-2003 IT-va B.V. All Rights Reserved.              |
   +----------------------------------------------------------------------+
   | This software is the confidential and proprietary information of 	  |
   | IT-va B.V. ("Confidential Information").		            		  |
   | You shall not disclose such Confidential Information and shall use   |
   | it only in accordance with the terms of the license agreement you    |
   | entered into with IT-va B.V.					                      |
   |									                                  |
   | SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO    |
   | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  |
   | PURPOSE, OR NON-INFRINGEMENT. IT-va B.V. SHALL NOT BE LIABLE FOR ANY |
   | DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR	  |
   | DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.			              |
   +----------------------------------------------------------------------+
   |  IT-va B.V.							                              |
   |  Zekeringstraat 50						                        	  |
   |  1014 BT  Amsterdam						                          |
   |  The Netherlands						                        	  |
   |  http://www.itva.nl					                        	  |
   +----------------------------------------------------------------------+
*/
// $Id: common.js,v 1.17 2005/01/17 11:17:07 sachat Exp $

/**
 * Common JavaScript functions
 * @version $Revision: 1.17 $
 */


/**
 * Opens new report
 *
 * @param   pageid   the pageid for the report
 * @return  void
 */
function openReport(pageid) {
	document.frm_report.page.value = pageid;
	document.frm_report.submit();
} // End function


/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }

    var row_cells_cnt = theRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;
    }

    return true;
} // End function


/**
 * Switches header orientation between normal and horizontal rotated
 *
 * @return  void
 */
function switch_orientation_header(table) {
	var obj = document.getElementById([table]);
	var head = obj.tHead;
	var style_normal = "ListCellHeader";
	var style_rotated = "ListCellHeader_Rotated";

	var r = head.rows.length;
    for (var j = 0; j < r; j++) {
    	var cells = head.rows[j].cells;
    	var l = cells.length;

    	for (var i = 0; i < l; i++) {
    		c = cells[i];
    		s = c.className;

    		if (s == style_normal)
    			c.className=style_rotated;

    		if (s == style_rotated)
    			c.className=style_normal;
    	} // End for
    }// End for
} // End function


/**
 * Adds classname to table for sorting
 *
 * @return  void
 */
function addClassName(el, sClassName) {
	var s = el.className;
	var p = s.split(" ");
	var l = p.length;
	for (var i = 0; i < l; i++) {
		if (p[i] == sClassName)
			return;
	}
	p[p.length] = sClassName;
	el.className = p.join(" ");
} // End function


/**
 * Removes classname from table for sorting
 *
 * @return  void
 */
function removeClassName(el, sClassName) {
	var s = el.className;
	var p = s.split(" ");
	var np = [];
	var l = p.length;
	var j = 0;
	for (var i = 0; i < l; i++) {
		if (p[i] != sClassName)
			np[j++] = p[i];
	}
	el.className = np.join(" ");
} // End function





/**
 * Launches a new window
 *
 * @return  void
 */
var newwin;
function launchwin(winurl,winname,winfeatures) {
	newwin = window.open([winurl],[winname],[winfeatures]);
	if (newwin.focus) {
		setTimeout('newwin.focus();',1000);
	}
} // End function


/**
 * Opens new window displaying relation information
 *
 * @return  void
 */
function openInfoWindow(url) {
	winHeight = 320;
	winWidth = 390;

	topPos = (screen.availHeight - winHeight) / 2 - 24;
	leftPos = (screen.availWidth - winWidth) / 2;

	strFeatures = "height=" + winHeight;
	strFeatures += ", width=" + winWidth;
	strFeatures += ", scrollbars=yes";
	strFeatures += ", left=" + leftPos;
	strFeatures += ", top=" + topPos;
	strFeatures += ", status=no";
	strFeatures += ", resizable=no";
	strFeatures += ", lokation=no";
	strFeatures += ", menubar=no";
	strFeatures += ", toolbar=no";
	launchwin(url, 'relationInfo', strFeatures);
} // End function


/**
 * Adds a bookmark to the clients browser
 *
 * @return  void
 */
function AddBookmark() {
	if (document.all) window.external.AddFavorite('http://www.kalshoven.nl/demo/', 'madHouse onroerend goed');
} // End function


/**
 * Displays the current page in a new window for printing purposes.
 *
 * @return  void
 */
function PrintPage(page) {
	launchwin(page, 'Print', 'width=600,height=450,scrollbars=yes');
} // End function


/**
 * Opens new window displaying a tenant file
 *
 * @return  void
 */
function openTenantFile(url) {
	winHeight = 600;
	winWidth = 640;

	topPos = (screen.availHeight - winHeight) / 2 - 24;
	leftPos = (screen.availWidth - winWidth) / 2;

	strFeatures = "height=" + winHeight;
	strFeatures += ", width=" + winWidth;
	strFeatures += ", scrollbars=yes";
	strFeatures += ", left=" + leftPos;
	strFeatures += ", top=" + topPos;
	strFeatures += ", status=no";
	strFeatures += ", resizable=no";
	strFeatures += ", lokation=no";
	strFeatures += ", menubar=no";
	strFeatures += ", toolbar=yes";
	launchwin(url, 'tenant_file', strFeatures);
} // End function

// ************************
// * window function for tenant *
// ************************
function newCall(page) {
	launchwin(page, 'newCall', 'height=390,width=390,scrollbars=no,screeny=130,screenx=165,left=130,top=165');
}


/**
 * Opens new window for selecting a relation
 *
 * @return  void
 */
function openSelectWindow(url) {
	winHeight = 400;
	winWidth = 410;

	topPos = (screen.availHeight - winHeight) / 2 - 24;
	leftPos = (screen.availWidth - winWidth) / 2;

	strFeatures = "height=" + winHeight;
	strFeatures += ", width=" + winWidth;
	strFeatures += ", scrollbars=yes";
	strFeatures += ", left=" + leftPos;
	strFeatures += ", top=" + topPos;
	strFeatures += ", status=no";
	strFeatures += ", resizable=no";
	strFeatures += ", lokation=no";
	strFeatures += ", menubar=no";
	strFeatures += ", toolbar=no";
	launchwin(url, 'relationInfo', strFeatures);
} // End function



/**
 * Launches a window to show the decoded password
 *
 * @param   url   the url for the processor
 * @return  void
 */
function openDecodePasswordWindow(url){
	winHeight = 170;
	winWidth = 622;

	topPos = (screen.availHeight - winHeight) / 2 - 24;
	leftPos = (screen.availWidth - winWidth) / 2;

	strFeatures = "dependent=no"
	strFeatures += ", toolbar=no";
	strFeatures += ", menubar=no";
	strFeatures += ", location=no";
	strFeatures += ", height=" + winHeight;
	strFeatures += ", width=" + winWidth;
	strFeatures += ", scrollbars=no";
	strFeatures += ", left=" + leftPos;
	strFeatures += ", top=" + topPos;
	strFeatures += ", status=no";
	strFeatures += ", resizable=no";
	launchwin(url, 'PasswordInformation', strFeatures);
} // End function




// ************************
// * Standard function    *
// ************************
function submitForm(n,d) {
//------------------------------------------------------------------------------------------------------------------
// Description:	 Deze functie zoekt aan de hand van ingevoerde veld naam het desbetreffende form object op
//		 welke in het document staat. Hetgeen wat kan worden ingevoerd is
//		 'objectName'
// Created by:   Mark Neeleman
// Date Created: 04/12/2003
//------------------------------------------------------------------------------------------------------------------
var i,x;
	if(!d) d=document;
	// Doorzoek de formulieren!
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	d.forms[i-1].submit();
} //End Function

// ************************
// * Common functions	  *
// ************************
function showDatePicker(page) {
	launchwin(page, 'datePicker', 'height=160,width=168,lokation=no,resizable=no,menubar=no,toolbar=no,scrollbars=no,screeny=130,screenx=165,left=130,top=165');
}

// ************************
// * Lokatie functions	  *
// ************************
function showLokatie(page) {
	launchwin(page, 'Lokatie', 'height=360,width=650,lokation=no,resizable=no,menubar=no,toolbar=no,scrollbars=no,screeny=130,screenx=165,left=130,top=165');
}


/**
 * Get variable in query string
 * @param string variable is a query string variable
 * @return string query string variable value
 */
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
    return false;
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

