function getvalue(objName,objLabel,datatype){
  var obj=document.me.elements[objName],value="";
  if (datatype.indexOf("choosebox")==0 || datatype.indexOf("selected")==0){
    obj.value="";
    var _obj=document.me.elements["_y"+objName]; 
    for(var i = 0; i < _obj.length; i++) {
       obj.value += (i==0)?_obj.options[i].value:("," + _obj.options[i].value);
    }
  }

  if (datatype.indexOf("PriceList")==0){
    value="";
    if (!(obj.length==1 && obj.options[0].value==0)) {
      for (var i=0; i<obj.length;i++) {
         var theText=obj.options[i].text, theValue=obj.options[i].value;
         var pos=theValue.lastIndexOf("[");
         pos=(pos==-1?theValue.length:pos)
         value+=theText + theValue.substr(pos) + '|~|'    // |~| is delimeters
      }
    }
    document.me.elements['`PriceList'].value=value;
  }
 
  if (datatype.toLowerCase().indexOf("bitcheckbox")==0){
    value=0; 
    for (var i=0;i<document.me.elements.length;i++){
      var e=document.me.elements[i];       
      if (e.name == "_"+objName)
        if (e.checked) value=value+eval(e.value);         
    }
    if(value==0) value=''; 
    obj.value=value;
  }

  if (datatype.toLowerCase().indexOf("multicombo")==0){
    value=""; 
    var patternname="_"+objName+":";
    for (var i=0;i<document.me.elements.length;i++){
      var e=document.me.elements[i];      
      if (e.name.indexOf(patternname)==0){
        value=value+'<item id="'+e.name.substr(e.name.indexOf(':')+1)+'">'+e.value+'</item>\n';
      }
    }
    obj.value=value;
  }

  return true;
}

function pickadate(sessionid,objName,wkday){
  oDate=new Date(document.me.elements[objName].value);
  if (isNaN(oDate)) oDate=new Date();    
  if(wkday==null) wkday='' //oDate.getDay();
  var prog="/asp/_calendar/dateFunc.asp?sessionID="+sessionid+"&Obj="+objName+"&Year="+oDate.getFullYear()+"&Month="+eval(oDate.getMonth()+1)+"&amp;wkday="+wkday;
  window.open(prog,"pickadate","width=200,height=150,resizable=no,status=no,left=200,top=200");
}

function datetimeselector(sessionid,objName){
  oDate=new Date(document.me.elements[objName].value);
  if (isNaN(oDate)) oDate=new Date();    
  var prog="/asp/_calendar/dateFunc.asp?sessionID="+sessionid+"&Obj="+objName+"&Year="+oDate.getFullYear()+"&Month="+eval(oDate.getMonth()+1)+"&TimeFormat=0";
  window.open(prog,"datetimeselector","width=200,height=200,resizable=no,status=no,left=200,top=200");
}

function pricebuilder(sessionid,objName,unitName) {
  var unitObj=document.me.elements[unitName],priceUnit="";
  if(unitObj.length>0) priceUnit=(unitObj.selectedIndex==-1)?unitObj.options[0].value:unitObj.options[unitObj.selectedIndex].value;  
  var URL="/asp/_emailaddress/listbuilder.asp?sessionID=" + sessionid + "&PriceUnit=" + priceUnit + "&returnObj=" + objName + "&Title=Price List&TextTitle=Name&ValueTitle=Price&lines=10&rowID=0&RsrcType=1340&datatype=float";
  var ListDuilder=window.open(URL,"ListDuilder","width=400,height=260,resizable=yes,status=no");
}

function DoAfterCombo(ComboName) {  
  var CountryID, CountryCombo, taskstatus, taskcomplete;

  if (ComboName == '~Prov_State') CountryCombo=document.me.elements['~Country'];
  if (ComboName == '~prov_state') CountryCombo=document.me.elements['~country'];
  if (ComboName == '~otherprov_state') CountryCombo=document.me.elements['~othercountry'];

  // Task Manager
  if ((ComboName=='`status')||(ComboName=='`complete')) {
    if (document.me.elements['`status'])   taskstatus=document.me.elements['`status'];
    if (document.me.elements['`complete']) taskcomplete=document.me.elements['`complete'];
    if (ComboName=='`status') {
      xValue=taskstatus.options[taskstatus.selectedIndex].value;
      if (taskcomplete != null) {
        if (xValue==1) taskcomplete.options[0].selected=true;   //Not Started
        if (xValue==3) taskcomplete.options[20].selected=true;  //Completed
      }
    }
    if (ComboName=='`complete') {
      xValue=taskcomplete.options[taskcomplete.selectedIndex].value;
      if (taskstatus != null)
        if (xValue != 0 && xValue != 100) taskstatus.options[1].selected=true; //In Progress
        if (xValue==0)   taskstatus.options[0].selected=true;
        if (xValue==100) taskstatus.options[2].selected=true;
    }
  }

  if (CountryCombo != null){
    var StateCombo = document.me.elements[ComboName];
    if (StateCombo.options[StateCombo.selectedIndex].value <= 13)
      CountryID='40'
    else
      CountryID='223';

    for(var i=0; i < CountryCombo.options.length; i++){
      if(CountryCombo.options[i].value==CountryID){
        CountryCombo.options[i].selected=true;
        break;
      }
    }
  }
}

