﻿var PageHost='http://vnexpress.net';
function AddHeader(Name, Header, Buttons, Symbol, AddChildTable)
{
	document.writeln('<div class=BreakLine id="IDM_', Name, '">');
	if (typeof(AddChildTable)=='undefined')
	{
		document.writeln('<table class="OutsiderBox" align=center width="100%" cellspacing=0 cellpadding=0 border=0>');
		LastChild = 1;
	}
	else
	{
		LastChild = 0;
	}
	return true;
}

function AddFooter()
{
	if (LastChild)
	{
		document.writeln('</table></div>');
	}
	else
	{
		document.writeln('</div>');
	}
}

function ItemMinMax(Name, ControlButton)
{
	var MItem = document.all(Name);
	var ImgItem = document.all(ControlButton);
	if (MItem.style.display=='')
	{
		MItem.style.display='none';
		ImgItem.src='Images/Weather/min.gif';
	}
	else
	{
		MItem.style.display='';
		ImgItem.src='Images/Weather/max.gif';			
	}
}
	
function opnwd(url)
{
	popupWin = window.open(url,'new_page','toolbar=no,location=no,menubar=no,scrollbars=yes,width=500,height=460,top=40,left=130,resizeable=yes,status=no');
}

function OpenNewWindow(url, wndName, attr)
{
	/*var winX = (screen.availWidth - w)*.5;
	var winY = (screen.availHeight - h)*.5;*/
	var _newWindow = window.open(url,wndName,attr);	
	return _newWindow;
}

//Ham dung de phong to anh
function openImageNews(vLink,ImgSrc)
{
	var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;
	var newImg,vHeight = 0, vWidth = 0;
	if (sLink == '')
	{
		return false;
	}
	newImg = new Image();
	newImg.src = ImgSrc;
	vWidth = newImg.width;
	vHeight = newImg.height;
	newImg = null;

	if (vWidth == 0 || vHeight == 0) return false;
	
	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>qdnd.vn</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="/NQL/', ImgSrc, '" alt="', 'Dong lai', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(vLink.href) != 'undefined')
	{
		return false;
	}
}

// Used by Paging Section
function changePage(form)
{
	form.submit();
}

// Use POST method to exec a link
// form : form id, this form
// ItemID : Hidden element ID
// ID : ID Value
function FollowLink(form, ItemID, ID)
{
	ItemID.value = ID;	
	form.submit();
}

// Use POST method to exec a link with two Parameter
// form : form id, this form
// ItemID : Hidden element ID
// ID : ID Value
// SecondItemID :Second Hidden element ID
// SecondID : Second ID Value
function FollowLink2P(form, ItemID, SecondItemID, ID, SecondID)
{
	ItemID.value = ID;
	SecondItemID.value = SecondID;
	form.submit();
}

function openInfo(url, width, height)
{
	var attri;
	attri = 'width=' + width + ',height=' + height + ',resize=yes ,scrollbars=yes,status=yes,toolbar=yes,top=0,left=0';
	var popwin = window.open(url,'Page_'+width,attri);
	return;
}


/************************************************
Makes all Yes/No entries on the form visible
*/
function showAllComboBox()
{
  var elements = document.getElementsByTagName("select");
  var i;
  for (i=0; i<elements.length; i++)
  {
	elements[i].style.visibility="visible";
  }
}



//ham sho va hide
function show(id)
{		
		var _objDiv= document.all[id];
		if(_objDiv.className=="Hidde")
		{
		    
			_objDiv.className="Show";
			
		}
}

function hidde(id)
{
		var _objDiv= document.getElementById(id);
		
		if(_objDiv != null && _objDiv.className != null && _objDiv.className == "Show")
		{
		    
			_objDiv.className="Hidde";
			
		}
}

function changetheImage(sPath,sImage)
{
  var  Iimage= document.all["Picture"];
  Iimage.src=sPath +sImage;
  var  intHeight,intWidth,intScale;
  intWidth=Iimage.width;
  intHeight=Iimage.height;
  intScale=intWidth/intHeight;
  if(intWidth>300)
  {
     Iimage.width=300;
     Iimage.height=300* intScale;
  }  
}

