/*Copyright LINE Communications 2005*/



function _common(){}
_common.prototype={



alert_errors:true,
debug_enabled:true,
default_popup_width:200,
default_popup_height:200,



include:function(path){
document.write("<script type=\"text/javascript\" src=\""+path+"\"><"+"/script>");
},
load_css:function(path){
if(document.createStyleSheet) document.createStyleSheet(path);
else{
var link_elem=document.createElement('link');
link_elem.rel='stylesheet';
link_elem.type='text/css';
link_elem.href=path
link_elem.media='screen' 
document.getElementsByTagName('head')[0].appendChild(link_elem);
}
},
find:function(id,frame,parent){

if(parent==null){
if(frame!=null&&top[frame])
var source=top[frame].document;
else var source=document;
if(!source){
this.error('find','Cannot find ['+id+']');
return null;
}
}else{
var source=parent;
}

if(source.getElementById&&source.getElementById(id)) return source.getElementById(id);
if(source.layers){
if(source.layers[id])  return source.layers[id];
if(source.forms[id])   return source.forms[id];
if(source.links[id])   return source.links[id];
if(source.images[id])  return source.images[id];
if(source.anchors[id]) return source.anchors[id];
if(source.embeds[id])  return source.embeds[id];

for(var index=0;index<source.forms.length;index++)
if(source.forms[index].elements[id]) return source.forms[index].elements[id];
}
if(source.childNodes)
for(var index=0;index<source.childNodes.length;index++)
if(source.childNodes[index].id==id||source.childNodes[index].name==id) return source.childNodes[index];
if(source.all&&source.all[id]) return source.all[id];

if(source.layers)
var elements=source.layers;
else if(source.childNodes)
var elements=source.childNodes;
else
var elements=new Array();
var elem=null;
for(var index=0;!elem&&index<elements.length;index++){
if(elements[index].document&&elements[index].document.layers) elem=this.find(id,null,elements[index].document);
else if(typeof elements[index].tagName!='undefined') elem=this.find(id,null,elements[index]);
}
return elem;
},
redirect:function(url,target){
if(target==null) target=document;
if(target.location==null){
this.error('redirect','No location member');
return;
}
this.debug_message('redirect','redirecting to '+url);
target.location=url;
},
popup:function(filename,title,w,h,x,y,scrollbars,statusbar,resize,toolbar){
if(!w||isNaN(parseInt(w))) w=this.default_popup_width;
if(!h||isNaN(parseInt(h))) h=this.default_popup_height;
if(!x||isNaN(parseInt(x))||x=='c') x=Math.round((screen.width/2)-(parseInt(w)/2));
if(!y||isNaN(parseInt(y))||y=='c') y=Math.round((screen.height/2)-(parseInt(h)/2));
if(scrollbars==null) var scrollbars=1;
if(statusbar==null) var statusbar=0;
if(resize==null) var resize=0;
if(toolbar==null) var toolbar=0;
this.debug_message('popup','opening popup '+filename);
this.debug_message('popup','status='+statusbar+',scrollbars='+scrollbars+',resizable='+resize+',toolbar='+toolbar+',menubar='+toolbar+',width='+w+',height='+h+',left='+x+',top='+y);
new_window=window.open(filename,title,'status='+statusbar+',scrollbars='+scrollbars+',resizable='+resize+',toolbar='+toolbar+',menubar='+toolbar+',width='+w+',height='+h+',left='+x+',top='+y);
if(!new_window.opener&&navigator.appVersion.indexOf('MSIE 5')==-1) new_window.opener=self;
return new_window;
},
random:function(min,max){
if(!min||isNaN(parseInt(min))) min=0;
if(!max||isNaN(parseInt(max))) max=1;
return(round(Math.random()*(parseInt(min)-parseInt(max)))+parseInt(min));
},
get_by_id:function(id,array){
for(var index=0;index<array.length;index++) 
if(array[index].id==id) return array[index];
return null;
},
contains:function(needle,haystack){
for(var item in haystack) 
if(haystack[item]==needle) return true;
return false;
},
undefined:function(item){return typeof(item)=='undefined';},
flexible_param:function(param,def){
if(this.undefined(def)||def==null||typeof(def)!='object'||def.constructor!=Array) def=new Array();
if(this.undefined(param)||param==null) param=def;
if(typeof(param)=='string'){
if(param.replace(/\s*/gi,'')=='') param=def;
else param=param.split(',');
}
if(typeof(param)!='object'||param.constructor!=Array) param=def;
for(var index=0;index<param.length;index++) param[index]=param[index].replace(/^\s*|\s*$/gi,'');
return param;
},
set_alert_errors:function(value){this.alert_errors=value;},
set_debug_enabled:function(value){this.debug_enabled=value;},
error:function(fn,error){
if(fn==null||fn=='') var fn='unknown';
if(error==null||error=='') var error='Unknown Error';
if(this.alert_errors) alert('ERROR in '+fn+'() : '+error);
},
debug_message:function(fn,message){
if(fn==null||fn=='') var fn='unknown';
if(message==null||message=='') var message='unknown debug';
if(this.debug_enabled) alert(fn+'() : '+message);
}
}