function DoAfterIconCombo(ComboName) {  
  var CountryID,CountryCombo;

  if (ComboName == '~Prov_State') CountryCombo=document.me.elements['~Country'];
  if (ComboName == '~prov_state') CountryCombo=document.me.elements['~country'];
  if (ComboName == '~otherprov_state') CountryCombo=document.me.elements['~othercountry'];

  if (CountryCombo != null){
    var StateCombo = document.me.elements[ComboName];
    if (StateCombo.options[StateCombo.selectedIndex].value <= 13)
      CountryID='40'
    else
      CountryID='223';

    for(var i=0; i < CountryCombo.options.length; i++){
      if(CountryCombo.options[i].value==CountryID){
        CountryCombo.options[i].selected=true;
        break;
      }
    }
  }

  var elementname=ComboName+"~icon";
  var src=document.me.elements[elementname].src;
  src=src.substr(0,src.lastIndexOf("/")+1).concat(document.me.elements[ComboName].value,".gif"); 
  document.me.elements[elementname].src=src;
}


function DoAfterThumbnailCombo(ComboName) {  
  var elementname=ComboName+"~thumbnail";
  var src=document.me.elements[elementname].src;
  src=src.substr(0,src.lastIndexOf("/")+1).concat(document.me.elements[ComboName].value); 
  document.me.elements[elementname].src=src;
}

function trim(sValue){
  while (1==1){
  if (sValue=="") sValue=null;
  if (sValue==null || (sValue.charAt(0)!=" " && sValue.charAt(sValue.length-1)!=" ")) break;
  if (sValue.charAt(0)==" ") sValue=sValue.substring(1,sValue.length);
  if (sValue.charAt(sValue.length-1)==" ") sValue=sValue.substring(0,sValue.length-1);
  }
  return sValue;
}

function valid(sValue, validString){
  if (trim(sValue)==null) return true;
  for (var i=0; i<sValue.length; i++)
  if ((validString.toUpperCase()).indexOf((sValue.toUpperCase()).charAt(i))<0) return false;
  return true;
}

function inputCheck(sObj,tag,validStr) {  //  tag='integer/float/string'  // if tag='string' validStr is needed
  if (sObj==null) return false;
  if (validStr==null) validStr='';
  if (trim(tag)==null) {tag='INTEGER' } else {tag=tag.toUpperCase()};
  if (tag=='ANY') return true;
  if (tag=='INTEGER') {validStr='0123456789'}  else if (tag=='FLOAT') {validStr='.0123456789'} else {validStr=validStr.toUpperCase()};
  var sValue=sObj.value;
  if (trim(sValue)==null)   { if ((tag=='INTEGER') || (tag=='FLOAT')) {sValue=0} else {sValue=''}};
  if (! valid(sValue, validStr)) {
   if ((tag!='INTEGER') && (tag!='FLOAT')) {
    alert('Invalid input, the valid characters are:['+validStr+']!');
    sObj.select();
    sObj.focus(); 
    return false
   };
  }
  if (tag=='INTEGER')  sObj.value=isNaN(sValue)?(isNaN(parseInt(sValue))?'':Math.abs(parseInt(sValue))):Math.abs(parseInt(sValue));
  if (tag=='FLOAT')  sObj.value=isNaN(sValue)?(isNaN(parseFloat(sValue))?'':Math.abs(parseFloat(sValue))):sValue;
  return true;
}

function ImageUpload(name){
 upload= '/api/webstorage/uploading_g.asp?imgpath=&imgtype=3&elmname='+name&"&sessionid="+document.me.elements['SessionID'].value;  
 
 upload = upload.replace(/ /g, '%20');
 window.open(upload,'webstorage','width=500,height=300,resizable=no,status=yes,location=no',true);
 return; 
} 


function Edithtml(name){
// alert(name)
 var agt=navigator.userAgent.toLowerCase();
 var is_ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1));
 var is_saf=((agt.indexOf("safari")!=-1));
  var is_cam=((agt.indexOf("mozilla")!=-1));

 if (is_ie){
 var URL= "/asp/htmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=550,height=300,resizable=yes,status=yes,location=no",true);
 }
else if (is_saf){
 var URL= "/asp/htmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=550,height=300,resizable=yes,status=yes,location=no",true);
 }
else if (is_cam){
 var URL= "/asp/htmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=550,height=300,resizable=yes,status=yes,location=no",true);
 } 
 else{
 alert("The HTML Editor requires Microsoft Internet Explorer browser")
 }
 

//if (browser=="MSIE") {alert("You are using MSIE")}
//else {alert("You are using Netscape")}; 



return;
} 


function xEdithtml(name){
// alert(name)
 var agt=navigator.userAgent.toLowerCase();
 var is_ie=((agt.indexOf("msie")!=-1)&&(agt.indexOf("opera")==-1));
 var is_saf=((agt.indexOf("safari")!=-1));
  var is_cam=((agt.indexOf("mozilla")!=-1));

 if (is_ie){
 var URL= "/asp/xhtmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=600,height=430,resizable=yes,status=yes,location=no",true);
 }
else if (is_saf){
 var URL= "/asp/xhtmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=600,height=430,resizable=yes,status=yes,location=no",true);
 }
else if (is_cam){
 var URL= "/asp/xhtmledit/?elmname="+name+"&sessionid="+document.me.elements['SessionID'].value; 
 var edithtml=window.open(URL,"EditHTML","width=600,height=430,resizable=yes,status=yes,location=no",true);
 } 
 else{
 alert("The HTML Editor requires Microsoft Internet Explorer browser")
 }
 
return;
} 

function cleardropdown(name){
 var obj=document.me.elements[name];
 for (var i = (obj.options.length-1); i >= 0; i=i-1){ obj.options[i]=null;}
}