//  ChoiceBook  javascript**************************** //
//  Created By Venkatesan Balasubramanian  [2009-04-14] //
var hide_key="";
function sortbyField(theForm,mode,r_criteria,okey)
{
	 if (theForm.getElementById("gtab"+mode).className=="")
	    hide_key="_asc";    
	 else if (theForm.getElementById("gtab"+mode).className=="asc")
	 	hide_key="_desc";  
	 else
		hide_key="_asc";  
	 theForm.getElementById(okey).value=hide_key;	
 //alert(hide_key+ "  hai");
 //dispUser(r_criteria,hide_key);	 
}
 function changeColor(trNode,row,colorCode,theForm,cur){
	if (colorCode=='#999999')
	{
	 	for(var i=0;i<=row;i++)
	 	{   if (cur==i)
			trNode.bgColor='#999999';	
			else
			theForm.getElementById("tr_"+i).bgColor='#FFFFFF'
		} //end of for

	}else {
		if(trNode.bgColor!='#999999')
		trNode.bgColor=colorCode;
	} 
}

function selectRecord(theForm,n)
{
 var con=false;
 if (theForm.chkbox_ctrl.checked==true) 
 con=true;
 for (var i=0;i<n;i++)
 { 
  //document.getElementById('formID:fieldId').click();  --syntax but it wont work
   theForm.elements['chkbox_'+i].checked=con;
 }
}  

function search_val(theForm)
{
 if(theForm.searchby.value==""){
	 alert("Please select your search criteria");
	 return false;
 }
 if(theForm.keyword.value==""){
	 alert("Please enter search keyword");
	 return false;
 }
 theForm.confirmed.value=true;
 return true;	
}


function addBooks_val(theForm)
{
	if (theForm.cate.value==""){
	alert("Please select category");
	return false; }
	 	
	if (theForm.bookName.value==""){
	alert("Please enter the book name");
	return false; }
    if (theForm.isbn.value==""){
	alert("Please enter ISBN code");
	return false; }
	if (theForm.publisher.value==""){
	alert("Please enter publisher name");
	return false; }
	if (theForm.price.value=="0.00"){
	alert("Please enter the book price");
	return false; }
	
 theForm.confirmed.value=true;
 return true;	
}

function addcddvd_val(theForm)
{
	if (theForm.cate.value==""){
	alert("Please select category");
	return false; }
	 	
	if (theForm.cddvdName.value==""){
	alert("Please enter the CD/DVD name");
	return false; }
    if (theForm.label.value==""){
	alert("Please enter label ");
	return false; }
	if (theForm.price.value=="0.00"){
	alert("Please enter the book price");
	return false; }
	
 theForm.confirmed.value=true;
 return true;	
}

function addUser_val(form)
{
   if (form.editmode.value=="0") 
   {
 	 if(form.username.value == "") {
      alert("Error: Username cannot be blank!");
      form.username.focus();
      return false;
      }
     var re = /^\w+$/;
    if(!re.test(form.username.value)) {
      alert("Error: Username must contain only letters, numbers and underscores!");
      form.username.focus();
      return false;
     }
	if(form.pwd1.value != "" && form.pwd1.value == form.pwd2.value) {
      if(form.pwd1.value.length < 6) {
        alert("Error: Password must contain at least six characters!");
        form.pwd1.focus();
        return false;
      }
      if(form.pwd1.value == form.username.value) {
        alert("Error: Password must be different from Username!");
        form.pwd1.focus();
        return false;
      }
      re = /[0-9]/;
      if(!re.test(form.pwd1.value)) {
        alert("Error: password must contain at least one number (0-9)!");
        form.pwd1.focus();
        return false;
      }
      re = /[a-z]/;
      if(!re.test(form.pwd1.value)) {
        alert("Error: password must contain at least one lowercase letter (a-z)!");
        form.pwd1.focus();
        return false;
      }
      re = /[A-Z]/;
      if(!re.test(form.pwd1.value)) {
        alert("Error: password must contain at least one uppercase letter (A-Z)!");
        form.pwd1.focus();
        return false;
      }
    } else {
      alert("Error: Please check that you've entered and confirmed your password!");
      form.pwd1.focus();
      return false;
    }
  }
 form.confirmed.value=true;
 return true;	
}
function addCategory_val(theForm)
{
	if (theForm.catName.value==""){
	alert("Please enter the category value");
	return false; }

theForm.confirmed.value=true;
 return true;	
}
function addSubCategory_val(theForm)
{
	if (theForm.scategory.value==""){
	alert("Please enter the Sub Category value");
	return false; }

theForm.confirmed.value=true;
 return true;	
}

