var receiveReq = getXmlHttpRequestObject();

function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		return new ActiveXObject('Microsoft.XMLHTTP');
	}
	else {
		document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' +	'Consider upgrading your browser.';	
	}
}

function getDropdown(state) {
	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
		//alert(state);
		//alert(document.getElementById('country').value);
		receiveReq.open('GET', 'ajax.php?action=dropdown&omraade_id='+document.getElementById('country').value+'&state_id='+state, true);
		receiveReq.onreadystatechange = handleReceiveDropdown; 
		receiveReq.send(null);
		
	}
}

function handleReceiveDropdown() {
	if (receiveReq.readyState == 4) {
		document.getElementById('usa_states').innerHTML = receiveReq.responseText;
	}
}
var receiveReq_cvrean = getXmlHttpRequestObject();

function getTjekCVR_EAN(country) {
	//alert(country);
	if (receiveReq_cvrean.readyState == 4 || receiveReq_cvrean.readyState == 0) {
		//alert(state);
		//alert(document.getElementById('country').value);
		receiveReq_cvrean.open('GET', 'ajax.php?action=cvr_ean&country_id='+country, true);
		receiveReq_cvrean.onreadystatechange = handleReceiveTjekCVR_EAN; 
		receiveReq_cvrean.send(null);
		
	}
}

function handleReceiveTjekCVR_EAN() {
	if (receiveReq_cvrean.readyState == 4) {
		var thing = receiveReq_cvrean.responseText;
		var split_array = thing.split(';');
		if (split_array[0] == 1) {
			document.getElementById('tr_cvr').style.visibility = 'visible';
			document.getElementById('tr_cvr').style.display = 'inline';
		}
		else {
			document.getElementById('tr_cvr').style.visibility = 'hidden';
			document.getElementById('tr_cvr').style.display = 'none';	
		}
		if (split_array[1] == 1) {
			document.getElementById('tr_ean').style.visibility = 'visible';
			document.getElementById('tr_ean').style.display = 'inline';
		}
		else {
			document.getElementById('tr_ean').style.visibility = 'hidden';
			document.getElementById('tr_ean').style.display = 'none';	
		}
		document.getElementById('cvr_text').innerHTML = split_array[2];
	}
}

function add_more_upload2() {
	if (document.getElementById('theFile['+document.form.TOTAL_FILE.value+']').value != "") {
		var new_total = Math.round(document.form.TOTAL_FILE.value) + 1;
		document.getElementById('attach_'+document.form.TOTAL_FILE.value).innerHTML = "<br /><input type='file' size='40' id='theFile["+new_total+"]'' name='theFile["+new_total+"]' /></div><div id='attach_"+new_total+"'>";
		document.form.TOTAL_FILE.value++;
		//alert(document.Uploader.TOTAL_FILE.value);
	}
}

function makeSure(txt) {
	var answer = confirm(txt);
	if (answer == true) {
		return true;
	} 
	else {
		return false;
	}
}

function changeLogo() {
	var logo = document.getElementById('toplogo');
	var logo_top = document.getElementById('toplogo').value;
	if(logo_top != 'random') {
		document.getElementById('showLogo').innerHTML = "<img src='../images/banners/"+logo.value+"' width='400'>";	
	}
	else {
		document.getElementById('showLogo').innerHTML = "";	
	}
}

function showFLV(filename, width, height) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="FLVPlayer">');
	document.write('<param name="movie" value="http://www.loligosystems.com/FLVPlayer_Progressive.swf">');
	document.write('<param name="salign" value="lt">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="scale" value="noscale">');
	document.write('<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=http://linux9.landit.dk/loligo/'+filename+'&autoPlay=true&autoRewind=true">');
	document.write('<embed src="FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=Clear_Skin_1&streamName=http://linux9.landit.dk/loligo/'+filename+'&autoPlay=true&autoRewind=true" quality="high" scale="noscale" width="'+width+'" height="'+height+'" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed>');
	document.write('</object>');
}