function changeImage(sPath,sImage)
{
  var objArr=sImage.split(".");
  var ext=objArr[objArr.length-1];
  if((ext=="jpg")||(ext=="gif")||(ext=="png"))
  {
	show("imgArea");
	hidde("flashArea");
	var  Iimage= document.all["Picture"];
	Iimage.src="getImage.aspx?filename="+sPath +sImage+"&width=200";
  }
  if(ext=="swf")
  {
	show("flashArea");
	hidde("imgArea");
	var _objDiv= document.all("flashArea");
	_objDiv.innerHTML="<embed src="+sPath +sImage+" width=200>";
  }
}

function getFileOnly(sValue)
{
   var sResult="";
   var i=sValue.lastIndexOf('/') +1;
   if(sValue!='')
      sResult=sValue.substring(i);
   document.all["PictureName"].innerText=sResult;
   return sResult;
}
function setHiddenField(sValue)
{
     document.all["PictureName"].innerText=getFileOnly(sValue);
     document.all["hddPicture"].value=sValue;
}

function SelectImage(aFolder)
{
    var objSelect =document.getElementsByTagName("select");
    var sValue="";
    
    if(objSelect!=null)
         sValue= objSelect[1].options[objSelect[1].selectedIndex].value;
    window.opener.document.getElementById("hddPicture").value= "Images/"+aFolder+"/"+sValue;
    window.opener.document.getElementById("Picture").src="Images/"+aFolder+"/"+sValue;
    window.opener.document.getElementById("PictureName").innerText=sValue;
    window.close();
}

function ShowWindow(sUrl,w,h)
{
	var winX = 0;
	var winY = 0;
	if (parseInt(navigator.appVersion) >= 4)
	{
		winX = (screen.availWidth - w)*.5;
		winY = (screen.availHeight - h)*.5;
	}
	popupLoadnWin=window.open(sUrl,'popupLoadnWin','scrollbars,resizable=no,status=yes, width=' + w + ',height=' + h + ',left=' + winX + ',top=' + winY);
	        
}

function Height_Width(obj)
{

  if(obj.value!="")
  {
	var Iimage=document.all["Picture"];
	var img= new Image();
	img.src=obj.value;
	document.all["Height"].value=img.height;
	document.all["Width"].value=img.width;
	
	Iimage.src=obj.value;
  }
   
}

function Filechange(obj)
{
   var Iimage= document.all["Picture"];
   Iimage.src=obj.value;
   
}

var _blnShow = false;
function comment()
{		
		var _objDiv= document.all["comment"];
		if(_objDiv.className=="commentHidden")
		{
		    
			_objDiv.className="commentVisible";
			
		}
		else 
		{
			_objDiv.className="commentHidden";
	}
}

function ChildImage(_strAuthor)
{
	var objSelect =document.getElementsByTagName("select");
    var sValue="";
    if(objSelect!=null)
         sValue= objSelect[1].options[objSelect[1].selectedIndex].text;
    
    var fulparth=window.location.href;     
    var hostname= fulparth.substring(0,fulparth.indexOf("MediaHelper.aspx"));
    window.opener.document.getElementById("inpImgURL").value=hostname+"images/"+_strAuthor+"/"+sValue;
    self.close();
}

function ShowListCat(sName,sNameStyle)
{
	var _objDiv=document.all[sName];
   _objDiv.className=sNameStyle;   
}
function CheckAccount(oldpass,hiddenPass, newpass)
{
	var result;
	if(oldpass=="")
	{
		alert('Bạn phải nhập vào ');
		result= false;
	}
	if(oldpass!=hiddenPass)
	{
		alert('Bạn đã nhập sai password cữ, xin mời nhập lại');
		result= false;
	}
	if(newpass=="")
	{
		alert('Mời bạn nhập vào password mới');
		result=false;
	}
	if(oldpass!=newpass)
	{
		alert('Mật khẩu chưa được xác nhận đúng, mời nhập lại');
		result= false;
	}
	return result;
}

function doGetModuleTitle()
{
	var res = Portal.Ultility.ShowInvidualModule.GetModuleTitle();
	
	p = res.value;
	alert(p);
}

function doGetModule(tabref, moduleref, callback)
{
	var res = Portal.Ultility.ShowInvidualModule.LoadModuleContent(tabref, moduleref);
	
	var p = res.value;
	
	alert(p);
}

