function showImage(code)
 {
  var url="index.php?action=largeImage&toplayout=1&productID="+code;
   SupermaxDetailsWindow = window.open(url,"Details","width=580,height=300,menubar=no,toolbar=no,scrollbars,resizable");
   SupermaxDetailsWindow.focus();
 }

function OpenUp(code)
{
  var url="index.php?action=productDetail&toplayout=1&productID="+code;
  SupermaxDetailsWindow = window.open(url,"Details","width=650,height=400,menubar=no,toolbar=no,scrollbars,resizable");
  SupermaxDetailsWindow.focus();
}

function ltrim ( s )
{
    return s.replace( /^\s*/, "" );
}
function rtrim ( s2 )
{
    return s2.replace( /\s*$/, "" );
}

function trim ( s )
{
    return rtrim(ltrim(s));
}
/*function assignTo(sortOn,formName)
{
	alert('test' + formName);
	var f = formName;
	var sortOrder = document.f.sortOrder.value;
	if(sortOrder == "asc")
	{
		sortOrder = "desc";
	}
	else
	{
		sortOrder = "asc";
	}
	document.formName.sortOn.value = sortOn;
	document.formName.sortOrder.value = sortOrder;
	document.formName.submit();
	return true;
}*/

//Function for validation of change password
function validateChangePassword()
{
	var errorMsg = "";
	var focus_field = '';
	var str = '';

	if(document.changePassword.oldPassword)
	{
		if(trim(document.changePassword.oldPassword.value) == "")
		{
			errorMsg += "Please enter your old Password.\n";
			if(!focus_field)
				focus_field = document.changePassword.oldPassword;
		}
	}
	if(trim(document.changePassword.newPassword.value) == "")
	{
		errorMsg += "Please enter your new Password.\n";
		if(!focus_field)
				focus_field = document.changePassword.newPassword;
	}
	if(trim(document.changePassword.confirmPassword.value) == "")
	{
		errorMsg += "Please enter your confirm Password.\n";
		if(!focus_field)
				focus_field = document.changePassword.confirmPassword;
	}
	if(trim(document.changePassword.confirmPassword.value) != trim(document.changePassword.newPassword.value))
	{
		errorMsg +=  "The confirm password does not match with the New password.!!\n";
		if(!focus_field)
				focus_field = document.changePassword.newPassword;
	}
	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		focus_field.focus();
		focus_field.select();
		return false;
	}
	str = trim(document.changePassword.newPassword.value);
	if(str.length < 4 && str.length > 25)
	{
		alert("Password must be greater than 4 characters and less than 25 characters.!!");
		document.changePassword.newPassword.focus();
		document.changePassword.newPassword.select();
		return false;
	}
}// end of function validateChangePassword()


//Function to validate the add Transaction form by Meghna Vora
function validateTransaction()
{
	var errorMsg = "";

	if(trim(document.addTransaction.poNo.value) == "")
	{
		errorMsg += "Please enter Purchase Order Number.\n";
	}
	/*if(trim(document.addTransaction.poRaisedOn.options[document.addTransaction.poRaisedOn.selectedIndex].value) == "0")
	{
		errorMsg += "Please select the Branch on which PO to be raised.\n";
	}*/

	if(trim(document.addTransaction.port.options[document.addTransaction.port.selectedIndex].value) == "0")
	{
		errorMsg += "Please select the port on which Shipment to be arrived.\n";
	}
	/*if(trim(document.addTransaction.item.options[document.addTransaction.item.selectedIndex].value) == "0")
	{
		errorMsg += "Please select an Item to be ordered.\n";
	}*/

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
}//end of function validateTransaction()

//Function for Validation of add Item and Update Item by Meghna Vora
function validateItem(formName)
{
	var errorMsg;
	errorMsg = "";
	var f = formName;

	if(trim(f.itemName.value) == "")
	{
		errorMsg = "Please enter Item Code.\n";
	}
	if(trim(f.itemCode.value) == "")
	{
		errorMsg += "Please enter Item Name.\n";
	}
	if(trim(f.unit.value) == "")
	{
		errorMsg += "Please enter the type of unit the Item would have.\n";
	}
	if(trim(f.noOfBlades.value) == "")
	{
		errorMsg += "Please enter Number of Blades.\n";
	}
	/*if(trim(f.retailPrice.value) == "")
	{
		errorMsg += "Please enter Retail Price.\n";
	}*/

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}

}//end of function validateItem(formName)

