function isBlank(val) {
  if (val.split(" ").join("") == "") {
    return true;
  } else {
    return false;
  }
}

function chkNull(obj) {
    //try{
  switch (obj.type) {
    // text, password, file, textarea
    case "text" :
    case "password" :
    case "file" :
    case "textarea" :
    case "hidden" :

      if (isBlank(obj.value)) {
          return false;
      } else {
        return true;
      }
      break;
    // checkbox
    case "checkbox" :
      if (!obj.checked) {
          return false;
      } else {
        return true;
      }
      break;
    // radiobutton
    case "radio" :
      var obj_len = obj.length;

      for (i=0; i < obj_len; i++) {
        if (obj[i].checked == true)
          return false;
      }

      if (i == obj_len) {
        return true;
      }
      break;
  }

     // select list
  if (obj.type.indexOf("select") != -1) {
    if (obj.options[obj.selectedIndex].value == 0 || obj.options[obj.selectedIndex].value == ""){
      return false;
    }else{
      return true;
    }
  }

  return true;
    //}
    //catch(e)
    //{
    //    err_handle(e);
    //}
}

function nullChk(obj) {
	var str = obj.value; 
	str = str.replace(/^\s+|\s+$/,"");

	return str;
}

function isNumber(numval){
	for(i=0; i<numval.length; i++){
		str=numval.charCodeAt(i);
		if(str<48 || str>57)
			return false;
	}
	return true;
}	

function isEmail(str) {
	  // regular expression 
	  var supported = 0;
	  if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	  }
	  if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	  return (!r1.test(str) && r2.test(str));
}

function winOPC(url,popname,w,h) {
	var pop = window.open( url, popname, "width="+w+",height="+h+",left="+((screen.width - w)/2)+",top="+((screen.height - h)/2) + ",status=0,resizable=0, scrollbars=0");
	if(pop){
		pop.focus();
	}
}

function winOPC2(url,popname,w,h) {

	
	//var pop = window.open( url, popname, "width="+w+",height="+h+",left="+((screen.width - w)/2)+",top="+((screen.height - h)/5) + ",resizable=0, scrollbars=0");
	
	//if(pop)
		//pop.focus();
	
	var myString = url;
    var urlLink;
    var linkPop;
    
    var form = document.createElement("form");
    var urlPos = myString.indexOf("?");
    if (urlPos > -1) {
        urlLink = myString.substring(0, urlPos);
        linkPop = urlLink.substring(0, urlLink.lastIndexOf("/"));
        myString = myString.substring(urlPos + 1);
        form.setAttribute("name", "Prelisten");
        form.setAttribute("method", "POST");
        form.setAttribute("action", urlLink);
        form.setAttribute("target", "Prelisten");
    }
    var count = 0;
    while (count != 1) {
        var pos = myString.indexOf("&");
        var tmp;
        if (pos != -1) {
            tmp = myString.substring(0, pos);
            myString = myString.substring(pos + 1);
        }
        else {
            tmp = myString;
            count = 1;
        }
        var paramName;
        var paramValue;
        var eqPos = tmp.indexOf("=");
        if (eqPos != -1) {
            paramName = tmp.substring(0, eqPos);
            paramValue = tmp.substring(eqPos + 1);
            
        }
        else {
            continue;
        }
           // alert("position :" + pos + "     tmp:" + tmp + "       mystring:" + myString);
          //alert("paramName :" + paramName + "       paramValue:" + paramValue);
		if(paramName=="title"||paramName=="artist" ||paramName=="album" ){
			paramValue = decodeURI(paramValue);						
		}					
        var elem = document.createElement("input");
        elem.setAttribute("type", "hidden");
        elem.setAttribute("name", paramName);
        elem.setAttribute("value", paramValue);
        form.appendChild(elem);
    }
   
    var win = window.open(urlLink.substring(0, urlLink.lastIndexOf("/"))+"/index.jsp", "Prelisten", "width=" + w + ", height=" +
    	    h +
    	    ",left=" +
    	    ((screen.width - w) / 2) +
    	    ",top=" +
    	    ((screen.height - h) / 5) +
    	    ",resizable=0, scrollbars=0");
   
    var body = document.getElementsByTagName("body")[0];
    body.appendChild(form);
    form.submit();
    body.removeChild(form);
    
}

