var PreloadImg = function(){
	var preloadImages = new Array();
	for(var i=0;i<arguments.length;i++){
		preloadImages[0] = new Image();
		preloadImages[0].src = arguments[i];
		//alert(arguments[i]);
	}
}

PreloadImg("/images/theme.gif","/images/loadingAnimation.gif");
function checksub(){
	var sub_email=$('#sub_email').val();
	if(chkemail(sub_email)){
		$.post("/ajax/user.php",{"action":'check_sub_email',sub_email:sub_email},
		function(avr){
			if(avr=='yi'){
				$('#sub_email_id').val('2');
				alert("Your have already subscribed to GotoArcade Newsletter.");
				$("#sub_email")[0].focus();
				return false;
			}else if(avr=='false'){
				alert("Incorrect email format.");
				$("#sub_email")[0].focus();
				return false;
			}else if(avr=='true'){
				$("#sub_email").val('');
				alert("Thank you. Your email is recorded.");
				return true;
			}
		});	
	}else{
		alert("Incorrect email format.");
		$("#sub_email")[0].focus();
		return false;
	}
}
function chkemail(a) { 
	var i=a.length; 
	var temp = a.indexOf('@'); 
	var tempd = a.indexOf('.'); 
	if (temp > 1) { 
		if ((i-temp) > 3){ 
			if ((i-tempd)>0){ 
				return 1; 
			} 
		} 
	} 
	return 0; 
} 

function searchcheck(){
	if(document.searchfrm.keyword.value==''){
		alert("Please enter the search key!");
		document.searchfrm.keyword.focus();
		return false;
	}
	return true;
}
function sendgood(id){
	$.post("/ajax/user.php",{action:"sendgood",id:id},
	function(msg){
		if(msg=='true'){
			alert("Thank you!");
			getvote(id);
		}else if(msg=='false'){
			alert("You have voted!");
		}
	})
}
function sendbad(id){
	$.post("/ajax/user.php",{action:"sendbad",id:id},
	function(msg){
		if(msg=='true'){
			alert("Thank you");
			getvote(id);
		}else if(msg=='false'){
			alert("You have voted!");
		}
	})
}
function getvote(id){
	$.getJSON("/ajax/user.php",{action:"getvote",id:id},
	function(json){
		$(".vote_center").html('<div class="vote_good" style="width:'+json.goodwidth+'%">'+json.goodwidth+'%</div><div class="vote_bad" style="width:'+json.badwidth+'%">'+json.badwidth+'%</div>');
		$("#num_good").html(json.times_good);
		$("#num_bad").html(json.times_bad);
	}
)}

function show_shockwave(src,width,height) {
	document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" width="' + width + '" height="' + height + '">');
	document.write('<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">');
	document.write('<param name="swStretchStyle" value="meet">');
	document.write('<param name="bgColor" value="#ffffff">');
	document.write('<param name="src" value="' + src + '">');
	document.write('<embed src="' + src + '" width="' + width + '" height="' + height + '" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>');
	document.write('</object>');
}

function CopyText(value) {
	try{
		var targetText = document.getElementById(value);
		targetText.focus();
		targetText.select();
		var clipeText = targetText.createTextRange();
		clipeText.execCommand("Copy");
	}catch(e){}
}
function displayload(){
	$("#preloaddiv").hide();
	$("#ContentDiv").show();
	$("#loadbar").hide();
	timesnap = 1;
}
function refreshProgress() {
	var bar = $("#loadcolumn");
	var movie =  $("#flashgame");
	//stringToEval = "window.document[\'flashgame\']";
	//var movie=eval(stringToEval);
	if (window.navigator.userAgent.indexOf("MSIE")>=1){//ie
		var nPercentLoaded = document.getElementById("flashgame").PercentLoaded();
		bar.css({ width: nPercentLoaded + "%"}); 
		bar.html(nPercentLoaded + "%");
		if(nPercentLoaded == 100){
			clearTimeout(nTimeoutId);
			if(timesnap == 1){
				displayload();
			}
			$("#loadbar").hide();
		} else {
			nTimeoutId = setTimeout('refreshProgress()', 100);
			//$("#preloaddiv").show();
			//$("#ContentDiv").hide();
		}
	}else{
		nTimeoutId = setTimeout('refreshProgress()', 100);
		
		//$("#preloaddiv").hide();
		//$("#ContentDiv").show();
		$("#loadbar").hide();
	}
	
}
