﻿
var sDomain	  = 'www.lasta.com.vn'; 

function scaleImg(pic){	
	var img = document.getElementById(pic);	
	var imgH = img.clientHeight;
	var imgW = img.clientWidth;
	
	// Find which dimension is scaled the most
	var img_size = 100;
	var stemp;
	
	// Scale the image
	if (imgW > imgH) {
		img.style.width = img_size + "px";
		temp = (imgH * img_size)/imgW;		
		//img.style.height = Math.round(imgH) + "px";		
	} else {
		img.style.height = img_size + "px";
		temp = (imgW * img_size)/imgH;		
		//img.style.width = Math.round(imgH) + "px";		
	}
}

function modalDialogShow_IE(url,width,height) //IE
	{
	return window.showModalDialog(url,window,
		"dialogWidth:"+width+"px;dialogHeight:"+height+"px;edge:Raised;center:Yes;help:No;Resizable:Yes;Maximize:No");
	}
function modalDialogShow_Moz(url,width,height) //Moz
    {
    var left = screen.availWidth/2 - width/2;
    var top = screen.availHeight/2 - height/2;
    activeModalWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
    window.onfocus = function(){if (activeModalWin.closed == false){activeModalWin.focus();};};
    }
	
function openLinkYes(url) {
    window.open(url,'mywindow','width=600,height=400,addressbar=yes,scrollbars=yes,toolbar=yes,resizable=yes,menubar=yes');
}

function openLinkNo(url) {
    window.open(url,'mywindow','width=600,height=400,addressbar=no,scrollbars=yes,toolbar=no,resizable=no,menubar=no');
}

function ClickToURL(selObj, restore)
{
var http=selObj.options[selObj.selectedIndex].value;
if (restore) selObj.selectedIndex=0;
if (http!="")
window.open(http);
}

function GotoSite(url)
{	 		
	 window.location.href=url;
}

function isEmail(s)
   {   
	  if (s=="") return false;
	  if(s.indexOf(" ")>0) return false;
	  if(s.indexOf("@")==-1) return false;
	  var i = 1;
	  var sLength = s.length;
	  if (s.indexOf(".")==-1) return false;
	  if (s.indexOf("..")!=-1) return false;
	  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
	  if (s.lastIndexOf(".")==s.length-1) return false;
	  var str="0123456789_abcdefghikjlmnopqrstuvwxyz-@._"; 
	  for(var j=0;j<s.length;j++)
		if(str.indexOf(s.charAt(j))==-1)
			return false;
	  return true;
	}
	
function makevisible(cur,which){
	var strength=(which==0)? 1 : 0.8
	if (cur.style.MozOpacity)
	cur.style.MozOpacity=strength
	else if (cur.filters)
	cur.filters.alpha.opacity=strength*100
}

