// JavaScript Document
/*
matrix 0.1 - Bilderauswahl für Fontformate aus dropdown Menü
GP 2.3.2009
*/


// create a boolean variable to check for a valid IE instance
var xmlhttp = false;

// check if we are using IE
try {
	// if JS version > 5
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	//alert("You are using IE");
} catch (e) {
	// if not, then use older active x object
	try {
		// if we are usinf IE
		xmlhttp = newActiveXObject("Microsoft.XMLHTTP");
		//alert("You are using IE");
	} catch (e) {
		// else we must be using a non-IE browser
		xmlhttp = false;
	}
}

// if we are using a non-IE browser, create a JS instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
	//alert ("You are not using IE");
}


function getSelectedFormat(foundryID, filename) {
//	alert('hello, matrix.js');
//	alert('matrix');
	//var verzeichnis = <?php echo $verzeichnis ?>;
	//var foundryID = " . $foundryID . ";
	//var filename = \"" . $fontFilename . "\";
	var selectedFormat;
	var selectedImage;
	var imagePath;
	var format;
	
	//alert(document.cart_quantity.elements['id[]'].length);
//	alert(foundryID);
	
	for(i = 0; i < document.cart_quantity.elements['id[]'].length; ++i)
		if (document.cart_quantity.elements['id[]'].options[i].selected == true)
			//alert(document.cart_quantity.elements['id[]'].options[i].value);
			
	selectedFormat = document.cart_quantity.elements['id[]'].options[i].value;
	//alert(selectedFormat);
	if (selectedFormat == 5) {
		format = 'pcps';
	} else if (selectedFormat == 6) {
		format = 'macps';
	} else if (selectedFormat == 7) {
		format = 'ttf';
	} else if (selectedFormat == 8) {
		format = 'otf';
	}
	//alert('Format: ' + format);		
	
	// Bildpfad
	//selectedImageLow = 'images/matrix/' + foundryID + '/' + format + '/test.gif';
	//selectedImageLow = 'http://version2.fonts4ever.com/images/matrix/' + foundryID + '/' + format + '/' + filename + '_' + format + '_matrix_low.png';
	selectedImageLow = 'images/matrix/' + foundryID + '/' + format + '/' + filename + '_' + format + '_matrix_low.png';
	//selectedImageHigh = 'http://version2.fonts4ever.com/images/matrix/' + foundryID + '/' + format + '/' + filename + '_' + format + '_matrix_high.png';
//	alert('selectedImageLow: ' + selectedImageLow);
	//alert('selectedImageHigh: ' + selectedImageHigh);
	

	document.getElementById('products_details_page').innerHTML = '<img src=' + selectedImageLow + ' />';					
	//document.getElementById('products_details_page').innerHTML = '<img src=' + selectedImageLow + ' data-magnifysrc=' + selectedImageHigh + ' id='myimage' />';	
	
	if (selectedFormat == 8) {
		document.getElementById('product_details_heading').style.visibility = "visible";
	} else {
		document.getElementById('product_details_heading').style.visibility = "hidden";
	}
	
	// Mit AJAX
	/*
	//var newHTML = \"<img src='\" + selectedImageLow + \"' />\";
	//var newHTML = "<img src='" + selectedImageLow + "' data-magnifysrc='" + selectedImageHigh + "' id='myimage' />";
	//alert(newHTML);
	//document.getElementById('myimage').innerHTML = newHTML;
	
	//document.getElementById('products_details_page').innerHTML = newHTML;
	//alert('document: ' + document.getElementById('products_details_page').innerHTML);
	*/
	
	/*
	// with makerequest with ajax
	//var obj = document.getElementById('matrixbild');
	//xmlhttp.open("GET", newHTML);
	//xmlhttp.open("GET", 'product_info_image.php?lowimage='+selectedImageLow+'&highimage='+selectedImageHigh);
	xmlhttp.open("GET", 'product_info_heading.php');
	//xmlhttp.open("GET", 'product_info_image.php', true);
	xmlhttp.onreadystatechange = function() {
		//alert('responseText: ' + xmlhttp.responseText);
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			alert('load success');
			alert('responsetext: ' + xmlhttp.responseText);
			if (selectedFormat == 8) {
				document.getElementById('product_details_heading').style.color = "yellow";
				
				var heading = 'otf'
				//document.getElementById('product_details_heading').innerHTML = heading;
				document.getElementById('product_details_heading').innerHTML = xmlhttp.responseText;	
			}
		}
	}
	xmlhttp.send(null);
	*/
}