function winOPCS(url,popname, w,h) {
	var pop = window.open( url, popname, "width="+w+",height="+h+",left="+((screen.width/2)-200)+",top="+((screen.height/2)-200) + ",status=0,resizable=0, scrollbars=yes");
	if(pop)
	{
		pop.focus();
	}

}

function winOPCF(url,popname,w,h) {
	var pop = window.open( url, popname, "width="+w+",height="+h+",left="+((screen.width - w)/2)+",top="+((screen.height - h)/2) + ",status=0,resizable=0, scrollbars=0");
	if (pop) {
		pop.focus();
	}
}

function winRPCIE(w,h) {
	if(window.navigator.userAgent.indexOf("MSIE 7") != -1)
		self.resizeTo(w,h);
	else
		//self.resizeTo(w,h-36);
		self.resizeTo(w,h-11);
}

function alpha_chk(str) {
	var eval = "abcdefghijklmnopqrstuvwxyz0123456789";
	var chk_val;
	
	if (null_chk(str) == false) {return false;}
	else {
		for (var ii = 0 ; ii < str.length ; ii++) {
			chk_val = 0;
			for (var jj = 0 ; jj < eval.length ; jj++) {
				if (str.substring(ii,ii+1) == eval.substring(jj,jj+1)) {
					chk_val = 1;
					break;
				}
			}
			if (chk_val == 0) {
				return false;
			}
		}
	}
	return true;
}

function isNull(str)
{
	if (str == "") 
		return true;
		
	var len = str.length;
	for (var i = 0; i < len; i++)
	{
		if (str.substring(i,i+1) != " ") 
			return false;
	}
	
	return true;
}

function null_chk(str) {
	if (str.length == 0) {return false;}
	else {
		for (var ii=0 ; ii < str.length ; ii++) { 
			if (str.substring(ii, ii+1) == " ") {
				return false;
			}
		}
	}
	return true;
}

function fnChkLogin() {

	winOPCF('<%=contextPath%>/web/popup/check_pop.jsp?checkgubun=login','checkPop','270','130');
}


function chkPhoneFormat(Min, contextPath){
	var url1 = contextPath+"/web/popup/check_pop.jsp?checkgubun=invalidphonenum";
	var url2 = contextPath+"/web/popup/check_pop.jsp?checkgubun=invalidphonenumlength";
	if ((Min.value.substring(0,2)!="08") && (Min.value.substring(0,3)!="668"))
	{
		winOPC(url1, "checkPop", "270", "130");
		return false;	
	} 
	if (Min.value.length >= 11)
	{
		winOPC(url2, "checkPop", "270", "130");
		return false;
	} 
	return true;
}

function getContextPath(){
    var offset=location.href.indexOf(location.host)+location.host.length;
    var ctxPath=location.href.substring(offset,location.href.indexOf('/',offset+1));
    return ctxPath;
}

function transPhoneFormat(obj){
	var phoneNumber = obj.value;
	if (phoneNumber.substring(0,3) == "668"){
		phoneNumber = "08"+phoneNumber.substring(3);
	}
	obj.value=phoneNumber;
}

function toShare(description, imgPath)
{
	imgPath= 'http://www.dtacmusic.com' + imgPath;

	var message = '';
	var attachment = {
		'name': 'dtacmusic.com',
		'href': 'http://www.dtacmusic.com',
		'description': description,
		'media': [{ 'type': 'image', 'src': imgPath, 'href': 'http://www.dtacmusic.com'}]
		}; 
		var action_links = [{'text':'http://www.dtacmusic.com', 'href':'http://www.dtacmusic.com'}];  
		callPublish(message, attachment, action_links);
}

function callPublish(msg, attachment, action_link) {
	FB.ensureInit(function () {
		FB.Connect.streamPublish('', attachment, action_link);
	});
}