function ChangeUserInfo(Control ) {
try 
{

if (document.getElementById) {

ctlValue = Control.value;

ctlText = Control.options[Control.selectedIndex].text;

document.getElementById(vXmodid.UserID).value = ''
document.getElementById(vXmodid.UserFullName).value = ''

document.getElementById(vXmodid.UserID).value = ctlValue
document.getElementById(vXmodid.UserFullName).value = ctlText
document.getElementById(vXmodid.UserEmail).value = ''
document.getElementById(vXmodid.AccountID).value = ctlValue + "-VEND"
document.getElementById(vXmodid.ListingID).value = "BLIST-" + ctlValue + "-VEND-" + vXmodFormatDate

}

}
catch(err)
  {
  txt="Hi .\n\n"
  txt+="There was an error on this page.\n\n"
  txt+="Error description: " + err.description + "\n\n"
  txt+="Error on: " + ctlValue + "\n\n"
  txt+="Click OK to continue.\n\n"
  alert(txt)
  }
finally
  {
  // do nothing
  }
}



function checkHTML() {
//test

var strTipDescript = document.getElementById(vXmodid.TipDescript).value;

var reg = new RegExp("<[^>]*>");

var arsTipDescript = reg.test(strTipDescript);


if (document.getElementById) {

if (arsTipDescript) {
document.getElementById(vXmodid.TipDescriptHTML).value = 'Yes';
}else{
document.getElementById(vXmodid.TipDescriptHTML).value = 'No';
}


}	

}

function Dec2Hex(Decimal) {
	var hexChars = "0123456789ABCDEF";
	var a = Decimal % 16;
	var b = (Decimal - a)/16;
	hex = "" + hexChars.charAt(b) + hexChars.charAt(a);
	return hex;
}

function encode(Ctrl1, Ctrl2) {
    var txt = '';
    var address = Ctrl1.value;

//if (address = '') {
//alert("You must first enter a valid email address.");
//}else{
    for (j=0; j<address.length; j++)
        {
            txt += '%' + Dec2Hex(address.charCodeAt(j))
        }
    //txt = '<a href = \"mailto:' + txt + '\">' + 'email me' + '<' + '/a>'
    Ctrl2.value=txt;
//}

}


function displayNonUS(Control) {

if (document.getElementById) {

	if (Control.selectedIndex == 1) {
	//if (document.getElementById(vXmodid.cboState).selectedIndex == 1)

	document.getElementById('DivNonUS').style.display='';
	}
	else 
	{ 
	document.getElementById('DivNonUS').style.display='none';
	}
}

}


function CheckSize(Ctrl, Size) {
x = Ctrl.value.length;
y = Size;
if (y > x)
SendMsg2 (Ctrl, "OK - number of characters is: " + x); else
SendMsg2 (Ctrl, "Too Long - number of characters is: " + x);}
function SendMsg2 (Ctrl, PromptStr) { alert (PromptStr);
return;
}

function CheckSizeBlur(Ctrl, Size) {
x = Ctrl.value.length;
y = Size;
if (x > y)
SendMsg (Ctrl, "Too Long - number of characters is: " + x);
}
function SendMsg (Ctrl, PromptStr) { alert (PromptStr);
Ctrl.focus(); return;
}

function SaveMultipleSubCategory(Control1, ContolCatIndex, Control2){
try 
{

if (ContolCatIndex > 0) {

  var txtSelectedValuesObj = Control2;
  var selectedArray = new Array();
  var selObj = Control1;
  var i;
  var count = 0;

  for (i=0; i<selObj.options.length; i++) {
    if (selObj.options[i].selected) {
      selectedArray[count] = selObj.options[i].value;
      count++;
    }
  }

Control2.value = selectedArray;
} else {
  Control2.value = '';
}

}
catch(err)
  {
  txt="Hi.\n\n"
  txt+="There was an error on this page.\n\n"
  txt+="Sub Category Index is: " + Control1Index + "\n\n"
  txt+="Error description: " + err.description + "\n\n"
  txt+="Click OK to continue.\n\n"
  alert(txt)
  }
finally
  {
  // do nothing
  }


}