/*Function for the validation of add location by Bhavin Shah*/
function locationValidation()
{
	var errorMsg;
	errorMsg = "";
	if(trim(document.addLocation.locationname.value) == "")
	{
		errorMsg += "Please enter location name.\n";
	}
	if(trim(document.addLocation.headfirstname.value) == "")
	{
		errorMsg += "Please enter location head's first name.\n";
	}
	if(trim(document.addLocation.headlastname.value) == "")
	{
		errorMsg += "Please enter location head's last name.\n";
	}
	if(trim(document.addLocation.locationshort.value) == "")
	{
		errorMsg += "Please enter location short name.\n";
	}
	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}//end of function locationValidation()

/*Function for the validation of add port by Bhavin Shah*/
function portValidation()
{
	var errorMsg;
	errorMsg = "";
	if(trim(document.form1.portname.value) == "")
	{
		errorMsg += "Please enter port name.\n";
	}

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}//end of function locationValidation()

/*Function for the validation of add user by Bhavin Shah*/
function addUserValidation()
{
	var errorMsg;
	errorMsg = "";
	if(trim(document.form1.firstName.value) == "")
	{
		errorMsg += "Please enter first name.\n";
	}

	if(trim(document.form1.lastName.value) == "")
	{
		errorMsg += "Please enter last name.\n";
	}

	//if(validateEmail(document.form1.email.value))
	//{
		email1 = document.form1.email.value + "@supermaxworld.com";
		errorMsg += validateEmail(email1);
	//}

	if(trim(document.form1.contactNo.value) == "")
	{
		errorMsg += "Please enter contact number.\n";
	}

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}//end of function addUserValidation()

function modifyUserValidation()
{
	var errorMsg;
	errorMsg = "";
	if(trim(document.form2.firstName.value) == "")
	{
		errorMsg += "Please enter first name.\n";
	}

	if(trim(document.form2.lastName.value) == "")
	{
		errorMsg += "Please enter last name.\n";
	}

	//if(validateEmail(document.form2.email.value))
	//{
		email1 = document.form2.email.value + "@supermaxworld.com";
		errorMsg += validateEmail(email1);
	//}

	if(trim(document.form2.contactNo.value) == "")
	{
		errorMsg += "Please enter contact number.\n";
	}

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}//end of function addUserValidation()

/*Function for the validation of adding Shipping agency by Bhavin Shah*/
function shippingValidation()
{
	var errorMsg;
	errorMsg = "";
	if(trim(document.addShippingAgency.saname.value) == "")
	{
		errorMsg += "Please enter shipping agency name.\n";
	}

	if(trim(document.addShippingAgency.saaddress.value) == "")
	{
		errorMsg += "Please enter shipping address.\n";
	}

	if(trim(document.addShippingAgency.sacontactno.value) == "")
	{
		errorMsg += "Please enter shipping agency contact number.\n";
	}

	if (trim(errorMsg) != "")
	{
		alert(errorMsg);
		return false;
	}
	else
	{
		return true;
	}
}//end of function addUserValidation()

function validate()
{
  var f = document.frmMain;
  var errormsg="";

  if(trim(f.username.value) == "")
  {
    f.username.focus();
    errormsg+="Please enter Username.\n";
  }

  else if(trim(f.password.value) == "")
  {
    f.password.focus();
    errormsg+="Please enter Password.\n";
  }


  if (errormsg != "")
  {
   alert(errormsg);
   return false;
  }
  else
   return true;

}

