﻿var request_pic = false;
try {
	request_pic = new XMLHttpRequest();
} catch (trymicrosoft) {
	try {
		request_pic = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (othermicrosoft) {
		try {
			request_pic = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (failed) {
			request_pic = false;
		}
	}
}

if (!request_pic)
	alert("Error initializing XMLHttpRequest!");

function getCollectionPic(url)
{	
	if(i < count_pic - 1)
		i += 1;
	else
		i = 0;
	request_pic.open("GET", url, true);
	
	request_pic.onreadystatechange = updatePagePic;
	
	//request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	request_pic.send(null);	
}
function updatePagePic() {
	if (request_pic.readyState == 4) {
		if (request_pic.status == 200) {
			var response = request_pic.responseText;			
			var obj = document.getElementById("Collection_Pic_slide");
			if(obj){
				obj.innerHTML = response;
			}
		}
	}
}
function run_slide(){	
	getCollectionPic(url_rg + i);	
}
function updatePageVote() {
	if (request_pic.readyState == 4) {
		if (request_pic.status == 200) {
			var response = request_pic.responseText;			
			alert(response);
			window.location.reload();
		}
	}
}
function vote_click(url){
	var obj = document.getElementById('vote');
	if(obj && obj.value==0){
		alert('Bạn chưa chọn số Sao đánh giá');
		return false;
	}
	if(obj){
		url += '&vote=' + (parseInt(obj.value) - 1);
	}
	obj = document.getElementById('vote_email');
	if(obj){
		if(obj.value == '' || obj.value == ' ' || obj.value == 'Địa chỉ Email của bạn là...'){
			alert('Bạn chưa nhập Email');
			obj.focus();
			return false;
		}
		if(!isEmail(obj.value)){
			alert('Địa chỉ Email không đúng định dạng');
			obj.focus();
			return false;
		}
	}
	if(obj){
		url += '&email=' + obj.value;
	}
	obj = document.getElementById('vote_tel');
	if(obj){
		if(obj.value == '' || obj.value == ' ' || obj.value == 'Số điện thoại của bạn là...'){
			alert('Bạn chưa nhập số điện thoại liên hệ');
			obj.focus();
			return false;
		}
	}
	if(obj){
		url += '&tel=' + obj.value;
	}
	request_pic.open("GET", url, true);
	request_pic.onreadystatechange = updatePageVote;
	request_pic.send(null);		
}
function vote_over(i,n, class1, class2){
	for(var j = 0; j <= n; j++){
		var obj = document.getElementById('vote_' + j);
		if(obj){
			if(j <= i){
				obj.className = class1;
			}else{
				obj.className = class2;
			}
		}
	}
	var obj = document.getElementById('vote');
	if(obj){
		obj.value = i + 1;	
	}
}
function clear_focus(obj, s){
	if(obj.value == s){
		obj.value = '';	
	}
}
function put_blur(obj, s){
	if(obj.value == '' || obj.value == ' '){
		obj.value = s;	
	}
}
function setHomepage(title, url)
{
	 if (document.all)
		{
			document.body.style.behavior='url(#default#homepage)';
			document.body.setHomePage(url);
	 
		}
		else if (window.sidebar)
		{
		if(window.netscape)
		{
			 try
	   		 {  
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			 }  
			 catch(e)  
			 {  
				 alert("Đặt trang chủ bị chặn bởi trình duyệt của bạn\n，nếu bạn muốn bật chức năng này, bạn ，hãy gõ about:config thanh địa chỉ.\nVà thay đổi giá trị ở mục signed.applets.codebase_principal_support là true \nbằng cách click đúp chuột vào mục đó.");  
			 }
		} 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',url);
	 }
}