function textCounter(field, countfield, maxlimit) 
{
  if (field.value.length >= maxlimit)
  {
    alert("Please limit your message to "+maxlimit+" chars");
    return false;
  }
  if (field.value.length > maxlimit) { // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
  }
  else {   // otherwise, update 'characters left' counter
    countfield.value = maxlimit - field.value.length; 
  }
  return true;
}
function enforceLength(field,maxlen)
{
	if (field.value.length > maxlen + 1)
	alert('your input has been truncated!');
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
}

function submit_post(theFrm,maxlen)
{
 if (theFrm.msg.value=="")
  { alert ("Please enter you comments first ");
   theFrm.msg.focus() ; return false;
  } 
  var iChars = ";\"";
  for (var i = 0; i < theFrm.msg.value.length; i++) {
  	if (iChars.indexOf(theFrm.msg.value.charAt(i)) != -1) {
  	alert ("Your Comment has special characters. \nThese are not allowed.\n Please remove them and try again.");
    theFrm.msg.focus(); return false;
  	}
  } 
 if (theFrm.msg.value.length < 2)
  {   alert ("Please enter your comments not less than 2 Char");
     theFrm.msg.focus(); return false;
  }
 if (theFrm.msg.length > maxlen)
  {  alert("Please limit your message to "+maxlen+" chars");
  	theFrm.msg.focus() ; return false;
  }
 theFrm.confirmed.value="true";
}
function openHelpWin() {
    helpArgs = openHelpWin.arguments;
    if (helpArgs[0]) {
	docName = helpArgs[0];
    } else {
	docName = "/static/blank.ws";
    }
    if (helpArgs[1]) {
	winWidth = helpArgs[1];
    } else {
	winWidth = 500;
    }
    if (helpArgs[2]) {
	winHeight = helpArgs[2];
    } else {
	winHeight = 170;
    }
    if (helpArgs[3]) {
	winScrollbars = helpArgs[3];
    } else {
	winScrollbars = 1;
    }
    if (helpArgs[4]) {
	winResizable = helpArgs[4];
    } else {
	winResizable = 1;
    }

// below line must be deleted when Show Search Criteria will be ready!  
// if(docName.indexOf("criteria") != -1) return
  
    HelpWinProps = "toolbar=0,location=0,directories=0,status=0,menubar=0" +
	",scrollbars=" + winScrollbars +
	",resizable=" + winResizable +
	",width=" + winWidth +
	",height=" + winHeight;
    HelpWin = window.open(docName,"HelpWin",HelpWinProps);
}
function openHelpWin2(){
  helpArgs = openHelpWin2.arguments
  if(helpArgs[0]) docName = helpArgs[0]; else docName = "/static/blank.ws"
  if(helpArgs[1]) winWidth = helpArgs[1]; else winWidth = 650
  if(helpArgs[2]) winHeight = helpArgs[2]; else winHeight = 1
  if(helpArgs[3]) winScrollbars = helpArgs[3]; else winScrollbars = 1
winHeight =380
// bellow line must be deleted when Show Search Criteria will be ready!  
// if(docName.indexOf("criteria") != -1) return
  
  HelpWinProp="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+winScrollbars+",resizable=0,width="+winWidth+",height="+winHeight;
  HelpWin=window.open(docName,"HelpWin",HelpWinProp);
}