function SaveSubCategory(Control1, ContolCatIndex, Control2) {


try 
{
	if (ContolCatIndex > 0) {
//Control2.value = Control1.value + " Index: " +  ContolCatIndex;
		Control2.value = Control1.value;
		//Control2.style.display = '';
	} else {
		Control2.value = ''
		//Control2.style.display = 'none';
	}	

}
catch(err)
  {
  txt="Hi {XMOD_UserFirstName}.\n\n"
  txt+="There was an error on this page.\n\n"
  txt+="Sub Category Index is: " + Control1Index + "\n\n"
  txt+="Error description: " + err.description + "\n\n"
  txt+="Click OK to continue.\n\n"
  alert(txt)
  }
finally
  {
  // do nothing
  }


}

function replaceChars(field1) {
out = ","; // replace this
add = "&nbsp;-&nbsp;"; // with this
temp = "" + field1; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
//field1.value = temp;
return document.write(temp)
}

function displayRatings() {

if (document.getElementById) {

if (document.getElementById(vXmodid.ShowRatings).selectedIndex == 0) 
{ 
document.getElementById('DivAllowRatings').style.display='none';
} 
else if (document.getElementById(vXmodid.ShowRatings).selectedIndex == 1) 
{ 
document.getElementById('DivAllowRatings').style.display='';
} 
else if (document.getElementById(vXmodid.ShowRatings).selectedIndex == 2) 
{ 
document.getElementById('DivAllowRatings').style.display='none';
} 
else 
{ 
document.getElementById('DivAllowRatings').style.display='none';
}
 
}

}


function displayReviews() {

if (document.getElementById) {

if (document.getElementById(vXmodid.ShowComments).selectedIndex == 0) 
{ 
document.getElementById('DivCommentApproval').style.display='none';
} 

else if (document.getElementById(vXmodid.ShowComments).selectedIndex == 1) 
{ 
document.getElementById('DivCommentApproval').style.display='';
} 
else if (document.getElementById(vXmodid.ShowComments).selectedIndex == 2) 
{ 
document.getElementById('DivCommentApproval').style.display='none';
} 
else 
{ 
document.getElementById('DivCommentApproval').style.display='none';
}
 
}

}


function displayAudioChoice() { 

if (document.getElementById) {

if (document.getElementById(vXmodid.AudioType).selectedIndex == 0) 
{
//document.getElementById('DivVideoJive').style.display=''; 
document.getElementById('DivAudioLocal').style.display='none'; 
document.getElementById('DivAudioAmazonS3').style.display='none';
document.getElementById('DivAudioDescription').style.display='none';
document.getElementById('DivAudioApproved').style.display='none';
} 
else if (document.getElementById(vXmodid.AudioType).selectedIndex == 1) { 
document.getElementById('DivAudioAmazonS3').style.display='';
document.getElementById('DivAudioDescription').style.display='';
document.getElementById('DivAudioLocal').style.display='none';
document.getElementById('DivAudioApproved').style.display='';
//document.getElementById('DivAudioJive').style.display='none';
}
else if (document.getElementById(vXmodid.AudioType).selectedIndex == 2) 
{
document.getElementById('DivAudioDescription').style.display='';
document.getElementById('DivAudioLocal').style.display=''; 
document.getElementById('DivAudioAmazonS3').style.display='none';
document.getElementById('DivAudioApproved').style.display='';
//document.getElementById('DivAudioJive').style.display='none';
}
else 
{ 
//document.getElementById('DivAudioJive').style.display=''; 
document.getElementById('DivAudioLocal').style.display='none'; 
document.getElementById('DivAudioAmazonS3').style.display='none';
document.getElementById('DivVideoYouTube').style.display='none';
document.getElementById('DivVideoImage').style.display='none';
document.getElementById('DivAudioDescription').style.display='none';
document.getElementById('DivAudioApproved').style.display='none';
}
 
}

} 

