var oldColor = '';
function CheckDate(objDateField,strDateFormat,strMsg){
	//Check Date of dateobjects.
	//User:NVK
	//Date:29/8/2003
	strDateFormat = strDateFormat.toLowerCase();
	mdateval = eval(objDateField).value;	
	switch(strDateFormat){
		case 'dd/mm/yyyy':
				if (mdateval != "") {
					mday = mdateval.substring(0, mdateval.indexOf("/"));
					mmonth = mdateval.substring(mdateval.indexOf("/") + 1, mdateval.lastIndexOf("/"));
					myear = mdateval.substring(mdateval.lastIndexOf("/") + 1, mdateval.length);
					mdate = new Date (mmonth + "/" + mday + "/" + myear);
					cday = mdate.getDate();
					cmonth = mdate.getMonth() + 1;
					cyear = mdate.getYear();
					if ((parseFloat(mday) != parseFloat(cday)) || (parseFloat(mmonth) != parseFloat(cmonth)) || (isNaN(myear)) || (myear.length < 4)) 
						{
							alert(strMsg);							
							eval(objDateField).value = "";							
							eval(objDateField).focus();							
							return false;
						}
					break;
				}	
		case 'mm/dd/yyyy':
				if (mdateval != "") {
					mmonth = mdateval.substring(0, mdateval.indexOf("/"));
					mday = mdateval.substring(mdateval.indexOf("/") + 1, mdateval.lastIndexOf("/"))
					myear = mdateval.substring(mdateval.lastIndexOf("/") + 1, mdateval.length);
					mdate = new Date (mmonth + "/" + mday + "/" + myear);
					cday = mdate.getDate();
					cmonth = mdate.getMonth() + 1;
					cyear = mdate.getYear();
					if (parseFloat(mday) != parseFloat(cday) || parseFloat(mmonth) != parseFloat(cmonth)|| (myear != cyear)) {
						alert(strMsg);
						eval(objDateField).value = "";
						eval(objDateField).focus();
						return  false;
					}		
					break;
				}
	}
	return true;
}

/* Check value is empty
	if obj's value is null return true 
	else return false
*/
function CheckNull(obj){	
    strValue=trim(eval(obj).value);
    if (strValue == "") {
       return true;
    }
}

//Check value of dateobjects is empty.
function CheckNullValue(obj, strMsg){	
	var strValue;
	var blnEmpty = true;
	if (obj)
		strValue =eval(obj).value;
	else
		strValue = obj;    
    if (strValue != ""){	
      for (i = 0; i < strValue.length; i++) {
        if (strValue.charAt(i) != " ") {
		   blnEmpty = false;           
           break;
        }
      }               
    }
    if (blnEmpty){
           alert(strMsg);
           if (eval(obj))
				eval(obj).focus();
		   return false;
	}
    return true;
}

//Check a variable is number
function CheckNum(obj, msg) {	
	var strValue;
	if (obj)
		strValue = eval(obj).value;
	else
		strValue = obj;			
	if ((isNaN(strValue)) || (!CheckNull(obj))) {
		alert(msg);
		if (obj){
			eval(obj).value = '';
			eval(obj).focus();
		}
		return false;
	} else {
		return true;
	}
}

// Open Window 
// By: 
// Modified: kiemdv
// Date: 30/8/2003
function OpenWindow(strUrl,strWinname,intWidth,intHeight,intLeft,intTop){                
        intLeft = (screen.width) / 2 - intWidth/2;
        intTop = (screen.height) / 2 - intHeight/2;
		popUp = window.open(strUrl,strWinname, "width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft+ ",top=" + intTop+ ",menubar=no,resizable=yes,scrollbars=yes");
		popUp.focus()
}

// Open Window 
// By: 
// Modified: kiemdv
// Date: 30/8/2003
function OpenWindowFix(strUrl,strWinname,intWidth,intHeight,intLeft,intTop){
        intLeft = (screen.width) / 2 - intWidth/2;
        intTop = (screen.height) / 2 - intHeight/2;
		popUp = window.open(strUrl,strWinname, "width=" + intWidth + ",height=" + intHeight + ",left=" + intLeft+ ",top=" + intTop+ ",menubar=no,resizable=no,scrollbars=yes");		
		popUp.focus()
}


// Hoan doi mau nen cho mot dong trong Datagrid
function dtgSwapBG(obj, bgColor) {		
	var tmpColor;
	if (obj){
		tmpColor = obj.parentElement.parentElement.style.backgroundColor;		
		if (bgColor != tmpColor)
			oldColor = tmpColor;					
		obj.parentElement.parentElement.style.backgroundColor = (tmpColor==bgColor) ? oldColor:bgColor;
	}
}
// Print
function Print(){
	self.focus();
    setTimeout('self.print()', 1);
}

/* Check value is empty
	if obj's value is null return true 
	else return false
*/
function CheckNullInput(obj){	
    strValue=eval(obj).value;
    if (strValue == "") {
       return true;
    }
    else {
      Status = 0;
      for (i = 0; i < strValue.length; i++) {
        if (strValue.charAt(i) != " ") {
           Status = 1;
           break;                      
        }
      }         
      if (Status == 0) {          
	      return true;
      }
      else {
          return false;
      }
    }
}

function writeTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+"&nbsp;"+hour+":"+minute+" (GMT+7)")
}

// trim function
function trim(str){
	return 	str.replace(/^\s*|\s*$/g,"");
}

function writeTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	var hour = mydate.getHours()
	if (hour < 10)
		hour = "0" + hour
	
	var minute=mydate.getMinutes()
	if (minute < 10)
		minute = "0" + minute
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y")
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)")
}

function getTimeString(s)
{
	document.write("<span class=LargeTime2>");
	writeTime(s);
	document.write("</span>")
}


//Chinhtt addon
function CheckThisVote(field)
{   
	form = field.form;
	if (field.checked)
	{	    
		form.fvotefor.value = field.value;		
	}
	else
	{
		form.fvotefor.value = '';
		return;
	}

	for (i=0; i < form.elements.length - 2; i++)
	{
		if(form.elements[i].type=='checkbox')
			if (form.elements[i] != field)
				if (form.elements[i].checked)
					form.elements[i].checked = false;
	}
}
function SubmitVote(sform, saction)
{   //var PollId = sform.ctl00_ContentPlaceHolder_ascThamDoYKien_PollId.value;
   var PollId = sform.PollId.value;
	if (saction==0)
	{
		if (sform.fvotefor.value=='')
		{
			alert('Hãy chọn một trong các mục trước khi biểu quyết.');
			return;
		}
	}

	var form = sform;
	var j = 0
	for (i=0; i < form.elements.length - 2; i++)
		{
			if(form.elements[i].type=='checkbox'){
				j = j + 1
			}
		}
	var sheight = (j * 40) + 50;
	if (sheight < 250){
		sheight = 250;
	}	
	str = '/VoteAction/'+PollId + '.vnn?OptionId=' + sform.fvotefor.value; 
	open(str, sform.name, 'scrollbars=yes,resizeable=no,locationbar=no,width=500,height='+sheight+',left='.concat((screen.width - 500)/2).concat(',top=').concat((screen.height - 250)/2));
	
}
//Chinhtt write for cookie

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000)); 
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}	

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}