﻿function homepage(t){
	document.body.style.behavior="url(#default#homepage)";
	document.body.setHomePage("http://abc.com");
}

function bookmark(){
	try{
		var title = "abc Website";   
		var url = "http://abc.com";
	
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url, "");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title); }
		else if(window.opera && window.print) { // Opera Hotlist
			return true; 
		}
	}
	catch(e){}
}

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function checkWeb(web)
{
	if (web=="")
	{
		return false;
	}
	if(!isWebChar(web))
    	return false;
	if (web.indexOf("www")!=0  && web.indexOf("http://")!=0)
	{
		return false;
	}
	if (web.indexOf("www")==0  && web.indexOf("http://")>0)
	{
		return false;
	}
	if (web.indexOf(".")<0 ||(web.lastIndexOf(".")==web.length- 1))
	{
		return false;
	}
	if(web.split(".").length<3)
	{
		return false;
	}	
	return true;
}

function isWebChar(str){
  for (i=0; i<str.length; i++){
    c = str.charAt(i);          
	
    if("~!#$%^*(),\'`\;<>+\n\t \\\"".indexOf(c,0) > 0) {
      return false;
	}
  }
  return true;
}

function checkWebCustomValidator(oSrc, args){
    args.IsValid = checkWeb(args.Value);
}

function isValidEmail(obj){
	var str = obj.value;
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(str)){
    	return 0;
	}else{
	    return 1;
	}	
}

function isPhoneNumber(str) {
	var stringCharacter="1234567890-()+ .";
	var c = '';
	for (var i=0; i<str.length; i++)
	{
		c = str.charAt(i);          
		if (stringCharacter.indexOf(c,0)==-1)
			{return false;}
	}  
	return true;
}

function checkPhoneCustomValidator(oSrc, args){
    args.IsValid = isPhoneNumber(args.Value);
}

function isNumber(str) {
	var filter = new RegExp("^\\d{1,15}$"); 
	if (filter.test(str)) {
		return true;
	} else {
		return false; 	
	}
}

