﻿
var xmlHttp;
var objID;

function __doPostBack(eventTarget, eventArgument)
{
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.Form1;
	}
	else {
		theform = document.forms["Form1"];
	}
	theform.__EVENTTARGET.value = eventTarget; 
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit(); 
}

function validateURL(txtObject, sText)
{
	var testpattern;
	testpattern = /http:\/\/www.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/;
	if(getObj(txtObject).value!="")
	{
		if(testpattern.test(getObj(txtObject).value)==false)
		{
			alert(sText);
			getObj(txtObject).focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}

function validateMailServer(txtObject, sText)
{
	var testpattern;
	testpattern = /mail|smtp.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/;
	if(getObj(txtObject).value!="")
	{
		if(testpattern.test(getObj(txtObject).value)==false)
		{
			alert(sText);
			getObj(txtObject).focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}

function getObj(name)
{   
	if (document.getElementById)
	{	
		return document.getElementById(name);
	}
	else if (document.all)
	{	
		return document.all[name];
	}
	else if (document.layers)
	{	
		return document.layers[name];
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}

//Hàm hiển thị thông tin data cho dropdownlist
//sPageName			Ten trang duoc reqquest
//sKeyQuery			Điều kiện truy vấn
//objReceiceData	Tên của dropdownlist nhận dữ liệu và hiển thị
//sText				Đoạn text hiển thị đầu tiên của dropdownlist
//ENorVN			Trạng thái hiển thị ngôn ngữ : true = tiếng Anh; false = tiếng Việt
//Module			Tên ID module (thực thi để lấy kết quả)

function Show(sPageName, sKeyQuery, objReceiceData, sText)
{
	objID = objReceiceData;
	strText=sText;
	if (sKeyQuery!= "")
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
  		{
  			alert ("Your browser does not support AJAX!");
  			return;
  		}
  		else
  		{
  			var url=sPageName;
			url=url+"?"+sKeyQuery;
			url=url+"&sid="+Math.random();
			xmlHttp.onreadystatechange=ReceiceData;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
  		}
	}
}
/*
	Hàm nhận dữ liệu và hiển thị giá của sản phẩm.
*/
function ReceiceData()
{
	if (xmlHttp.readyState==4)
	{ 
		var strTemp=xmlHttp.responseText;
		getObj(objID).innerHTML=""
		getObj(objID).innerHTML=strTemp;
	}
	else
	{
		if (strText=="")
		{
			getObj(objID).innerHTML="<div align='center'><img src='images/loading_1.gif' align='absmiddle' /> Đang tải dữ liệu...</div";
		}
		else
		{
			getObj(objID).innerHTML=strText;
		}
		
	}
}


function insertOption(sourceArr)
{
	var optionArr=new Array();
	var ValAndTextArr=new Array();
	optionArr=sourceArr.split("~");
	var x=getObj(objID);
	for(var i=x.length-1; i>=0; i--)
	{
		x.options[i] = null;
	}
	var y;
	y= document.createElement('option');
	y.text=strText;
	y.value="0";
	try
	{
		x.add(y,null); // standards compliant
	}
	catch(ex)
	{
		x.add(y); // IE only
	}
	for (i=0;i<optionArr.length;i++)
	{
		y= document.createElement('option');
		ValAndTextArr=optionArr[i].split("#");
		y.value=ValAndTextArr[0];
		y.text=ValAndTextArr[1];
		try
		{
			x.add(y,null); // standards compliant
			}
		catch(ex)
		{
			x.add(y); // IE only
		}
	}
}

//CloseMoreImage();
function ShowComment()
{
    try
    {
        getObj("pnlWriteComment").style.display = "none";
        getObj("pnlViewComment").style.display = "block";
    }
    catch (e)
    {}
}
function ShowWrite()
{
    try
    {
        getObj("pnlViewComment").style.display = "none";
        getObj("pnlWriteComment").style.display = "block";
    }
    catch (e)
    {}
}
function ShowFlashImage()
{
	try
	{
	    getObj("pnlMoreImage").style.display = "block";
	    getObj("divImageFlash").style.position = "absolute";
	    getObj("divImageFlash").innerHTML = CreateFlash();
	    document.location.href = "#MoreImage";
	}
	catch (e)
	{}
}

function CheckFormatEmail(txtObject, strENorVN) 
{
	var testpattern = /^\d+$/;
	testpattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(getObj(txtObject).value!="")
		if(testpattern.test(getObj(txtObject).value)==false)
		{
			alert(strENorVN);
			getObj(txtObject).focus();
			return false;
		}
	return true;	
}

function CheckFormatNumber(txtObject, strENorVN)
{
	var Temp=getObj(txtObject).value
	if (Temp !="" && Temp >0)
	{
		if (isNaN(getObj(txtObject).value))
		{			
			getObj(txtObject).focus();
			alert(strENorVN);
			return false;
		}
	}
	else
	{
		getObj(txtObject).focus();
		alert(strENorVN);
	}	
}

function checkNumeric(txtObject, strENorVN)
{
	if (isNaN(getObj(txtObject).value))
	{			
		getObj(txtObject).focus();
		alert(strENorVN);
		return false;
	}
	if (getObj(txtObject).value==0) getObj(txtObject).value=1;
}
function checkBrowser()
{
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		return true;
	}
	else {
		return false;
	}
}

function CreateImageHtmlTag(s_FilePath, i_Width, i_Height)
{
	var html="";
	html = "<img src='" + s_FilePath + "' height='" + i_Height + "px' width='" + i_Width + "' border='0' />";
	alert(html);
	return html;
}

function CreateFlash1(s_FilePath, i_Width, i_Height)
{
	var html = "";
	html  = "<OBJECT id='Shockwaveflash1' codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ";
	html +=	"height=\"" + i_Height + "\" width=\"" + i_Width + "\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" VIEWASTEXT>";
	html += "<PARAM NAME=\"_cx\" VALUE=\"10848\">";
	html +=	"<PARAM NAME=\"_cy\" VALUE=\"2646\">";
	html += "<PARAM NAME=\"FlashVars\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"Movie\" VALUE=\"" + s_FilePath + "\">";
	html +=	"<PARAM NAME=\"Src\" VALUE=\"" + s_FilePath + "\">";
	html +=	"<PARAM NAME=\"WMode\" VALUE=\"Window\">";
	html += "<PARAM NAME=\"Play\" VALUE=\"-1\">";
	html +=	"<PARAM NAME=\"Loop\" VALUE=\"-1\">";
	html +=	"<PARAM NAME=\"Quality\" VALUE=\"High\">";
	html +=	"<PARAM NAME=\"SAlign\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"Menu\" VALUE=\"-1\">";
	html +=	"<PARAM NAME=\"Base\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"AllowScriptAccess\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"Scale\" VALUE=\"ShowAll\">";
	html +=	"<PARAM NAME=\"DeviceFont\" VALUE=\"0\">";
	html +=	"<PARAM NAME=\"EmbedMovie\" VALUE=\"0\">";
	html +=	"<PARAM NAME=\"BGColor\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"SWRemote\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"MovieData\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"SeamlessTabbing\" VALUE=\"1\">";
	html +=	"<PARAM NAME=\"Profile\" VALUE=\"0\">";
	html +=	"<PARAM NAME=\"ProfileAddress\" VALUE=\"\">";
	html +=	"<PARAM NAME=\"ProfilePort\" VALUE=\"0\">";
	html +=	"<EMBED src='" + s_FilePath + "' quality='high' ";
	html +=	"bgcolor='#FFFFFF' WIDTH='" + i_Width + "' HEIGHT='" + i_Height + "' NAME='ImageFlash' TYPE='application/x-shockwave-flash' ";
	html +=	"PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>";
	html +=	"</OBJECT>";
	return html;
}
//, CapNhatOrThemMoi
function KiemTraHopLeCuaViTri(iGiaTri, sViTri, chkName, CapNhatOrThemMoi)
{
	//CapNhatOrThemMoi == 0=CapNhat; 1=ThemMoi && CapNhatOrThemMoi!=0
	if (iGiaTri==0)
	{
		if (getObj(chkName).checked==true)
		{
			alert('Không còn chỗ để đặt quản cáo này trên trang được chọn ở vị trí bên ' + sViTri);
			getObj(chkName).checked=false;
		}
	}
}

function who(i, iFlag)
{
	var sPageName=""
	var iPosLeft=screen.availWidth/2-260;
	var iPostTop=screen.availHeight/2-250;
	if (iFlag==1)
	{
		sPageName = "../Forum/"
	}
	else
	{sPageName = "../"}
	sPageName += "ForumPages/" + "MemberProfile.aspx";
	smallwindow=window.open(sPageName + "?m_id=" +i ,"smallwindow","location=0,menubar=0,scrollbars=yes,width=330,height=240,left=" + iPosLeft + ",top=" + iPostTop + ",noresize,scrolling=yes");
	if(!smallwindow.focus())smallwindow.focus()
}
function ViewAdsFlash(ContainerName, iWidth, iHeight, sPath){
    var sObjFlash="";
    sObjFlash+="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' style='z-index: -1'"; 
    sObjFlash+="codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' ";
    sObjFlash+="width='"+iWidth+"' height='"+iHeight+"'>";
    sObjFlash+="<param name='movie' value='../AppFile/Flash/"+sPath+"' />";
    sObjFlash+="<param name='WMode' value='Transparent'>";
    sObjFlash+="<param name='quality' value='high' />"
    sObjFlash+="<embed src='../AppFile/Flash/"+sPath+"' quality='high' ";
    sObjFlash+="pluginspage='http://www.macromedia.com/go/getflashplayer' ";
    sObjFlash+="type='application/x-shockwave-flash' width='"+iWidth+"' height='"+iHeight+"' wmode='transparent' style='z-index: -1'></embed></object>";
    document.getElementById(ContainerName).innerHTML=sObjFlash;
}