function ShowModule_CallBack(response)
{
	if (response.error != null)
	{
		alert("Error : " + response.error);
		return;
	}
	alert("Value : " + response.value);
}
function popup(wURL,wTitle,wFeature)
{
	mywin=window.open(wURL,wTitle,wFeature);
}
function slow(ele)
{
 ele.scrollAmount = 1;
}
function fast(ele) 
{ 
ele.scrollAmount = 2; 
}
// window media
function Playfile(sfile) {
	document.forms[0].mediaplayer.URL=sfile;
}
function PlayformUrl()
{
	var strUrl=window.location.href;
	if(strUrl.indexOf("#mms")>0)
	{
		var strMms=strUrl.split("#")[1];
		//alert("url="+strUrl+"mms="+strMms);
		Playfile(strMms);
	}
}
function uMouseMove()
{
document.forms[0].test.value = "B&#7845;m &#273;úp &#273;&#7875; xem toàn màn hình.";
}

function uMouseOut()
{
document.forms[0].test.value = "T&#7843;i ph&#7847;n m&#7873;m xem ch&#432;&#417;ng trình.";
}

function uMouseDown()
{
document.forms[0].test.hideFocus=true;
} 

/*voi votes*/
function doVote(id, frm)
{
	/*var ml=document.vote;
	ml.action="site/usercontrols/vote_result.aspx?id="+id;
	ml.submit();*/
	var val=document.forms[0].R1;
	var Rval= getCheckedValue(val);
	OpenNewWindow('Ultility/ResultSelect.aspx?edittype='+ id +'&pollid='+ Rval,'myWind','width=500, height=350, resize=0, scrollbars=1');
	//javascript:window.open('site/usercontrols/vote_result.aspx?id='+id+'&R1='+Rval, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,top=200,left=200,width=400,height=300');	
}
function getCheckedValue(radioObj) 
{
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
		for(var i = 0; i < radioLength; i++) 
		{
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
}

/*doSearch*/
function doSearch(txtSearch)
{
	var text=document.all[txtSearch].value;
	//alert('obj='+text);
	window.location.href='searching.aspx?s=&q=' + escape(text) + '&m=0';
}

/*Duongna scripts*/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
// Get control bằng tên control
function GetControlByName(name)
{
    return document.getElementById(document.getElementById('hidIdPrefix').value+name);
}
//Kiểm tra giá trị cần
function CheckRequire(controlToCheck , nameOfControl)
{
    var controlToValidate;
    controlToValidate = GetControlByName(controlToCheck);
    if(controlToValidate.value.trim().length == 0)
    {
        alert(nameOfControl + " không được để trống!");
        controlToValidate.focus();
        return false;
    }
    else
    {
        return true;
    }
}
//Kiểm tra Email
function EmailCheck (controlName) 
{
var emailStr = GetControlByName(controlName).value;
if(emailStr.trim().length==0)
    return true;
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) 
{
    alert("Email address seems incorrect (check @ and .'s)");
    GetControlByName(controlName).focus();
    return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) 
{
    // user is not valid
    alert("The username doesn't seem to be valid.");
    GetControlByName(controlName).focus();
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) 
{
    // this is an IP address
	  for (var i=1;i<=4;i++) 
	  {
	    if (IPArray[i]>255) 
	    {
	        alert("Destination IP address is invalid!");
	        GetControlByName(controlName).focus();
		    return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) 
{
	alert("The domain name doesn't seem to be valid.")
	GetControlByName(controlName).focus();
    return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) 
{
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   GetControlByName(controlName).focus();
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) 
{
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//Chỉ nhập số
function NumberBox(e)
{
  var keynum;
  e = window.event;  
  keynum = e.keyCode; 
  
  if (keynum  < 48 || keynum > 57)
  {
   e.cancelBlur = false;
   e.returnValue = false ;
  }     
}
//không cho phép nhập 1 số ký tự đặc biệt
function CheckUserName(e)
{
  var keynum;
  e = window.event;  
  keynum = e.keyCode;
  
  if (!((keynum  >= 48 && keynum <= 57) || (keynum>=97 && keynum<=122) || (keynum>=65 && keynum<=90) || keynum == 45 || keynum == 95 ))
  {
    e.cancelBlur = false;
    e.returnValue = false ;
  }
}

function GetQueryString(value) 
{
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) 
    {
        ft = gy[i].split("=");
        if (ft[0] == value)
        {
            return ft[1];
        }
    }
}
