var xmlHttp = false;

function en(form,callingField)
{
	top.location.href=form.till.options[form.till.selectedIndex].value
} 

function active(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {oldonload();func();}
	}
}

function detail(id,index,page) {
	var searchType		=	document.getElementById('searchType').value; 
	var searchText		=	document.getElementById('searchText').value; 
	var countryCode		=	document.getElementById('countryCode').value; 	
	
	var setGroup		=	document.getElementById('setGroup').value; 
	var setTranslation 	=	document.getElementById('setTranslation').value; 
	var setPicture	 	=	document.getElementById('setPicture').value; 	
	
	var pageNow		=	document.getElementById('pageNow').value; 	
	var pageView	=	document.getElementById('pageView').value; 
	var pageImg		=	document.getElementById('pageImg').value;
	if(searchText != "") 
	{	
		document.getElementById(id).style.display  = ""; 
		var req = new Array(1+'detail');
		req[index]	= window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
		if (searchType='avancerad') {
			req[index].open('GET', "/includes/search.inc.php?countryCode="+countryCode+"&searchType="+searchType+"&setPicture="+setPicture+"&search="+encodeURIComponent(searchText)+"&setGroup="+setGroup+"&setTranslation="+setTranslation+"&page="+page+"&pageView="+pageView,true);			
		} else {
			req[index].open('GET', "/includes/search.inc.php?countryCode="+countryCode+"&searchType="+searchType+"&search="+encodeURIComponent(searchText)+"page="+page+"&pageView="+pageView,true);
		}
		req[index].onreadystatechange = function() {
		if (req[index].readyState == 1) {
			document.getElementById('loadbar').style.display  = ""; 
			} else if (req[index].readyState == 4 && req[index].status == 200) {
				document.getElementById('loadbar').style.display  = "none"; 
				document.getElementById('pageNow').value = page;
				document.getElementById(id).innerHTML = req[index].responseText;
				document.getElementById('page'+pageView).className="enable";			
			} else if (req[index].readyState == 4 && req[index].status == 404) {	
				alert('404 Error');
			}
		}
		req[index].send(null);
	} else {
		document.getElementById('video').style.display  = "none"; 
		document.getElementById(id).style.display  = "none"; 
	}
}

function display(index,id) {	
	scroll(0,0);
	document.getElementById('video').style.display  = ""; 
	var countryCode		=	document.getElementById('countryCode').value; 	
	var req = new Array(1+'display');
	req[index]	= window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
	req[index].open('GET', "/includes/display.inc.php?countryCode="+countryCode+"&key="+id,true);
	req[index].onreadystatechange = function() {
	if (req[index].readyState == 1) {
//			document.getElementById('loadbar').style.display  = ""; 
//			document.getElementById("loadbar").innerHTML = '<img src="http://pro.spreadthesign.com/images/icons/ajax.gif" />';
		} else if (req[index].readyState == 4 && req[index].status == 200) {
//			document.getElementById('loadbar').style.display  = "none"; 
			document.getElementById('video').innerHTML = req[index].responseText;
		} else if (req[index].readyState == 4 && req[index].status == 404) {
			alert('404 Error');
		}
	}
	req[index].send(null);
}

function changePageView(page) {
	var pageNow	= document.getElementById('pageNow').value; 
	var pageView	= document.getElementById('pageView').value; 	
	document.getElementById('page'+pageView).className="disable";	
	document.getElementById('pageView').value = page;
	detail(1,1,1);
}

function changeGroup(id,name) {
	var pageNow	= document.getElementById('pageNow').value; 
	document.getElementById('setGroup').value = id;	
	if (id==0) {
		document.getElementById('Group').style.background = '#fe7901';
		document.getElementById('Group').style.borderColor = '#fe9230';	
	} else {
		document.getElementById('Group').style.background = '#ff0000';
		document.getElementById('Group').style.borderColor = '#df0000';			
	}
	document.getElementById('Group').innerHTML = name;	
	detail(1,1,pageNow);	
}

function changeTranslation(id,name) {
	var pageNow	= document.getElementById('pageNow').value; 
	document.getElementById('setTranslation').value = id;
	if (id==0) {
		document.getElementById('Translation').style.background = '#fe7901';
		document.getElementById('Translation').style.borderColor = '#fe9230';			
	} else {
		document.getElementById('Translation').style.background = '#ff0000';
		document.getElementById('Translation').style.borderColor = '#df0000';	
	}
	document.getElementById('Translation').innerHTML = name;
	detail(1,1,pageNow);	
}

function changePicture(id,name) {
	var pageNow	= document.getElementById('pageNow').value; 
	document.getElementById('setPicture').value = id;
	if (id==0) {
		document.getElementById('Picture').style.background = '#fe7901';
		document.getElementById('Picture').style.borderColor = '#fe9230';			
	} else {
		document.getElementById('Picture').style.background = '#ff0000';
		document.getElementById('Picture').style.borderColor = '#df0000';	
	}
	document.getElementById('Picture').innerHTML = name;
	detail(1,1,pageNow);	
}


$(document).ready(function() {
	$('#avanceradbox').hide();
	$('a#avancerad').click(function() {
		var pageNow		=	document.getElementById('pageNow').value; 										
		document.getElementById('searchType').value = "avancerad";
		document.getElementById('normal').className="disable";	
		document.getElementById('avancerad').className="enable";			
		$('#avanceradbox').slideToggle(400);
		detail(1,1,pageNow);
		return false;
	});	
	$('a#normal').click(function() {
		document.getElementById('Group').style.background = '#fe7901';
		document.getElementById('Group').style.borderColor = '#fe9230';									 
		document.getElementById('Picture').style.background = '#fe7901';
		document.getElementById('Picture').style.borderColor = '#fe9230';		
		document.getElementById('Translation').style.background = '#fe7901';
		document.getElementById('Translation').style.borderColor = '#fe9230';		
		
		document.getElementById('searchType').value = "normal";								 
		document.getElementById('normal').className="enable";	
		document.getElementById('avancerad').className="disable";
		document.getElementById('setGroup').value = '0';
		document.getElementById('setTranslation').value = '0';		
		document.getElementById('setPicture').value = '0';				
		$('#avanceradbox').slideUp(400);
		detail(1,1,1);		
		return false;
	});		
});

function playAudio(lang, id)
{
    var content;

    content  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"0\" height=\"0\" id=\"myFlashContent\">";
    content += "<param name=\"movie\" value=\"/flash/sound.swf?country="+lang+"&key="+id+"\" />";
    content += "<param name=\"wmode\" value=\"transparent\" />";
    content += "<param name=\"allowFullScreen\" value=\"true\" />";
    content += "<param name=\"play\" value=\"true\" />";
    content += "<!--[if !IE]>-->";
    content += "<object type=\"application/x-shockwave-flash\" data=\"/flash/sound.swf?country="+lang+"&key="+id+"\" width=\"0\" height=\"0\">";
    content += "<!--<![endif]-->";
    content += "<a href=\"http://www.adobe.com/go/getflashplayer\">";
    content += "<img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" />";
    content += "</a>";
    content += "<!--[if !IE]>-->";
    content += "</object>";
    content += "<!--<![endif]-->";
    content += "</object>";

    $('#audio').html(content);
}