function displayVideoChoice() { 

if (document.getElementById) {

if (document.getElementById(vXmodid.VideoType).selectedIndex == 0) 
{
document.getElementById('DivVideoJive').style.display=''; 
document.getElementById('DivVideoLocal').style.display='none'; 
document.getElementById('DivVideoAmazonS3').style.display='none';
document.getElementById('DivVideoYouTube').style.display='none';
document.getElementById('DivVideoImage').style.display='none';
document.getElementById('DivVideoDescription').style.display='none';
document.getElementById('DivVideoHeader').style.display='none';
} 
else if (document.getElementById(vXmodid.VideoType).selectedIndex == 1) { 
document.getElementById('DivVideoAmazonS3').style.display='';
document.getElementById('DivVideoImage').style.display='';
document.getElementById('DivVideoDescription').style.display='';
document.getElementById('DivVideoLocal').style.display='none';
document.getElementById('DivVideoYouTube').style.display='none';
document.getElementById('DivVideoJive').style.display='none';
document.getElementById('DivVideoHeader').style.display='';
}
else if (document.getElementById(vXmodid.VideoType).selectedIndex == 2) 
{
document.getElementById('DivVideoYouTube').style.display='';
document.getElementById('DivVideoDescription').style.display='';
document.getElementById('DivVideoImage').style.display='none';
document.getElementById('DivVideoLocal').style.display='none'; 
document.getElementById('DivVideoAmazonS3').style.display='none';
document.getElementById('DivVideoJive').style.display='none';
document.getElementById('DivVideoHeader').style.display='';
}
else if (document.getElementById(vXmodid.VideoType).selectedIndex == 3) 
{
document.getElementById('DivVideoLocal').style.display='';
document.getElementById('DivVideoImage').style.display='';
document.getElementById('DivVideoDescription').style.display='';
document.getElementById('DivVideoAmazonS3').style.display='none';
document.getElementById('DivVideoYouTube').style.display='none';
document.getElementById('DivVideoJive').style.display='none';
document.getElementById('DivVideoHeader').style.display='';
}
else 
{ 
document.getElementById('DivVideoJive').style.display=''; 
document.getElementById('DivVideoLocal').style.display='none'; 
document.getElementById('DivVideoAmazonS3').style.display='none';
document.getElementById('DivVideoYouTube').style.display='none';
document.getElementById('DivVideoImage').style.display='none';
document.getElementById('DivVideoDescription').style.display='none';
document.getElementById('DivVideoHeader').style.display='none';
}
 
}

} 

function showYouTube(url) {
try
{
var urlInput = url;
var pattern = "watch\?v=";
var replacement = "v/";
var urlInput = urlInput.replace(pattern, replacement);
var YouTubeEmbed = '<object width="320" height="267"><param name="movie" value="' + urlInput + '&rel=0&color1=0x3a3a3a&color2=0x999999&border=1&hl=en"><\/param><param name="wmode" value="transparent"><\/param>\<embed src="' + urlInput + '&rel=0&color1=0x3a3a3a&color2=0x999999&border=1&hl=en" type="application\/x-shockwave-flash" wmode="transparent" width="320" height="267"><\/embed><\/object>';	
return document.writeln(YouTubeEmbed);
}
catch(err)
  {
  txt="Hi .\n\n"
  txt+="There was an error on this page.\n\n"
  txt+="YouTube video cannot be displayed.\n\n"
  txt+="Error description: " + err.description + "\n\n"
  txt+="Error on: " + ctlValue + "\n\n"
  txt+="Click OK to continue.\n\n"
  alert(txt)
  }
finally
  {
  // do nothing
  }
} 


function ClearSubCategory(Control1, Control2) {

Control2.value = '';

}



function setCategory() {


categorySel = document.getElementById(vXmodid.cboCategory);
categoryList = CAT[categorySel.value];
Field_ID = vXmodid.SubCategory;
changeSelect(Field_ID, categoryList, categoryList);
}


function changeSelect(fieldID, newOptions, newValues) {
selectField = document.getElementById(fieldID);
selectField.options.length = 0;
for (i=0; i<newOptions.length; i++) {
selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
}

}


function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
setCategory();
});
