﻿var imgServer = 'http://localhost/cweb/';

String.prototype.trim = function() { //Trim ambas direcciones
   return this.replace(/^[ ]+|[ ]+$/g,"");
}

String.prototype.tripSpace = function() { //Trim ambas direcciones
   return this.replace(/(\s\s+)/g, " ");
	 //replace(/^[ ]+|[ ]+$/g,"");
}

//Kiem tra ki tu dac biet
function existsSpecialChars(str)
{
		//var re = /^[0-9a-zA-Z ]*$/;
		/*
		var re = /([!@#$%^&*]$/;
		str = str.trim();
		var pos = str.search(re);
		if(pos == -1)
			return false;
		else
			return true;
		*/
}	

//Kiem tra URL
function isURL(str) {
	var pattern = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789/~:";
	if (str.length > 0) {
		if (str.length < 5 ) {
			return false;
		} else {
			if (str.lastIndexOf(".") == -1) { 											// khong tim thay dau cham
				return false;
			} else {
				if (str.lastIndexOf(".") == (str.length - 1)) return false;				// dau cham nam o cuoi cung
//				if (!isAlpha(str.charCodeAt(str.lastIndexOf(".") + 1))) return false;	// sau dau cham khong phai ki tu Alphabet
			}
			for (var c=0; c<pattern.length; c++) {
				if (pattern.indexOf(str.charAt(c),0) == -1) return false;				// ki tu khong hop le
			}
		}
	}
	return true;	
}

//Open popup
function openWindow(filename, winname, width, height, feature) {
	var features, top, left;
	var reOpera = /opera/i ;
	var winnameRequired = ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) || reOpera.test(navigator.userAgent));
	
	left = (window.screen.width - width) / 2;
	top = (window.screen.height - height) / 2;	
	if(feature == '')
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + ",status=0,location=0";
	else
		features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left + "," + feature;
