//alert('xxx');
function toggleClass(eId) {

	curClass = document.getElementById(eId).className;

	baseName = ""; //className uden Show eller Hide

	if (curClass.lastIndexOf("Hide") > -1) {

		arrClassName = curClass.split("Hide");

		postfix = "Show";

	} else if (curClass.lastIndexOf("Show") > -1) {

		arrClassName = curClass.split("Show");

		postfix = "Hide";

	}

	baseName = arrClassName[0];

	className =  baseName + postfix

	document.getElementById(eId).className = className;

	return className;

}


function toggleElementClass(argObj)
{
	curClass = argObj.className;
	if (curClass.lastIndexOf("Hide") > -1)
	{
		newClassName = curClass.replace("Hide","Show");
	}
	else if (curClass.lastIndexOf("Show") > -1)
	{
		newClassName = curClass.replace("Show","Hide");
	}

	argObj.className = newClassName;
}

function bottomShowMoreTopics(argElement)
{
	var objParent = argElement.parentNode.parentNode
	toggleElementClass(objParent.getElementsByTagName('ul')[1])
	toggleElementClass(objParent.getElementsByTagName('ul')[2])
}


function ShowFuldTxt(argElement)
{
	var objParent = argElement.parentNode.parentNode
	toggleElementClass(objParent.getElementsByTagName('ul')[0])
	toggleElementClass(objParent.getElementsByTagName('ul')[1])
	toggleElementClass(objParent.getElementsByTagName('ul')[2])
}

function ShowFuldTxtReport(argElement)
{
	var objParent = argElement.parentNode.parentNode
	toggleElementClass(objParent.getElementsByTagName('ul')[0])
	toggleElementClass(objParent.getElementsByTagName('ul')[1])
	toggleElementClass(objParent.getElementsByTagName('ul')[2])
	toggleElementClass(objParent.getElementsByTagName('ul')[3])
}


//xxxDenne funktion er kun midlertidig - til HTML-dummyen!
function shiftFpListImg(argInt)
{
	var strImgSrc = document.getElementById('fastBook' + argInt).src
	var temp1 = strImgSrc.split('fastBook')
	var intNow = temp1[1].substring(0,1)
	if(intNow == 3)
	{
		intNew = 1
	}
	else
	{
		intNew = intNow*1 + 1
	}

	document.getElementById('fastBook' + argInt).src = "/img/fastBook" + intNew + ".jpg";
}

function focusForm()
{
	document.getElementById('test').className = 'memberInput2';
	document.getElementById('test2').className = 'memberInput3';
	document.getElementById('memberPassID1').className = 'memberPass2';
	document.getElementById('memberPassID2').className = 'memberPass2';
	document.formMember.password1.focus();

}

function printOrderOverview(argID)
{
	w = 600;
	h = 450;
	wh = "width=" + w + ", height=" + h;
	center = ", "+ getCenterWindowString(w, h);
	features = wh + center + ', scrollbars=yes, status=yes, resizable=yes';
	win = window.open("/betal/printorderoversigt/" + argID, "orderoverview", features);
	win.focus();
}

function getCenterWindowString(argW, argH)
{

	if (document.all || document.layers)
	{
	   w = screen.availWidth;
	   h = screen.availHeight;
	}
	else
	{
		w = window.screen.availWidth;
		h = window.screen.availHeight;
	}
	var topPos = Math.floor((h-argH)/2);
	var leftPos = Math.floor((w-argW)/2);

	return 'top='+ topPos + ', left=' + leftPos;
}

function changeFastView(argCategory)
{
	elms = document.getElementById('fastviewContent').getElementsByTagName('span');
	for (var i=0, node; node = elms[i++];)
	{
		node.className = 'elementHide';
	}

	if (argCategory && document.getElementById('fastview_' + argCategory))
		document.getElementById('fastview_' + argCategory).className = 'elementShow';

	elms = document.getElementById('fastName').getElementsByTagName('a');
	for (var i=0, node; node = elms[i++];)
	{
		node.className = '';
	}
	if (argCategory && document.getElementById('fastviewselector_' + argCategory))
		document.getElementById('fastviewselector_' + argCategory).className = 'selected';
}

