// JavaScript Document

function focusLoginUsername() {
	document.frmMemberLogin.username.focus();	
	return true;
}

// JavaScript Document
function focusSystemAccountUsername() {
	document.frmAccount.username.focus();	
	return true;
}

// JavaScript Document
function focusCompanyName() {
	document.frmMemberCompany.company_name.focus();
	countCompanyWords();
	return true;
}

// JavaScript Document
function focusPackageName() {
	document.frmPackage.name.focus();
	return true;
}

// JavaScript Document
function focusProductName() {
	document.frmMemberProduct.name.focus();	
	countProductWords();
	return true;
}

// JavaScript Document
function focusAccountName() {
	document.frmMemberAccount.username.focus();	
	return true;
}

function focusVideoName() {
	document.frmMemberVideo.name.focus();
	countVideoWords();
	return true;	
}

function focusCategoryName() {
	document.frmCategory.name.focus();
	return true;	
}

function countCompanyWords(){
	/*Word count script
	By JavaScript Kit (http://javascriptkit.com)
	Over 400+ free scripts here!
	*/
	var formcontent=document.frmMemberCompany.company_description.value;
	formcontent=formcontent.split(" ");	
	document.frmMemberCompany.wordcount.value=formcontent.length;
}

function countProductWords(){
	/*Word count script
	By JavaScript Kit (http://javascriptkit.com)
	Over 400+ free scripts here!
	*/
	var formcontent=document.frmMemberProduct.description.value;
	formcontent=formcontent.split(" ");
	document.frmMemberProduct.wordcount.value=formcontent.length;

}

function countVideoWords(){
	/*Word count script
	By JavaScript Kit (http://javascriptkit.com)
	Over 400+ free scripts here!
	*/
	var formcontent=document.frmMemberVideo.description.value;
	formcontent=formcontent.split(" ");
	document.frmMemberVideo.wordcount.value=formcontent.length;
}


function redirectto(location){
	window.location.href = location;		
}

function switchLoginState(id, visibleStateCSS) {
	// Locate and update our popup window
	object = document.getElementById(id);	
	object.className = visibleStateCSS;	
	return true;
}

function closeDiv(id,visibleStateCSS){
		switchLoginState(id,visibleStateCSS);
		return true;
}

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};



function checkMystery(){    
	focusProductName();

	mysteryDivId = document.getElementById("mystery");			
	normalDivId  = document.getElementById("normal");
	if (document.frmMemberProduct.category.selectedIndex >=1 && document.frmMemberProduct.category.options[document.frmMemberProduct.category.selectedIndex].text == "Mystery Category"){
		mysteryDivId.style.display = "";				
		normalDivId.style.display = "none";
	}	
	else {
		mysteryDivId.style.display = "none";				
		normalDivId.style.display = "";		
	}
		
}

function loadProduct(path){
	
	var product_id = document.frmMemberProduct.products.options[document.frmMemberProduct.products.selectedIndex].value;
	
	if (product_id){
		var path = path + "&product_id=" + product_id;
		window.location.href = path;
	}
	else {
		alert("Choose Product");		
	}
}

function loadVideo(path){
	
	var video_id = document.frmMemberVideo.videos.options[document.frmMemberVideo.videos.selectedIndex].value;
	
	if (video_id){
		var path = path + "&video_id=" + video_id;
		window.location.href = path;
	}
	else {
		alert("Choose Video");		
	}
}



function loadCategoryProduct(path, elementId){

	var query = document.getElementById(elementId).value;
	
	if (query){
		var path = path + query;
		window.location.href = path;
	}
	else {
		alert("Choose Product");		
	}
}

function loadCategoryPage(path){
	
	var query = document.frmCategory.categories.options[document.frmCategory.categories.selectedIndex].value;
	
	if (query){
		var path = path + query;
		window.location.href = path;
	}
	else {
		alert("Choose Category");		
	}
}


function addTrademark(textAreaId){
	
	id = document.getElementById(textAreaId);
	id.value = id.value + "&trade;";
	
}

function addCopyright(textAreaId){
	
	id = document.getElementById(textAreaId);
	id.value = id.value + "&copy;";
	
}

function addRegistration(textAreaId){
	
	id = document.getElementById(textAreaId);
	id.value = id.value + "&reg;";
	
}

function messageWindow(title, msg){

  var width="300", height="125";

  var left = (screen.width/2) - width/2;

  var top = (screen.height/2) - height/2;

  var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;

  var msgWindow = window.open("","msgWindow", styleStr);

  var head = '<head><title>'+title+'</title></head>';

  var body = '<center>'+msg+'<br><p><form><input type="button" value="   Done   " onClick="self.close()"></form>';

  msgWindow.document.write(head + body);

}
