window.onload = function() {
  fixFlash(); }
  
function fixFlash() 
{
    objects = document.getElementsByTagName("object");
    for (var i = 0; i < objects.length; i++)
   	{
  		objects[i].outerHTML = objects[i].outerHTML;
	}
}


function CheckAll() {
	for (var i=0;i<document.form.elements.length;i++) {
    	var e = document.form.elements[i];
        if ((e.name != 'allbox') && (e.type=='checkbox')) {
          e.checked = document.form.allbox.checked;
        }
    }
}

var checkflag = "false";
function check(field) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
		return "Uncheck All"; 
	}
	else {
			for (i = 0; i < field.length; i++) {
				field[i].checked = false; 
			}
			checkflag = "false";
			return "Check All"; 
		}
}
function ajaxLoader(url,id) {
	var x = false
	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		x = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
				x = new ActiveXObject("Msxml2.XMLHTTP")
			} 
		catch (e){
					try {
							x = new ActiveXObject("Microsoft.XMLHTTP")
						}
					catch (e){}
		}
	}else
		return false;
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
        el = document.getElementById(id);
        el.innerHTML = x.responseText;
      }
    }
    x.open("GET", url, true);
    x.send(null);
  }
}
function LoadFrom2ComboBoxWithOneValue(obj1,obj2,obj3,obj4,obj5,obj6,start,status)
{
	var num= obj3.length;
	var arrItem=new Array();
	count=0;
	if (obj2.length>1)
	for (i=eval(start);i<obj2.length;i++)
		arrItem[count++]=obj2.options[i].value;
	var countItem=obj2.length;
	for (j=1;j<countItem;j++)
		{
			for (i=0;i<arrItem.length;i++)
				{
					if (obj2.options[j].value==arrItem[i])
						obj2.options[j]= null;
				}
			countItem=obj2.length;
		}
	if (obj1.value!=0)
	{
		for (i=0;i<num;i++){
			if (obj3[i].value==obj1.value)
				{
					newoption = new Option(obj4[i].value,obj5[i].value, false,false);
					obj2.options[obj2.length] = newoption;
				}
		}
	}
	
	if (eval(status)==1)
		for (i=0;i<obj2.length;i++)
		{
			if (obj2.options[i].value==obj6.value)
				obj2.options[i].selected=true;
		}
}

function doAdd(obj1,obj2)
{
	for (i=0;i<obj1.length;i++){
		if (obj1.options[i].selected){
			var selectedText = obj1.options[i].text;
			var selectedValue = obj1.options[i].value;
			var ite=true;
			for (j=0;j<obj2.length;j++)
			{
				thisItem=obj2.options[j].value;
				if (thisItem==selectedValue)
					{
						ite=false;
						break;
					}
			}
			if (ite==true)
			{
				newoption = new Option(selectedText, selectedValue, false,false);
				obj2.options[obj2.length] = newoption;
				//document.frmAddjob.location1.options[selectedItem] = null;
				//jobFee(document.frmAddjob.location2);
			}
		}
	}
}


function removeItem(obj)
{
	var arrItem=new Array();
	var count=0;
	var num=0;
	var boxlength=obj.length;
	for (i=0;i<boxlength;i++)
		{
			//var selectedItem = document.frmAddjob.location2.selectedIndex;
			if (obj.options[i].selected)
				arrItem[count++]=obj.options[i].value;
		}
	for (j=0;j<boxlength;j++)
		{
			for (k=0;k<arrItem.length;k++)
				if (obj.options[j].value==arrItem[k])
					{
						obj.options[j]=null;
					}
				boxlength=obj.length;
		}
}

// obj1 is a value list
//obj2 is a hidden keep value of list
function getvalue(obj1,obj2)
{
	var strValues = "";
	var boxLength = obj1.length;
	var count = 0;
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			if (count == 0) {
				strValues = obj1.options[i].value;
			}
			else {
					strValues = strValues + "," + obj1.options[i].value;
			}
			count++;
	   }
	}
	obj2.value=strValues;
	//alert(obj2.value);
}

function getValueListCheckBox(list,id)
{	
	if(list!=undefined){
	var num=list.length;
	if (num==undefined)
		id.value=list.value;
	else
		{
			count=0;
			str="";
			for (i=0;i<num;i++)
			{
				if (list[i].checked)
					{
						if (count==0)
							str=list[i].value;
						else
							str = str + ", " + list[i].value;
						count++;
					}
			}
		id.value=str;
       }
	}
	//alert(id.value);
}
function getValueListLocation(list,id,status)
{
	var num=list.length;
	if (num==undefined)
		id.value=list.value;
	else
		{
			count=0;
			str="";
			for (i=0;i<num;i++)
			{
				if (list[i].checked)
					{
						if (count==0)
							str=list[i].value;
						else
							str = str + ", " + list[i].value;
						count++;
					}
			}
						id.value=str;
		}
	if (id.value=="")	
		alert("Please select logo!");			
	else
		if (eval(status)>0)
			window.location="?act=ht_adm_logo_banner&stvl="+status+"&logo_id="+id.value;
}