function clearInputField(argInputElm, argDefaultContent)
{
	if (argInputElm.value == argDefaultContent)
		argInputElm.value = '';
}

/**
 * For making page requests from Javascript
 */
function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
//			alert('HTTP error ' + req.status);
			return;
		}
		if(null != callback)
		{
			callback(req);
		}
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}



function getLeadingHtml (input, maxChars) {
	// token matches a word, tag, or special character
	var	token = /\w+|[^\w<]|<(\/)?(\w+)[^>]*(\/)?>|</g,
		selfClosingTag = /^(?:[hb]r|img)$/i,
		output = "",
		charCount = 0,
		openTags = [],
		match;

	// Set the default for the max number of characters
	// (only counts characters outside of HTML tags)
	maxChars = maxChars || 250;

	while ((charCount < maxChars) && (match = token.exec(input))) {
		// If this is an HTML tag
		if (match[2]) {
			output += match[0];
			// If this is not a self-closing tag
			if (!(match[3] || selfClosingTag.test(match[2]))) {
				// If this is a closing tag
				if (match[1]) openTags.pop();
				else openTags.push(match[2]);
			}
		} else {
			charCount += match[0].length;
			if (charCount <= maxChars) output += match[0];
		}
	}

	// Close any tags which were left open
	var i = openTags.length;
	while (i--) output += "</" + openTags[i] + ">";

	return output;
};

function makeTeaser(argIdTextBox,argMaxChars)
{
	var text = document.getElementById(argIdTextBox).innerHTML
	document.getElementById(argIdTextBox).innerHTML = getLeadingHtml (text, argMaxChars) ;
}

/*
function memberSignupTermsToggle()
{
	toggleClass('memberSignupTerms');
//	parent.document.getElementById('page').style.display='none';
	parent.document.getElementById('fbContent').height='540px';
	document.getElementById('signUpTerms').style.display='none';
	parent.document.getElementById('fbBox').style.height='540px';
	parent.document.getElementById('fbMainDiv').style.height='540px';
}
*/

function memberSignupTermsToggle(argMode)
{
	//alert(parent.document.getElementById('fbContent').height);
	currentHeight = parent.document.getElementById('fbContent').height;
	
	/* remove "px" if present */
	if( currentHeight.search("px") != -1)
	{
		//alert("gggg"+currentHeight.substr(0,currentHeight.length-2));
		currentHeight = parseInt(currentHeight.substr(0,currentHeight.length-2));
	}

	/*toggle class of terms area*/
	toggleClass('memberSignupTerms');

	/*change height*/
	if (document.getElementById('memberSignupTerms').className == 'elementHide')
	{
		linkTest = 'Lęs betingelser';
		h = parseInt(currentHeight) - 110;
	}
	else
	{
		linkTest = 'Luk';
		if (argMode && argMode == 'sale'){
			h = parseInt(currentHeight) + 110;
		}else{
			h = parseInt(currentHeight) + 110;
		}
	}
	parent.document.getElementById('fbContent').height = h+'px';
	document.getElementById('signUpTerms').innerHTML = linkTest;
	parent.document.getElementById('fbBox').style.height = h+'px';
	parent.document.getElementById('fbMainDiv').style.height = h+'px';
}

function changeOverLayHeight(argIntHeight)
{
	parent.document.getElementById('fbContent').height=argIntHeight+'px';
	parent.document.getElementById('fbBox').style.height=argIntHeight+'px';
	parent.document.getElementById('fbMainDiv').style.height=argIntHeight+'px';

}

function writeHTML(a)
{
	document.write(a)
}

