// JavaScript Document

// Example:
// var b = new BrowserInfo();
// alert(b.version); 
function BrowserInfo()
{
  this.name = navigator.appName;
  this.codename = navigator.appCodeName;
  this.version = navigator.appVersion.substring(0,4);
  this.platform = navigator.platform;
  this.javaEnabled = navigator.javaEnabled();
  this.screenWidth = screen.width;
  this.screenHeight = screen.height;
}
/* Set focus on username field */
function loginFocus(){
	document.formLogin.username.focus();
}
// Open new browser window on pricelist page 
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
if(window.screen)if(isCenter)if(isCenter=="true"){
var myLeft = (screen.width-myWidth)/2;
var myTop = (screen.height-myHeight)/4;
features+=(features!='')?',':'';
features+=',left='+myLeft+',top='+myTop;
}
window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

/*Validate login fields */
function validateLogin(){
	if (formLogin.username.value.length == 0) {
		alert('You have to type in your username! ');
		document.formLogin.username.focus();
		return false;
	}
	else if (formLogin.password.value.length == 0) {
		alert('You have to type in your password! ');
		document.formLogin.password.focus();
		return false;
		}
	else{
	return true;
	}
}
/* Open new window */
function newWin(GotoPage, WWidth, WHeight, WResize) {
	var WLeft = (screen.width / 2) - (WWidth / 2);
	var WTop = (screen.height / 2) - (WHeight / 2);
	var wOptions = "location=no,directories=no,";
	wOptions = wOptions + ",status=no,";
	wOptions = wOptions + "width=" + WWidth + "," + "height=" + WHeight + ",";
	if (WResize == "1") {
		wOptions = wOptions + "left=" + WLeft + ",top=" + WTop + ",screenx=" + WLeft + ",screeny=" + WTop;
		wOptions = wOptions + "toolbar=yes,scrollbars=yes,resizable=yes,menubar=yes,";
		varSizeScroll = window.open(GotoPage, "varSize", wOptions);
		varSizeScroll.focus();
		return varSizeScroll;
	}
	else if (WResize == "2") {
		wOptions = wOptions + "left=" + WLeft + ",top=" + (WTop -50) + ",screenx=" + WLeft + ",screeny=" + (WTop -50);
		wOptions = wOptions + "toolbar=no,scrollbars=yes,resizable=yes,menubar=no,";
		fixSizeScroll = window.open(GotoPage, "fixSize", wOptions);
		fixSizeScroll.focus();
	}
	else if (WResize == "3") {
		wOptions = wOptions + "left=" + WLeft + ",top=" + WTop + ",screenx=" + WLeft + ",screeny=" + WTop;
		wOptions = wOptions + "toolbar=no,scrollbars=no,resizable=no,menubar=no,";
		fixSize = window.open(GotoPage, "fixSize", wOptions);
		fixSize.focus();
	}
	else {
		wOptions = wOptions + "left=" + WLeft + ",top=" + 0 + ",screenx=" + WLeft + ",screeny=" + 0;
		wOptions = wOptions + "toolbar=no,scrollbars=yes,resizable=yes,menubar=no,";
		fixSize2 = window.open(GotoPage, "fixSize2", wOptions);
		fixSize2.focus();
	}
}

/* Special offer char limit */
function checkspecial(textArea,boxText){
	var specialvalue = textArea.value;	
	var specialvaluelength = textArea.value.length;	
	var value = 650 - specialvaluelength;	
	if (value < 0)
	{
		var specialvalue = textArea.value;		
		alert('You have entered ' + (650 - value) +  ' characters. 650 is the limit.');			
		textArea.value = specialvalue.substr(0, 650);
	}	
	value = 650 - textArea.value.length;	
	boxText.value = value;	
}

function updatenum() {
var profilevalue = document.formCoupon.content.value;	
var profilevaluelength = document.formCoupon.content.value.length;	
var value = 200 - profilevaluelength;	
if (value < 0)
{
var profilevalue = document.formCoupon.content.value;		
alert('You have entered ' + (200 - value) +  ' characters. 200 is the limit.');			
document.formCoupon.content.value = profilevalue.substr(0, 200);
}	
value = 200 - document.formCoupon.content.value.length;	
document.formCoupon.num.value = value;	
}
/* Unlock user profile */
function unLock() {
		document.formUserProfile.Username.disabled = false;
		document.formUserProfile.Title.disabled = false;
		document.formUserProfile.First_Name.disabled = false;
		document.formUserProfile.Last_Name.disabled = false;
		document.formUserProfile.edit.disabled=false;
}

//Item textarea char limit
function validate(theForm)  {
  //max char and rows
  var maxChar=300;
  //var maxRows=3;
  
  var s=theForm.Item.value;
  msg ="";
  var count=0;
  //var lines=new Array();
  var val = ""+theForm.Item.value;
  //if (val.indexOf('\n') !=-1) var lines = val.split('\n');
  //else lines[0]=val;
  //if (lines.length>maxRows) {
  //	msg += 'Please enter only ' + maxRows + ' lines\n';
	//s=theForm.Item.value.substr(0,(theForm.Item.value.length-2));
  //}
//  for (i=0;i<lines.length;i++) { 
 //    count+= lines[i].length;
 //	}
  count = theForm.Item.value.length;
  if (count > maxChar) msg += 'Please enter max ' + maxChar + ' chars';
  if (msg) {
     alert(msg);
     theForm.Item.value=s;
     return false;
  }
  theForm.textcount.value=maxChar - count;
  return true;
}