function hideBody( val1 )
{
	alert('test' + document.modifyTransaction.getElementById( "tdDisplayBody" ).innerHTML);
	 if( innerHtml2 == '' )
     {
	 	innerHtml2 = document.getElementById( "tdDisplayBody" ).innerHTML;
	 }

	if ( innerHtml3 == '' )
	 {
		innerHtml3 = document.getElementById( "tdDisplayShipForm" ).innerHTML;
	 }
	 if( innerHtml4 == '' )
	 {
		innerHtml4 = document.getElementById( "tdDisplayArrived" ).innerHTML;
	 }
	 if( innerHtml5 == '')
	 {
		innerHtml5 = document.getElementById( "tdDisplayCancelled" ).innerHTML;
	 }

	if( ( val1.value ==  "SB" ) || ( val1.value ==  "SV" ) )
    {
	    document.getElementById( "tdDisplayBody" ).innerHTML = innerHtml2;
		document.getElementById( "tdDisplayShipForm" ).innerHTML = '';
		document.getElementById( "tdDisplayArrived" ).innerHTML = '';
		document.getElementById( "tdDisplayCancelled" ).innerHTML = '';
		return;

	}
	else if( val1.value == "SH" )
	{
			document.getElementById( "tdDisplayShipForm" ).innerHTML = innerHtml3;
			document.getElementById( "tdDisplayBody" ).innerHTML = '';
			document.getElementById( "tdDisplayArrived" ).innerHTML = '';
			document.getElementById( "tdDisplayCancelled" ).innerHTML = '';
			return;

	}
	else if( val1.value == "AR")
	{
		document.getElementById( "tdDisplayArrived" ).innerHTML = innerHtml4;
		document.getElementById( "tdDisplayBody" ).innerHTML = '';
		document.getElementById( "tdDisplayShipForm" ).innerHTML = '';
		document.getElementById( "tdDisplayCancelled" ).innerHTML = '';
	}
	else if( val1.value == "CA")
	{
		document.getElementById( "tdDisplayCancelled" ).innerHTML = innerHtml5;
		document.getElementById( "tdDisplayBody" ).innerHTML = '';
		document.getElementById( "tdDisplayShipForm" ).innerHTML = '';
		document.getElementById( "tdDisplayArrived" ).innerHTML = '';
	}
	else if(val1.value == "CO")
	{
		return1 = confirm('Are you sure you want to close this Transaction');
		if(return1 == 1)
			document.modifyTransaction.submit();
	}
	else
	{
		document.getElementById( "tdDisplayBody" ).innerHTML = '';
		document.getElementById( "tdDisplayShipForm" ).innerHTML = '';
		document.getElementById( "tdDisplayArrived" ).innerHTML = '';
		document.getElementById( "tdDisplayCancelled" ).innerHTML = '';
	}
}

function validateEmail(value)
{
  var RegExpOb = new RegExp("^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~ ])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,5}\$");
  var errmsg = "";

  if(!RegExpOb.test(value))
  {
	errmsg = "Invalid Email address.\n";
	return errmsg;
  }
  errmsg = "";
  return errmsg;
}

function validate1()
{

  var f = document.userDetails;
  var errormsg = "";
  if(trim(f.firstName.value) == "")
  {
    f.firstName.focus();
    errormsg+="Please enter First Name.\n";
  }

  if(trim(f.lastName.value) == "")
  {
    f.lastName.focus();
    errormsg+="Please enter Last Name.\n";
  }

  if(trim(f.email.value) == "")
  {
    f.email.focus();
    errormsg+="Please enter email address.\n";
  }
  if(trim(f.address1.value) == "")
  {
    f.address1.focus();
    errormsg+="Please enter Address1.\n";
  }
  if(trim(f.phone1.value) == "")
  {
    f.phone1.focus();
    errormsg+="Please enter Phone No.\n";
  }

  if (errormsg != "")
  {
   alert(errormsg);
   return false;
  }
  else
   return true;

}

/* Function to open new window */
function openNew(url,w,h,resize)
{
   var properties="width="+w+",height="+h+",screenX=10,screenY=10,top=10,left=10,menubar=no,toolbar=no,scrollbars,"+resize;
   whatsNewWindow = window.open(url,"NewWindow",properties);
   whatsNewWindow.focus();
}
//var glbResize = true;
var glbResize = new Array();
var glbWhoseFocus = new Array();
//onFocus="window.whoseFocus=
function WhoseFocus(ObjName)
{
	glbWhoseFocus = ObjName.id;
	return true;
}
function resize(resizeObj,IncDesc)
{
	if(document.all)
	{
		if(IncDesc)
		{
			resizeObj.style.width = "100px";
			//glbResize = true;
			glbResize[resizeObj.id] = false;
		}
		else
		{
			if(!glbResize[resizeObj.id])
			{
				resizeObj.style.width = "300px";
				//resizeObj.click();
				if(glbWhoseFocus != resizeObj.id)
				{
					resizeObj.focus();
				}
				glbWhoseFocus = resizeObj.id;
				//glbResize = false;
				glbResize[resizeObj.id] = true;
			}
		}
	}
	return true;
}