function validContactForm(thisform){
		var objform = document.forms[thisform];
		if (objform.elements['txtHoten'].value == ""){
				alert("Vui lòng nhập tên !\n(Please insert your name !)");	
				objform.elements['txtHoten'].focus();
				return false;
			}
		if (objform.elements['txtMail'].value == ""){
				alert("Vui lòng nhập địa chỉ mail !\n(Please insert your email !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		else		
			if (!isEmail(objform.elements['txtMail'].value)){
				alert("Địa chỉ mail không hợp lệ !\n(Your email incorrect !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		if (objform.elements['txtNoidung'].value == ""){
				alert("Vui lòng nhập nội dung !\n(Please insert content!)");
				objform.elements['txtNoidung'].focus();
				return false;
			}
		if (objform.elements['txtsafecode'].value == ""){
				alert("Vui lòng nhập mã an toàn !\n(Please insert safe code!)");
				objform.elements['txtsafecode'].focus();
				return false;
			}
		return true;
	}
function checkYK(thisform){
		var objform = document.forms[thisform];
		if (objform.elements['txtHoten'].value == ""){
				alert("Vui lòng nhập tên !\n(Please insert your name !)");	
				objform.elements['txtHoten'].focus();
				return false;
			}
		if (objform.elements['txtMail'].value == ""){
				alert("Vui lòng nhập địa chỉ mail !\n(Please insert your email !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		else		
			if (!isEmail(objform.elements['txtMail'].value)){
				alert("Địa chỉ mail không hợp lệ !\n(Your email incorrect !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		if (objform.elements['txtContent'].value == ""){
				alert("Vui lòng nhập nội dung !\n(Please insert content!)");
				objform.elements['txtContent'].focus();
				return false;
			}
		if (objform.elements['txtsafeCode'].value == ""){
				alert("Vui lòng nhập mã an toàn !\n(Please insert safe code!)");
				objform.elements['txtsafeCode'].focus();
				return false;
			}		
		return true;
	}
	
function printArticle(id){
	var w=window.open("http://" & sDomain & "/printpage.asp?id=" + id, '_blank', '');	
	return false;	
}
function printFAQ(id){
	var w=window.open("http://" & sDomain & "/printpage.asp?Code=faq&id=" + id, '_blank', '');	
	return false;	
}

function checkAQ(thisform){
		var objform = document.forms[thisform];
		if (objform.elements['txtHoten'].value == ""){
				alert("Vui lòng nhập tên !\n(Please insert your name !)");	
				objform.elements['txtHoten'].focus();
				return false;
			}
		if (objform.elements['txtMail'].value == ""){
				alert("Vui lòng nhập địa chỉ mail !\n(Please insert your email !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		else		
			if (!isEmail(objform.elements['txtMail'].value)){
				alert("Địa chỉ mail không hợp lệ !\n(Your email incorrect !)");	
				objform.elements['txtMail'].focus();
				return false;
			}
		if (objform.elements['txtContent'].value == ""){
				alert("Vui lòng nhập nội dung !\n(Please insert content!)");
				objform.elements['txtContent'].focus();
				return false;
			}
		if (objform.elements['txtsafeCode'].value == ""){
				alert("Vui lòng nhập mã an toàn !\n(Please insert safe code!)");
				objform.elements['txtsafeCode'].focus();
				return false;
			}		
		return true;
	}

function SubmitVote(sform, saction)
{
	var flag=false;
	if (saction==0)
	{
		for (i=0; i<sform.fvotefor.length; i++){
			if (sform.fvotefor[i].checked)
			{ flag=true; break;	}			
		}
		if (!flag)
		{
			alert('Hay chon mot trong cac muc truoc khi bieu quyet');
			return false;
		}
	}

	var form = sform;
	var j = 0
	for (i=0; i < form.elements.length - 2; i++)
		{
			if(form.elements[i].type=='radio'){
				j = j + 1
			}
		}
	var sheight = (j * 40) + 80;
	if (sheight < 250){
		sheight = 250;
	}
	
	open('', sform.name, 'scrollbars=yes,resizeable=no,locationbar=no,width=550,height='+sheight+',left='.concat((screen.width - 500)/2).concat(',top=').concat((screen.height - 250)/2));
	sform.faction.value = saction;
	sform.action = 'http://'+sDomain+'/Vote/';
	sform.submit();
}


var version = "other"
browserName = navigator.appName;   
browserVer = parseInt(navigator.appVersion);

if (browserName == "Netscape" && browserVer >= 3) version = "n3";
else if (browserName == "Netscape" && browserVer < 3) version = "n2";
else if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) version = "e4";
else if (browserName == "Microsoft Internet Explorer" && browserVer < 4) version = "e3";

function stopError(){return true;}
window.onerror = stopError;

function wireOpen()
{if (version == "e4")
{document.write("<marquee behavior=scroll direction=up width=150  height=200 scrollamount=1 scrolldelay=10 onmouseover='this.stop()' onmouseout='this.start()'>")}}

function wireClose()
{if (version == "e4")
{document.write("</marquee>")}}

function openNewWin(url) {
    if(navigator.appName.indexOf('Microsoft')!=-1)
		modalDialogShow_IE(url,455,340); //IE	
	else
		modalDialogShow_Moz(url,455,330); //Moz		
}

function openPopup(url) {
    if(navigator.appName.indexOf('Microsoft')!=-1)
		modalDialogShow_IE(url,325,445); //IE	
	else
		modalDialogShow_Moz(url,325,430); //Moz		
}

function getData(dataSource, divID){
	var XMLHttpRequestObject = false;
	var myobj = document.getElementById(divID);
	if (!myobj){
		return;
	}
	if (window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(XMLHttpRequestObject) {
		XMLHttpRequestObject.open("GET", dataSource);
		XMLHttpRequestObject.onreadystatechange = function()			
		{ //alert(XMLHttpRequestObject.responseText);
			if (XMLHttpRequestObject.readyState == 4 &&	XMLHttpRequestObject.status == 200) {
				myobj.innerHTML = XMLHttpRequestObject.responseText;
			}
		}
	XMLHttpRequestObject.send(null);
	}
}


function EW_Encode(str) {	
	return encodeURIComponent(str);
}

function EW_Decode(str) {
	return decodeURIComponent(str);	
}

function onViewImgAlbum(img, divID){
		var myobj = document.getElementById(divID);
		if (img.length>0){
				myobj.innerHTML = "<img src='" + img + "' border=0 width=550 style='border:1px solid #FFFFFF;'>"
			}
	}
	
function Nexter(){

	if (currentIndx<imagesPreloaded.length-1){
	
		/* the length of our array is 4. But the images go from 0 to 3, so we take one off the count. (We made currentIndx equal 0 right at the beginning of our script!) */
		
		currentIndx=currentIndx+1;
		
		/* To go forward, we add one, providing the number is less than the number of images */
		
		document.theImage.src=imagesPreloaded[currentIndx].src
		
		/* The NAME of the image in our slide show is theImage. We can change the image loaded here as above */	
		
	}
	
	else {
	
		currentIndx=0
		
		/* Otherwise, we go back to the beginning, if currentIndx is too big */
		
		document.theImage.src=imagesPreloaded[currentIndx].src		
	}

}

/* The function Baccker() is similar to the previous function, so it contains no comments */

function Backer(){

	if (currentIndx>0){
	
		currentIndx=currentIndx-1;
		
		document.theImage.src=imagesPreloaded[currentIndx].src
	
	}
	
	else {
	
		currentIndx=imagesPreloaded.length-1
		
		document.theImage.src=imagesPreloaded[currentIndx].src

	}
}

function automaticly() {	
	if (currentIndx<imagesPreloaded.length-1){
	
		currentIndx=currentIndx+1;
	}
	
	else {
	
		currentIndx=0;
	}
	
	/* I have put this code at the end, so it follows on naturally after the value of currentIndx is determined */
	
	document.theImage.src=imagesPreloaded[currentIndx].src;
	
	/* The only special bit of script is this line, which sets the timer value to 5 seconds, or 5000 milliseconds. */
	
	var delay = setTimeout("automaticly()",3000)

}