//	if(!winnameRequired)	winname = "";
	newwindow = window.open(filename,winname,features);
	newwindow.focus();
}
//
//Cookie
function GetCookie(sName)
{
  // cookies are separated by semicolons
 var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function cfmDelete(msg)
{
    if( confirm('Are you sure you want to delete: '+ msg+' ?')==false)
    {
        try
        {
            window.event.returnValue = false;
        }
        catch(err){}
        return false;
    }
    return true ;
}

function delAll(msg,l,type,id)
{
//Setup_History
//"window.open('<%=VatLid.Variables.sWebRoot%>ConfirmDelete.aspx?setType=<%# DataBinder.Eval(Container.DataItem,"setType")%>&callerName=<%# DataBinder.Eval(Container.DataItem,"callerName")%>&callerNumber=<%# DataBinder.Eval(Container.DataItem,"callerNumber")%>&settingID=<%# DataBinder.Eval(Container.DataItem,"settingID")%>','','top=100,left=200,height=300,width=300,scrollbars=0,toolbar=0')"
    if(cfmDelete(msg)==false) return;
    var url="delAll.aspx?l="+l+"&type="+type+"&id="+id;
    window.open(url,'','top=0,left=0,height=10,width=10,scrollbars=0,toolbar=0');
}

function openCate(type,l,key)
{
    var url;
    if (type=="l")
        url="listcategory.aspx?l="+l+"&catid="+key;    
    else if (type=="s")
        url="listcategory.aspx?l="+l+"&catid=search&key="+key;
    else
        url="index.aspx?l="+l;
    window.location = url;
}

function selectAct(type,id)
{
    var url,size
    switch(type)
    {
          //PlayName
           case "PopSmsUsers":
            url='Users/PopsmsUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          case "PopSmsUsersDK":
            url='Users/PopsmsUsersDK.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
           case "PlayName":
            url='Users/PlayName.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          case "PopNameUsers":
            url='Users/PopNameUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          case "PopNameReceiverID":
            url='Users/PopNameReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;

        case "PopFullUsersNG":
            url='Users/PopFullUsersNG.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopFullReceiverIDNG":
            url='Users/PopFullReceiverIDNG.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         
            
        //full
         case "PlayDigital":
            url='Users/PlayDigital.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
        
         case "PopFullUsers":
            url='Users/PopFullUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopFullReceiverID":
            url='Users/PopFullReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         
         case "PopFullView":
            url='Users/PopFullView.aspx?id='+id;
            size='top=100,left=300,height=410,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
         case "PopFullViewNG":
            url='Users/PopFullViewNG.aspx?id='+id;
            size='top=100,left=350,height=430,width=350,scrollbars=0,toolbar=0,location=0';
            break;
         
         //crbt
          case "PlayCrbt":
            url='Users/PlayCrbt.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopCrbtReceiverID":
            url='Users/PopCrbtReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopCrbtUsers":
            url='Users/PopCrbtUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
         
           //Ring
         case "PopRingReceiverID":
            url='Users/PopRingReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopRingUsers":
            url='Users/PopRingUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PlayTrue":
            url='Users/PlayTrue.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
          case "PopStoryReceiverID":
            url='Users/PopStoryReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopStoryUsers":
            url='Users/PopStoryUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PlayStory":
            url='Users/PlayStory.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
        case "PopRadioReceiverID":
            url='Users/PopRadioReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopRadioUsers":
            url='Users/PopRadioUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PlayRadio":
            url='Users/PlayRadio.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         
         
        case "PopGift":
            url='Users/PopGift.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
            
         case "PopVideoReceiverID":
            url='Users/PopVideoReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopVideoUsers":
            url='Users/PopVideoUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
         case "PopFlashReceiverID":
            url='Users/PopFlashReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          
         case "Pop3gpReceiverID":
            url='Users/Pop3gpReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
              
         case "PopFlashUsers":
            url='Users/PopFlashUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
         case "Pop3gpUsers":
            url='Users/Pop3gpUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;   
         
         //Game   
         case "PopGameReceiverID":
            url='Users/PopGameReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopGameUsers":
            url='Users/PopGameUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         
         //Wap
         case "PopWapListReceiverID":
            url='Users/PopWapListReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopWapListUsers":
            url='Users/PopWapListUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
               
         //photo
          case "PopPhotoReceiverID":
            url='Users/PopPhotoReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
         case "PopPhotoUsers":
            url='Users/PopPhotoUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          case "PopPhotoView":
            url='Users/PopPhotoView.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
          case "PopFlashView":
            url='Users/PopFlashView.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
          
          case "Pop3gpView":
            url='Users/Pop3gpView.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
            
          case "PopThiepNhacUsers":
            url='Users/PopThiepNhacUsers.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;  
          case "PopThiepNhacReceiverID":
            url='Users/PopThiepNhacReceiverID.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;  
            
        case "login":
            url='Users/login.aspx';
            size='top=100,left=200,height=250,width=300,scrollbars=0,toolbar=0,location=0';
            break;
        case "Change":
            url='Users/Change.aspx';
            size='top=100,left=200,height=250,width=300,scrollbars=0,toolbar=0,location=0';
            break;
            
         case "Forget":
            url='Users/Forget.aspx';
            size='top=100,left=200,height=250,width=300,scrollbars=0,toolbar=0,location=0';
            break;
         case "Register":
            url='Users/Register.aspx';
            size='top=100,left=200,height=250,width=270,scrollbars=0,toolbar=0,location=0';
            break;
         
         default:
            url= "Users/" + type + '.aspx?id='+id;
            size='top=100,left=300,height=400,width=400,scrollbars=0,toolbar=0,location=0';
            break;
                     
    }
    if (size=='')window.open(url);
    else window.open(url,'',size)
}

function CloseRefreshParent(controlName)
{
  if (opener && !opener.closed) {
    var x = opener.document.getElementById(controlName);
    if (x) {
      x.value = "True";
      opener.document.forms[0].submit();
    }
  }
  window.close();
}

function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}
function setHomePage(){
    if(document.all){
        var homepage = document.getElementById('DailyID');
        if(!homepage)
            return;
        var ishp = false;
        for(var i=0;i<ZingD.length;i++)                     /*Check homepage*/
        {
            if(homepage.isHomePage('http://dailyinfo.vn/'))
            {
                ishp = true;
                break;
            }
        }  
        if(!ishp){
            homepage.style.behavior='url(#default#homepage)';            
            homepage.setHomePage(url);                  /*Set homepage*/
        }
    }
    else
        alert('Chọn Tools > Option > Main > Use Current Page (Alt+C) để đặt trang chủ!');
};