function getsort(ck,tx,sortvl)
{
	var num=ck.length;
	if (num==undefined)
		sortvl.value=tx.value;
	else
		{
			count=0;
			str="";
			for (i=0;i<num;i++)
			{
				if (ck[i].checked && eval(tx[i].value)>=0)
					{
						if (count==0 )
							str=tx[i].value;
						else
							str = str + "," + tx[i].value;
						count++;
					}
			}
						sortvl.value=str;
		}
	/*if (sortvl.value=="")	
		alert("Please select logo!");			
	else
		window.location="?act=ht_adm_logo_banner&stvl="+status+"&logo_id="+id.value+"&sort="+sortvl.value;*/
}

function checkMail(object)
{
	var x = object;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function getLengthtextarear(item1,item2,num)
	{
		var str=item2.value;
		item1.value=eval(num)-eval(item2.value.length);
		if (item2.value.length>=eval(num))
		{
			//alert("Max Letters are "+num);
			item2.value=str.substring(0,eval(num));
			item1.value=eval(num)-eval(item2.value.length);
		}
	}
//strvalid=0123456789 -.()+EeXxTtNnSsIiOo:<br>/
function checkphone(obj,strvalid)
{
	if (obj!="")
	{											
		var str=obj;
		var valid=strvalid;
		var ok="yes";
		var temp;
		for (var i=0;i<str.length;i++){
			temp = "" +str.substring(i, i+1);
			if (valid.indexOf(temp) == -1) ok = "no";
		}
		if (ok == "no") {
			return false;
		}
	}
	return true;
}
function GetDate(dd,mm,yyyy,obj){
	var selectDate= dd.value;
	var day=0;
	var month=eval(mm.value);
	var Year=eval(yyyy.value);
	
		switch (month){
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12: 
					day=31; 
					break;
			case 4:
			case 6:
			case 9:
			case 11: 
					day=30; 
					break;
			case 2: 
					if (month>0 && Year>0){
						if ((Year%4==0 && Year%100!=0)||(Year%400==0))
								day=29;
							else
								day=28;
					}
					break;
		}
		// Delete all day of previous month
		if (month>0){
			boxlength=dd.length;
			for (i=0;i<boxlength;)
				{
					dd.options[i]=null;
					boxlength=dd.length;
				}
		}
		// Ket thuc
		for (i=1;i<=day;i++){
			if (i<10)
				gt="0"+i;
			else
				gt=i;
			if (eval(selectDate)==i)
				newoption=new Option(gt,gt,true,true);
			else
				newoption=new Option(gt,gt,false,false);
			dd.options[dd.length]=newoption;
		}
		if (selectDate>day)
			dd.options[0].selected;
		obj.value=yyyy.value+"-"+mm.value+"-"+dd.value;
}

//obj la gia tri khoi tao
function Begin(dd,mm,yyyy,obj,numyear){
	var date=new Date();
	if ((obj.value==""||obj.value=="0000-00-00") && numyear==0)
		obj.value=date.getYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	else
		if (obj.value=="0000-00-00" && numyear==1)
			obj.value="1945-02-14";//

	var str=obj.value;
	
	var arrDate=new Array();
	arrDate=str.split("-");
	numday=0;
	//alert(numyear+arrDate[0]+date.getYear());
	if (numyear>0)
		for(i=0;i<=42;i++)
			{
				newoption=new Option(eval(arrDate[0]-30)+i,eval(arrDate[0]-30)+i,false,false);
				yyyy.options[yyyy.length]=newoption;
			}
	else
		for(i=0;i<=5;i++)
			{
				newoption=new Option(eval(arrDate[0])+i,eval(arrDate[0])+i,false,false);
				yyyy.options[yyyy.length]=newoption;
			}
	switch(eval(arrDate[1])){
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12: 
					numday=31; 
					break;
			case 4:
			case 6:
			case 9:
			case 11: 
					numday=30; 
					break;
			case 2: 
						if ((arrDate[0]%4==0 && arrDate[0]%100!=0)||(arrDate[0]%400==0))
								numday=29;
							else
								numday=28;
					break;
	}
	for (i=1;i<=numday;i++)
		{
			if (i<10)
				gt="0"+i;
			else 
				gt=i;				
			newoption=new Option(gt,gt,false,false);
			dd.options[dd.length]=newoption;
		}
	for (i=1;i<=12;i++)
		{
			if (i<10)
				gt="0"+i;
			else 
				gt=i;	
			switch (i)
			{
				case 1: 
					vttext='Jan';
					break;
				case 2:
					vttext='Feb';
					break;
				case 3:
					vttext='Mar';
					break;
				case 4: 
					vttext='Apr';
					break;
				case 5:
					vttext='May';
					break;
				case 6:
					vttext='Jun';
					break;
				case 7: 
					vttext='Jul';
					break;
				case 8:
					vttext='Aug';
					break;
				case 9:
					vttext='Sep';
					break;
				case 10: 
					vttext='Oct';
					break;
				case 11:
					vttext='Nov';
					break;
				case 12:
					vttext='Dec';
					break;
			}
			newoption=new Option(vttext,gt,false,false);
			mm.options[mm.length]=newoption;
		}
	// Get default value of yyyy/mm/dd
	
	for (i=0;i<yyyy.length;i++)
		{
			if (yyyy.options[i].value==arrDate[0])
				yyyy.options[i].selected=true;
		}
	for (i=0;i<mm.length;i++)
		{
			if (eval(mm.options[i].value)==eval(arrDate[1]))
				mm.options[i].selected=true;
		}
	for (i=0;i<dd.length;i++)
		{
			if (eval(dd.options[i].value)==eval(arrDate[2]))
				dd.options[i].selected=true;
		}
	obj.value=yyyy.value+"-"+mm.value+"-"+dd.value;
	
}
function categoryOnchane(sl_1,sl_11,sl_2,sl_22,sl_3,sl_33,type) {
		
		switch(type) {		
			case 1: {							
				if(eval(sl_1).value!="0") {
					eval(sl_11).disabled = false;
					eval(sl_2).disabled = false;
				}else {
					eval(sl_11).selectedIndex = 0;	
					eval(sl_2).selectedIndex = 0;
					eval(sl_22).selectedIndex= 0;
					eval(sl_3).selectedIndex= 0;
					eval(sl_33).selectedIndex = 0;
					
					eval(sl_11).disabled = true;
					eval(sl_2).disabled = true;
					eval(sl_22).disabled= true;
					eval(sl_3).disabled = true;
					eval(sl_33).disabled = true;
				}
				break;	
			}
			case 2: {			
				if(eval(sl_2).value!="0") {
					eval(sl_22).disabled = false;
					eval(sl_3).disabled= false;
				}else {								
					eval(sl_22).selectedIndex = 0;
					eval(sl_3).selectedIndex = 0;
					eval(sl_33).selectedIndex = 0;	
						
					eval(sl_22).disabled = true;
					eval(sl_3).disabled = true;
					eval(sl_33).disabled = true;
				}
				break;	
			}
			case 3: {			
				if(eval(sl_3).value!="0") {
					eval(sl_33).disabled = false;					
				}else {						
					eval(sl_33).selectedIndex= 0;				
					eval(sl_33).disabled = true;
				}
				break;	
			}

		}
	}
	
	function ViewImage(ifile,ix,iy,ititle) { 
		var win;
		var sWidth;
		var sHeight;
		var NS = (document.layers) ? 1 : 0;
		win = window.open("","imageviewer","width="+ix+",height="+iy+",menubar=no,toolbar=no");
	if (NS) {
		sWidth = win.innerWidth;
		sHeight = win.innerHeight;
	} else {
		sWidth = win.document.body.clientWidth;
		sHeight = win.document.body.clientHeight;
	}
	if(sWidth!=ix || sHeight!=iy) {
		win.close();
		setTimeout("ViewImage('"+ifile+"',"+ix+","+iy+",'"+ititle+"')", 250);
		return;
	}
		win.document.open();
		win.document.write("<html><head><title>"+ititle+"</title>");
		win.document.write("</head><body>");
		win.document.write('<div style="position:absolute;width:'+ix+'px;height:'+iy+'px;left:0px;top:0px">');
		win.document.write("<img src="+ifile+"></div></body></html>");
		win.document.close();
	}
	
	//close window without confirm
	function closeWindow(){
		window.open('','_self','');
		window.close();
	}

function showPicFillter() 
{
	for(jp=0;jp<bp;jp++)
	{
		//n=Math.round(Math.random()*22);
		/*document.piclink.logo[jp].style.filter='revealTrans(duration=n)';
		document.piclink.logo[jp].style.filter='revealTrans(transition=n)';
		document.piclink.logo[jp].filters.revealTrans.apply();*/
		document.piclink.logo[jp].src = "images/logos/"+document.piclink.pic[kp].value;
		document.links[poslg-bp+jp].href=document.piclink.linkpage[kp].value;
		//document.piclink.logo[jp].filters.revealTrans.Play();
		kp++;
		if (kp==ap)
			kp=0;
	}
	setTimeout('showPicFillter()', Speed);
}

function showPicFillter1() 
{
	for(j=0;j<b;j++)
	{
		//n=Math.round(Math.random()*22);
		/*document.piclink.logo[j].style.filter='revealTrans(duration=n)';
		document.piclink.logo[j].style.filter='revealTrans(transition=n)';
		document.piclink.logo[j].filters.revealTrans.apply();*/
		document.piclink.logo[j].src = "images/logos/"+document.piclink.pic[k].value;
		document.links[pos-b+j].href=document.piclink.linkpage[k].value;
		//document.piclink.logo[j].filters.revealTrans.Play();
		k++;
		if (k==a)
			k=0;
	}
	setTimeout('showPicFillter1()', Speed);
}

function showPicPartner() 
{
	var pospn=document.links.length;
	for(jpn=0;jpn<bpartner;jpn++)
	{
		//n=Math.round(Math.random()*22);
		/*document.partner.logopartner[jpn].style.filter='revealTrans(duration=n)';
		document.partner.logopartner[jpn].style.filter='revealTrans(transition=n)';
		document.partner.logopartner[jpn].filters.revealTrans.apply();*/
		document.partner.logopartner[jpn].src = "images/logos/"+document.partner.picpartner[kpartner].value;
		document.partner.logopartnerover[jpn].src = "images/logos/"+document.partner.picpartnerover[kpartner].value;
		document.links[pospn-bpartner+jpn].href=document.partner.linkpagepartner[kpartner].value;
		//document.partner.logopartner[jpn].filters.revealTrans.Play();
		//alert (document.links[pospn-bpartner+jpn].href);
		kpartner++;
		if (kpartner==apartner)
			kpartner=0;
	}
	//alert(apartner + ' ' + bpartner+ ' '+ pospn);
	if (eval(apartner)>5)
		setTimeout('showPicPartner()', Speedpartner);
}

function writeObject(pic,hrf)
{
	var arr=pic.split('.');
	
	if (arr[1]=='jpg' || arr[1]=='JPG' || arr[1]=='gif' || arr[1]=='GIF')
	{
		str='<a href="'+hrf+'"><img src="images/logo_av/'+pic+'" border="0"></a>';
	}
	else
	{
		str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="190" height="142">';
        str+='<param name="movie" value="images/logo_av/'+pic+'">';
        str+='<param name="quality" value="high">';
        str+='<embed src="images/logo_av/'+pic+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="190" height="142"></embed>';
        str+='</object>';
	}
	return str;	
}

function writeObjectHeader(pic,hrf)
{
	var arr=pic.split('.');
	
	if (arr[1]=='jpg' || arr[1]=='JPG' || arr[1]=='gif' || arr[1]=='GIF')
	{
		str='<a href="'+hrf+'"><img src="images/logo_av/'+pic+'" border="0"></a>';
	}
	else
	{
		str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="545" height="70">';
        str+='<param name="movie" value="images/logo_av/'+pic+'">';
        str+='<param name="quality" value="high">';
        str+='<embed src="images/logo_av/'+pic+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="545" height="70"></embed>';
        str+='</object>';
	}
	return str;	
}

function LeftAdvertiseBig() 
{
		str=writeObject(RefValBig[kb][0],RefValBig[kb][1]);
		document.getElementById('advLeftBig').innerHTML=str;
		kb++;
		if (kb==RefValBig.length)
			kb=0;
	setTimeout('LeftAdvertiseBig()', Speed1);
}

function LeftAdvertiseSmall() 
{
		str=writeObject(RefValSmall[l][0],RefValSmall[l][1]);
		document.getElementById('advLeftSmall').innerHTML=str;
		l++;
		if (l==RefValSmall.length)
			l=0;
	setTimeout('LeftAdvertiseSmall()', Speed2);
}

function AdvertiseBottom() 
{
		str=writeObject(RefValBottom[ab][0],RefValBottom[ab][1]);
		document.getElementById('advBottom').innerHTML=str;
		ab++;
		if (ab==RefValBottom.length)
			ab=0;
	setTimeout('AdvertiseBottom()', Speed3);
}

function AdvertiseHeader() 
{
		str=writeObjectHeader(RefValHeader[ah][0],RefValHeader[ah][1]);
		document.getElementById('advHeader').innerHTML=str;
		ah++;
		if (ah==RefValHeader.length)
			ah=0;
	setTimeout('AdvertiseHeader()', Speed4);
}

function submitEvents(page)
{
	document.events.page.value=page;
	document.events.submit();
}

function locationEvents(page)
{
	//document.events.page.value=page;
	window.location='?act=my_events&page='+page+'&mn=5_2&mn1=18_2';
}