/**
 *	=======================================================
 *
 * 	javascript_common.js
 *	@common javascript-functions
 *
 *	=======================================================
 */




/**
 * 	swap_it ( img_name , img_src )
 *	@img_name	name-tag of the image
 *	@img_src	src-value of the image (location)
 *	-------------------------------------------------------
 */

function swap_it(img_name, img_src) {

	document[img_name].src = img_src;

}



/**
 * 	popIt ( sPage , iWidth, iHeight )
 *	@sPage		page you want to open as a popup
 *	@iWidth		width of the popup
 *	@iHeight	height of the popup
 *
 *	note: popup will open with auto-scrollbars, located in the middle of the page
 *	-------------------------------------------------------
 */
 
function popIt ( sPage , iWidth , iHeight ) {

	var sPosX, sPosY;
	
	sPosX		= (screen.width / 2 ) - ( iWidth / 2 );
	sPosY		= (screen.height / 2 ) - ( iHeight / 2 );
	
	window.open(sPage, '', "toolbar=no, location=no, status=no, directories=no, menubar=no, resizable=no, top="+sPosY+", left="+sPosX+", width="+iWidth+", height="+iHeight+", scrollbars=auto");


} 
 
 
/**
 * 	pagePop ( sPage )
 *	@sPage		page you want to open as a popup
 *	
 *	note: popup will open with auto-scrollbars, located in the middle with a fixed width and height
 *	-------------------------------------------------------
 */
 
function pagePop ( sPage ) {
 	
 	var iHeight, iWidth, sPosX, sPosY;
 	
 	iHeight		= 400;
 	iWidth		= 250;
 	
 	sPosX		= ( screen.width / 2 ) - ( iWidth / 2 );
 	sPosY		= ( screen.height / 2 ) - ( iHeight / 2 );
 	
 	window.open(sPage, '', "toolbar=no, location=no, status=no, directories=no, menubar=no, resizable=no, top="+sPosY+", left="+sPosX+", width="+iWidth+", height="+iHeight+", scrollbars=no");
 
}



/**
 * 	checkForm ( aValues , aColour )
 *	@aValues	array with form-elements that need validation
 *	@aColour	array with colour (hexa) for labels
 *	
 *	note: we only check for a value, not a specific value
 *	-------------------------------------------------------
 */
 
function checkForm ( aValues , aColour ) {

	var iCount;
	var bStatus;
	bStatus		= true;
	
	for ( iCount in aValues ) {

		if ( document.getElementById('input' + aValues[iCount]).value == "" ) {
			
			document.getElementById('val' + aValues[iCount]).style.color		= aColour[0];
			bStatus		= false;
			
		} else {
		
			document.getElementById('val' + aValues[iCount]).style.color		= aColour[1];
		
		}
	
	}
	
	if ( bStatus == false ) 	return true;
	else				return false;

}


/**
 * 	checkEmail ( aValues , aColour , sForm )
 *	@aValues	array with form-elements that need validation
 *	@aColour	array with colour (hexa) for labels
 *	@sForm		id of the form (for submitting)
 *	
 *	note: we only check for a valid email-address
 *	-------------------------------------------------------
 */
 
function checkEmail ( aValues , aColour ) {
 	
  	var supported = 0;
  	if (window.RegExp) {
    		var tempStr = "a";
    		var tempReg = new RegExp(tempStr);
    		if (tempReg.test(tempStr)) 	supported = 1;
  	}

	var iCount;
	var bStatus;
	bStatus			= true;
	
	for ( iCount in aValues ) {
		
		var sEmail;
		sEmail		= document.getElementById('input' + aValues[iCount]).value;
		
		
		if ( !supported ) 	bStatus		= ( sEmail.indexOf(".") > 2 ) && ( sEmail.indexOf("@") > 0 );
		
  		var r1 		= new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  		var r2 		= new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");	
	
		bStatus		= ( !r1.test(sEmail) && r2.test(sEmail));
	
		if(bStatus == false) {
			document.getElementById('val' + aValues[iCount]).style.color		= aColour[0];
			bStatus		= false;
		} else {
			document.getElementById('val' + aValues[iCount]).style.color		= aColour[1];
		}
		
	}
	
	if ( bStatus == false ) 	return true;
	else				return false;

}