// check if Lupe and format = otf
function checkForMagnifier(productsID) {
	//alert('productsID: ' + productsID)
	for(i = 0; i < document.cart_quantity.elements['id[]'].length; ++i)
		if (document.cart_quantity.elements['id[]'].options[i].selected == true)
			//alert(document.cart_quantity.elements['id[]'].options[i].value);
			
	selectedFormat = document.cart_quantity.elements['id[]'].options[i].value;
	//alert(selectedFormat);
	if (selectedFormat == 5) {
		format = 'pcps';
		window.location.replace('http://version2.fonts4ever.com/product_info.php?detail_page=charset&products_id='+productsID+'&format=5');
		document.cart_quantity.elements['id[]'].options.value = 5;
		document.getElementById('product_details_heading').style.visibility = "hidden";
	} else if (selectedFormat == 6) {
		format = 'macps';
		window.location.replace('http://version2.fonts4ever.com/product_info.php?detail_page=charset&products_id='+productsID+'&format=6');
		document.cart_quantity.elements['id[]'].options.value = 6;
		document.getElementById('product_details_heading').style.visibility = "hidden";
	} else if (selectedFormat == 7) {
		format = 'ttf';
		window.location.replace('http://version2.fonts4ever.com/product_info.php?detail_page=charset&products_id='+productsID+'&format=7');
		document.cart_quantity.elements['id[]'].options.value = 7;
		document.getElementById('product_details_heading').style.visibility = "hidden";
	} else if (selectedFormat == 8) {
		format = 'otf';
	}
	//alert('Format: ' + format);	
}


function changeFormat(foundryID, filename) {
//	alert('hello, matrix.js');
	//var verzeichnis = <?php echo $verzeichnis ?>;
	//var foundryID = " . $foundryID . ";
	//var filename = \"" . $fontFilename . "\";
	var selectedFormat;
	var selectedImage;
	var imagePath;
	var format;
	
	//alert(document.cart_quantity.elements['id[]'].length);
	//alert(foundryID);
	
	for(i = 0; i < document.cart_quantity.elements['id[]'].length; ++i)
		if (document.cart_quantity.elements['id[]'].options[i].selected == true)
			//alert(document.cart_quantity.elements['id[]'].options[i].value);
			
	selectedFormat = document.cart_quantity.elements['id[]'].options[i].value;
	//alert(selectedFormat);
	if (selectedFormat == 5) {
		format = 'pcps';;
	} else if (selectedFormat == 6) {
		format = 'macps';
	} else if (selectedFormat == 7) {
		format = 'ttf';
	} else if (selectedFormat == 8) {
		format = 'otf';
	}
	//alert('Format: ' + format);		
	
	// Bildpfad
	selectedImageLow = 'images/matrix/' + foundryID + '/' + format + '/test.gif';
	//selectedImageLow = 'http://version2.fonts4ever.com/images/matrix/' + foundryID + '/' + format + '/' + filename + '_' + format + '_matrix_low.png';
	selectedImageHigh = 'http://version2.fonts4ever.com/images/matrix/' + foundryID + '/' + format + '/' + filename + '_' + format + '_matrix_high.png';
	//selectedImageHigh = \"http://version2.fonts4ever.com/images/matrix/\" + foundryID + \"/\" + format + \"/\" + filename + \"_\" + format + \"_matrix_high.png\";
	alert('selectedImageLow: ' + selectedImageLow);
	//alert('selectedImageHigh: ' + selectedImageHigh);
	

	//document.getElementById('products_details_page').innerHTML = '<img src=' + selectedImageLow + ' />';					
	//document.getElementById('products_details_page').innerHTML = '<img src=' + selectedImageLow + ' data-magnifysrc=' + selectedImageHigh + ' id='myimage' />';	
	
	var newHTML = "<img src='" + selectedImageLow + "' />";
	//var newHTML = "<img src='" + selectedImageLow + "' data-magnifysrc='" + selectedImageHigh + "' id='myimage' />";
	//alert(newHTML);
	//document.getElementById('myimage').innerHTML = newHTML;
	
	//document.getElementById('products_details_page').innerHTML = newHTML;
	//alert('document: ' + document.getElementById('products_details_page').innerHTML);
	
	
	
	// with makerequest with ajax
	//var obj = document.getElementById('matrixbild');
	//xmlhttp.open("GET", newHTML);
	//xmlhttp.open("GET", 'product_info_image.php?lowimage='+selectedImageLow+'&highimage='+selectedImageHigh);
	xmlhttp.open("GET", 'product_info_image.php?lowimage='+selectedImageLow);
	//xmlhttp.open("GET", 'product_info_image.php', true);
	xmlhttp.onreadystatechange = function() {
		//alert('responseText: ' + xmlhttp.responseText);
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//alert('load success');
			//alert('resonsetext: ' + xmlhttp.responseText);
			document.getElementById('products_details_page').innerHTML = xmlhttp.responseText;	// keine Lupe
			//document.getElementById('products_details_page').innerHTML = xmlhttp.evalResponse(responseText);	// kein neus bild
		}
	}
	xmlhttp.send(null);
	

	
	/*
	// programm auf server aufrufen
	xmlhttp.open("GET", 'product_info.php?eingabe='+newHTML);
	xmlhttp.onreadystatechange = receiveE;
	xmlhttp.send(null);
	*/
	
}

function hello() {
	alert('Hello');	
}