function isEmptyField(field) {
   if ((field.value==null)||(field.value.replace(/(^\s*)|(\s*$)/g, "").length==0)) {
      return true;
   } else { 
      return false; 
   }
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function validateMobile(obj){
	var str = obj.value;
	var filter = /^13\d{9}$/;
	if(filter.test(str)) return 0;
	return 1; 	
}

function compareDate(d1, m1, y1, d2, m2, y2)
{
	if (y1 > y2)
		return -1;
	if (y1 == y2 && m1 > m2)
		return -1;
	if (y1 == y1 && m1 == m2 && d1 > d2)
		return -1;
	if (y1 == y1 && m1 == m2 && d1 == d2)
		return 0;
	return 1;
}

function validateCheckCode(obj){
	var str = obj.value;
	var filter = /^[0-9a-zA-Z]{4}$/;
	if(filter.test(str)) return 0;
	return 1;
}

function checkByteLength(str, minlen, maxlen) {
	if (str == null) return false;
	var l = str.length;
	var blen = 0;
	for(i=0; i<l; i++) {
		if ((str.charCodeAt(i) & 0xff00) != 0) {
			blen ++;
		}
		blen ++;
	}
	if (blen > maxlen || blen < minlen) {
		return false;
	}
	return true;
}

function validateYear(obj){
	var str = obj.value;

	if(isNumber(str)) {
	   if(parseInt(str)>0 && parseInt(str)<9999)
	     return true;
	} 	
	return false;
}

function validateSameAs(obj){
	var v1,v2;
	if(!getAttrValueByName(obj,"sameas")) return true;
	v1=obj.value;
	v2=document.getElementById(getAttrValueByName(obj,"sameas")).value;
	if(v1 == v2) return true;
	return false;
}

function getAttrName(str){
	var s=str.split("=");
	return s[0];
}

function getAttrValue(str){
	var s=str.split("=");
	return s[1];
}

function getAttrValueByName(obj,str){
	var para;
	if(obj.id){
		if(eval(obj.id).p) para=eval(obj.id).p;
		else return;
	}else{
		return;
	}
	var s = para.split(",");
	for(var i=0;i<s.length;i++){
		if(getAttrName(s[i]) == str){
			if(getAttrValue(s[i]))
				return getAttrValue(s[i]);
			else
				return;
		}
	}
	return;
}

function SetUnicode(iStr){
	for (i=0, oStr=''; i < iStr.length; ){
		if (iStr.charCodeAt(i)==38){
			if (iStr.charCodeAt(i + 1)==35){
				p=iStr.indexOf(';', i  + 2);
				if (p!=-1){
					if (p - i <= 7){
						if (isFinite(iStr.substr(i + 2, p - i - 2))){
							oStr = oStr.concat(String.fromCharCode(iStr.substr(i + 2, p - i - 2)));
							i = p + 1;
							continue;
						}
					}
				}
			}

		}	
		oStr=oStr.concat(iStr.charAt(i));
		i++;
	}	
	return oStr;
}

function create_arr(str, aa) {
	st = 0;
	kk = 0;
	arr = new Array(aa + 1);
	for(ii = 0; ii < str.length; ii++) {
		if(str.charAt(ii) == '|') {
			arr[kk] = SetUnicode(str.substring(st, ii));
			st = ii + 1;
			kk++;
		}
	}
	arr[kk] = SetUnicode(str.substring(st, str.length));
	return arr;
}

function checkAll(NumberCheckBox, checkBoxId, checkBoxAllId){
    var objCheckBoxAll = document.getElementById(checkBoxAllId);
    for(i=0; i<NumberCheckBox; i++){
        var objCheckBox = checkBoxId +  "_" + ( i + "");
        document.getElementById(objCheckBox).checked = objCheckBoxAll.checked;
        return str;   
    }            
}

function isPhoneNumber(str) {
	var stringCharacter="1234567890-()+ .";
	var c = '';
	for (var i=0; i<str.length; i++)
	{
		c = str.charAt(i);          
		if (stringCharacter.indexOf(c,0)==-1)
			{return false;}
	}  
	return true;
}

function checkPhoneCustomValidator(oSrc, args){
    args.IsValid = isPhoneNumber(args.Value);
}
    
function openNewWindow(link){
    window.open(link);
}

function addClickedBanner(Id){
    WebService.AddClickQuangCao(Id,null,null);
}
   
function clickOnBanner(link, Id){
    openNewWindow(link);    
    addClickedBanner(Id);
}

function getById(Id){
    return document.getElementById(Id);
}

function findPosX(obj)
{
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

/*
WebService.AddClickQuangCao(Id,OnRequestComplete,OnError);
function OnRequestComplete(result)
{
    var obj = document.getElementById(AJAX_DISPLAY_DIV_ID);
    obj.innerHTML = result;            
}

function OnError(result)
{
    if(AJAX_DISPLAY_DIV_ID=="")
    {
        alert(result.get_message());
    }        
    else
    {
        var obj = document.getElementById(AJAX_DISPLAY_DIV_ID);        
        obj.innerHTML = "<b>" + result.get_message() + "</b>";        
    }       
}
*/



function initPrettyZoom(){               
    //$("a[class^='A_prettyzoom']").prettyPhoto();
    $("a[rel^='A_prettyzoom']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/' /* The separator for the gallery counter 1 "of" 2 */
	});

}

/* Use for Bao List */
function initPrettyZoomWithMouseOver(){                   
    $("a[rel^='A_prettyzoom']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/' /* The separator for the gallery counter 1 "of" 2 */
		
	});
}

function initPrettyZoomWithMouseOver_BaoKhuyenMai(){                   
    $("a[rel^='A_BaoKhuyenMai_prettyzoom']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		open_when_click : true, 
		open_when_mouseover : false
	});
}

function initPrettyZoom_BaoBanChay(){                   
    $("a[rel^='A_BaoBanChay_prettyzoom']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		open_when_click : true, 
		open_when_mouseover : false
	});
}

function hideAllFlash(){
/*
    var ele = document.getElementById("flash_top");
    if(ele){
        ele.style.visibility = "hidden";
    }
    
    ele = document.getElementById("flash_thuchuctet");
    if(ele){
        ele.style.visibility = "hidden";
    }
    */
}

function showAllFlash(){
/*
    var ele = document.getElementById("flash_top");
    if(ele){
        ele.style.visibility = "visible";
    }
    
    ele = document.getElementById("flash_thuchuctet");
    if(ele){
        ele.style.visibility = "visible";
    }
    */
}

function showMessage(header, message){    
    $.popup.show(header, message);
}   

function dialog_Load(url, title, options, fClass)
{
    var str = "<iframe frameborder='0' src='" + url + "' class='"+fClass+"'></iframe>";
    $.popup.show(title, str, options);    
}

function getCurrentDate(){
    var d = new Date();  
    var date = d.getDate();
    if(date * 1 < 10 ) date = "0" + date;  
    return date;        
}

function getCurrentMonth(){
    var d = new Date();        
    var month = ( d.getMonth() * 1 ) + 1;
    if(month * 1 < 10 ) month = "0" + month;
    return month;
}

function getCurrentYear(){
    var d = new Date();   
    var year =  d.getYear();   
    if (year < 1000) year+=1900 ;
    return year;    
}

