// JavaScript Document

function chkValidationLogin()
{
	if(document.frmLogin.txtLogin.value == "")
	{
		alert("Please enter Login ID");
		document.frmLogin.txtLogin.focus();
		return false;
	}
	if(document.frmLogin.txtPassword.value == "")
	{
		alert("Please enter Password");
		document.frmLogin.txtPassword.focus();
		return false;
	}
	document.frmLogin.action = "index.php";
	document.frmLogin.submit();	
}
function chkSubCategoryValidation(val){
	/*if(document.frmSubCategory.txtCategoryName.value==""){
		alert("Please Select the category");
		document.frmSubCategory.txtCategoryName.focus();
		return false;
	}*/
	if(document.frmSubCategory.txtSubCategoryName.value==""){
		alert("SubCategory Name should not be blank");
		document.frmSubCategory.txtSubCategoryName.focus();
		return false;
	}
	
	document.frmSubCategory.action ="subcatagory.php";
	document.frmSubCategory.submit();	
}
function checkBAddress1()
{
	//alert(frmpara);
	document.frmOrder.txtBillingAddress.disabled=true;
	document.frmOrder.txtbCity.disabled=true;
	document.frmOrder.txtbState.disabled=true;
	document.frmOrder.txtbCountry.disabled=true;
	//document.frmOrder.action = "order.php";
	//document.frmOrder.submit();
}
function checkBAddress()
{
	//alert(frmpara);
	document.frmOrder.txtBillingAddress.disabled=false;
	document.frmOrder.txtbCity.disabled=false;
	document.frmOrder.txtbState.disabled=false;
	document.frmOrder.txtbCountry.disabled=false;
	
}
function checkSAddress1()
{
	//alert(frmpara);
	document.frmOrder.txtShippingAddress.disabled=true;
	document.frmOrder.txtsCity.disabled=true;
	document.frmOrder.txtsState.disabled=true;
	document.frmOrder.txtsCountry.disabled=true;
}
function checkSAddress()
{
	//alert(frmpara);
	document.frmOrder.txtShippingAddress.disabled=false;
	document.frmOrder.txtsCity.disabled=false;
	document.frmOrder.txtsState.disabled=false;
	document.frmOrder.txtsCountry.disabled=false;
}
function chkLoginClient()
{
	if(document.frmLogin.txtLogin.value == "")
	{
		alert("Please enter Login ID");
		document.frmLogin.txtLogin.focus();
		return false;
	}
	if(document.frmLogin.txtPassword.value == "")
	{
		alert("Please enter Password");
		document.frmLogin.txtPassword.focus();
		return false;
	}
	document.frmLogin.action = "login.php";
	document.frmLogin.submit();
}
function changePassword(password, user_id, session)
{
	if(document.frmEditPass.txtOld.value == "")
	{
		alert('Enter Value in Old Password');
		document.frmEditPass.txtOld.focus();
		return false;
	}
	if(document.frmEditPass.txtNew.value == "")
	{
		alert('Enter Value in New Password');
		document.frmEditPass.txtNew.focus();
		return false;
	}
	if(document.frmEditPass.txtConfirm.value == "")
	{
		alert('Enter Value in New Password Again');
		document.frmEditPass.txtConfirm.focus();
		return false;
	}
	if(document.frmEditPass.txtOld.value != password)
	{
		alert('Your Old Password not match with your Entered Password');
		document.frmEditPass.txtOld.focus();
		return false;
	}
	if(document.frmEditPass.txtNew.value != document.frmEditPass.txtConfirm.value)
	{
		alert('Please Enter Same password In both Field');
		document.frmEditPass.txtConfirm.focus();
		return false;		
	}
	return true;
	
}
function changePasswordcli(password, user_id, session)
{
	if(document.frmEditcliPass.txtOld.value == "")
	{
		alert('Enter Value in Old Password');
		document.frmEditcliPass.txtOld.focus();
		return false;
	}
	if(document.frmEditcliPass.txtNew.value == "")
	{
		alert('Enter Value in New Password');
		document.frmEditcliPass.txtNew.focus();
		return false;
	}
	if(document.frmEditcliPass.txtConfirm.value == "")
	{
		alert('Enter Value in New Password Again');
		document.frmEditcliPass.txtConfirm.focus();
		return false;
	}
	if(document.frmEditcliPass.txtOld.value != password)
	{
		alert('Your Old Password not match with your Entered Password');
		document.frmEditcliPass.txtOld.focus();
		return false;
	}
	if(document.frmEditcliPass.txtNew.value != document.frmEditcliPass.txtConfirm.value)
	{
		alert('Please Enter Same password In both Field');
		document.frmEditcliPass.txtConfirm.focus();
		return false;		
	}
	return true;
	
}
//For User
function InsertUser(FrmPara)
{
	document.frmUserMgmt.action = FrmPara;
	document.frmUserMgmt.submit();
}
function InsertClient(FrmPara)
{
	document.frmClientMgmt.action = FrmPara;
	document.frmClientMgmt.submit();
}
function InsertCatagory(FrmPara)
{
	document.frmCatagoryMgmt.action = FrmPara;
	document.frmCatagoryMgmt.submit();
}
function InsertOrder(FrmPara)
{
	document.frmOrderMgmt.action = FrmPara;
	document.frmOrderMgmt.submit();
}
function InsertProduct(FrmPara)
{
	document.frmProductMgmt.action = FrmPara;
	document.frmProductMgmt.submit();
}
function InsertComment(FrmPara)
{
	document.frmCommentMgmt.action = FrmPara;
	document.frmCommentMgmt.submit();
}
function deleteUser(FrmPara)
{
	//alert("hi");
	var ans = confirm("Would you like to  Delete User?");
	if(ans==true)
	{
		document.frmUserMgmt.hidFrmVal.value = "Delete";
		document.frmUserMgmt.action = FrmPara;
		document.frmUserMgmt.submit();
	}
	else
	{
		document.frmUserMgmt.action = FrmPara;
	}
	
}
function UpdateStatus(FrmPara)
{
	var ans = confirm("are you shore u want to update the progress status");
	if(ans==true)
	{
		document.form1.action = FrmPara;
		document.form1.submit();
	}
}
function deleteClient(FrmPara)
{
	//alert("hi");
	var ans = confirm("Would you like to  Delete Client?");
	if(ans==true)
	{
		document.frmClientMgmt.hidFrmVal.value = "Delete";
		document.frmClientMgmt.action = FrmPara;
		document.frmClientMgmt.submit();
	}
	else
	{
		document.frmClientMgmt.action = FrmPara;
	}
	
}
function deleteCatagory(FrmPara)
{
	//alert("hi");
	var ans = confirm("All the Order Under This Product will Also Deleted.\n Would you like to Delete Catagory?");
	if(ans==true)
	{
		document.frmCatagoryMgmt.hidFrmVal.value = "Delete";
		document.frmCatagoryMgmt.action = FrmPara;
		document.frmCatagoryMgmt.submit();
	}
	else
	{
		document.frmCatagoryMgmt.action = FrmPara;
	}
	
}
function deleteComment(FrmPara)
{
	//alert("hi");
	var ans = confirm("Would you like to Delete Comment?");
	if(ans==true)
	{
		document.frmCommentMgmt.hidFrmVal.value = "Delete";
		document.frmCommentMgmt.action = FrmPara;
		document.frmCommentMgmt.submit();
	}
	else
	{
		document.frmCommentMgmt.action = FrmPara;
	}
	
}
function deleteOrder(FrmPara)
{
	//alert("hi");
	var ans = confirm("Would you like to  Delete Order?");
	if(ans==true)
	{
		document.frmOrderMgmt.hidFrmVal.value = "Delete";
		document.frmOrderMgmt.action = FrmPara;
		document.frmOrderMgmt.submit();
	}
	else
	{
		document.frmOrderMgmt.action = FrmPara;
	}
}
function deleteProduct(FrmPara)
{
	//alert("hi");
	var ans = confirm("All the Order Under This Product will Also Deleted.\n Would you like to Delete Product?");
	if(ans==true)
	{
		document.frmProductMgmt.hidFrmVal.value = "Delete";
		document.frmProductMgmt.action = FrmPara;
		document.frmProductMgmt.submit();
	}
	else
	{
		document.frmProductMgmt.action = FrmPara;
	}
}
function submitclient()
{
	document.frmClientID.action ="clientid.php?f=1";
	document.frmClientID.submit();
}
function submitorder()
{
	document.frmOrderID.action ="orderid.php?f=1";
	document.frmOrderID.submit();
}
function editReg()
{
		if(document.frmRegister.txtEmail.value == "")
		{
			alert('Please Enter your Email Address');
			document.frmRegister.txtEmail.focus();
			return false;
		}
		if(document.frmRegister.txtEmail.value.indexOf("@") == -1 || document.frmRegister.txtEmail.value.indexOf(".") == -1)
		{
			alert("Please Enter Valid Email Address!!!");
			document.frmRegister.txtEmail.focus();
			return false;
		}
		if(document.frmRegister.txtPhone.value == "")
		{
			alert('Please enter the Phone Number');
			document.frmRegister.txtPhone.focus();
			return false;
		}
		if(document.frmRegister.txtScreen.value.indexOf("@") == -1 || document.frmRegister.txtScreen.value.indexOf(".") == -1)
		{
			alert("Please Enter Valid Screen Name!!!");
			document.frmRegister.txtScreen.focus();
			return false;
		}
		if(!IsNumericforReg(document.frmRegister.txtPhone.value))
		{
			return false;
		}
		document.frmRegister.action = "register.php";
		document.frmRegister.submit();
}
function chkCatagoryValidation(val){
	if(document.frmCatagory.txtCatagoryName.value==""){
		alert("Catagory Name should not be blank");
		document.frmCatagory.txtCatagoryName.focus();
		return false;
	}
	document.frmCatagory.action ="catagory.php";
	document.frmCatagory.submit();	
}
function chkProductValidation(val){
	if(document.frmProduct.txtCatagoryName.value==""){
		alert("Please Select the Catagory Name");
		document.frmProduct.txtCatagoryName.focus();
		return false;
	}
	if(document.frmProduct.txtProductName.value==""){
		alert("Product Name should not be blank");
		document.frmProduct.txtProductName.focus();
		return false;
	}
	
	if(document.frmProduct.txtProductPrice.value==""){
		alert("Product Price should not be blank");
		document.frmProduct.txtProductPrice.focus();
		return false;
	}
	if(!IsNumericforReg(document.frmProduct.txtProductPrice.value))
		{
			alert("Please Enter Valid Price");
			document.frmProduct.txtProductPrice.focus();
			return false;
		}
	document.frmProduct.action ="product.php";
	document.frmProduct.submit();	
}
function chkCommentValidation(val){
	if(document.frmComment.txtComment.value==""){
		alert("Please Enter Comment");
		document.frmComment.txtComment.focus();
		return false;
	}
	document.frmComment.action ="comment.php";
	document.frmComment.submit();
}

function cSubmit(){
	if(document.frmClient1.txtClientNo.value==""){
		alert("Please Enter OrderNo");
		document.frmClient1.txtClientNo.focus();
		return false;
	}
	document.frmClient1.action ="validate.php";
	document.frmClient1.submit();
}
function chkOrderValidation(val){
	if(document.frmOrder.txtProductName.disabled==false)
	{
		if(document.frmOrder.txtProductName.value==""){
			alert("Please select the Product Name ");
			document.frmOrder.txtProductName.focus();
			return false;
		}
	}
	if(document.frmOrder.txtClientName.value==""){
		alert("Please select the Client Name ");
		document.frmOrder.txtClientName.focus();
		return false;
	}
	//if(document.frmOrder.txtStatus.value==""){
		//alert("Please enter the Status ");
		//document.frmOrder.txtStatus.focus();
		//return false;
	//}
	if(document.frmOrder.txtOrderDate.value==""){
		alert("Please enter the Order Date ");
		document.frmOrder.txtOrderDate.focus();
		return false;
	}
	if(document.frmOrder.txtEstimatedDate.value==""){
		alert("Please enter the Estimated Date ");
		document.frmOrder.txtEstimatedDate.focus();
		return false;
	}
	if(!document.frmOrder.txtBillingAddress.disabled)
	if(document.frmOrder.txtBillingAddress.value==""){
		alert(" Billing Address should not be blank");
		document.frmOrder.txtBillingAddress.focus();
		return false;
	}
	if(!document.frmOrder.txtBillingAddress.disabled)
	if(document.frmOrder.txtbCity.value == "" ){
		alert("City should not be blank");
		document.frmOrder.txtbCity.focus();
		return false;
	}
	if(!document.frmOrder.txtBillingAddress.disabled)
	if(document.frmOrder.txtbState.value == "" ){
		alert("State should not be blank");
		document.frmOrder.txtbState.focus();
		return false;
	}
	if(!document.frmOrder.txtBillingAddress.disabled)
	if(document.frmOrder.txtbCountry.value == "" ){
		alert("Country should not be blank");
		document.frmOrder.txtbCountry.focus();
		return false;
	}
	if(!document.frmOrder.txtShippingAddress.disabled)
	if(document.frmOrder.txtShippingAddress.value==""){
		alert(" Shipping Address should not be blank");
		document.frmOrder.txtShippingAddress.focus();
		return false;
	}
	if(!document.frmOrder.txtShippingAddress.disabled)
	if(document.frmOrder.txtsCity.value == ""){
		alert("City should not be blank");
		document.frmOrder.txtsCity.focus();
		return false;
	}	
	if(!document.frmOrder.txtShippingAddress.disabled)
	if(document.frmOrder.txtsState.value == ""){
		alert("State should not be blank");
		document.frmOrder.txtsState.focus();
		return false;
	}
	if(!document.frmOrder.txtShippingAddress.disabled)
	if(document.frmOrder.txtsCountry.value == ""){
		alert("Country should not be blank");
		document.frmOrder.txtsCountry.focus();
		return false;
	}
	document.frmOrder.action ="order.php";
	document.frmOrder.submit();	
}
	function chkUserValidation(val){
	if(document.frmUser.txtUName.value == ""){
		alert(" User Name should not be blank");
		document.frmUser.txtUName.focus();
		return false;
	}
	if(document.frmUser.txtUName.value.indexOf("@") == -1){
		alert("Please enter valid Email");
		document.frmUser.txtUName.focus();
		return false;
	}
	if(document.frmUser.txtUName.value.indexOf(".") == -1){
		alert("Please enter valid Email");
		document.frmUser.txtUName.focus();
		return false;
	}
	if(document.frmUser.txtFName.value == ""){
		alert("First Name should not be blank");
		document.frmUser.txtFName.focus();
		return false;
	}	
	if(document.frmUser.txtLName.value == ""){
		alert("Last Name should not be blank");
		document.frmUser.txtLName.focus();
		return false;
	}
	if(document.frmUser.txtPhone.value == ""){
		alert("Phone no should not be blank");
		document.frmUser.txtPhone.focus();
		return false;
	}
	if(!IsNumericforReg(document.frmUser.txtPhone.value))
		{
			alert("Please Enter Valid Phone Number");
			document.frmUser.txtPhone.focus();
			return false;
		}
	if(document.frmUser.selStatus.value==""){
		alert("Please Select the User Status");
		document.frmUser.selStatus.focus();
		return false;
	}	
	document.frmUser.action ="user.php";
	document.frmUser.submit();	
}

	function chkValidation(val){
	if(document.frmClient.txtCName.value == ""){
		alert(" Company Name should not be blank");
		document.frmClient.txtCName.focus();
		return false;
	}
	if(document.frmClient.txtCAddress.value==""){
		alert("Company Address should not be blank");
		document.frmClient.txtCAddress.focus();
		return false;
	}
	if(document.frmClient.txtCCity.value == ""){
		alert("City should not be blank");
		document.frmClient.txtCity.focus();
		return false;
	}	
	if(document.frmClient.txtCState.value == ""){
		alert("State should not be blank");
		document.frmClient.txtState.focus();
		return false;
	}
	
	if(document.frmClient.txtCCountry.value == ""){
		alert("Country should not be blank");
		document.frmClient.txtCountry.focus();
		return false;
	}
	if(document.frmClient.txtCPhoneNo.value == ""){
		alert(" Company Phone should not be blank");
		document.frmClient.txtPhoneNo.focus();
		return false;
	}
	if(!IsNumericforReg(document.frmClient.txtCPhoneNo.value))
		{
			alert("Please Enter Valid Company Phone Number");
			document.frmClient.txtCPhoneNo.focus();
			return false;
		}
	if(document.frmClient.txtUName.value != ""){
		if(document.frmClient.txtUName.value.indexOf("@") == -1){
			alert("Please enter valid Email");
			document.frmClient.txtUName.focus();
			return false;
		}
		if(document.frmClient.txtUName.value.indexOf(".") == -1){
			alert("Please enter valid Email");
			document.frmClient.txtUName.focus();
			return false;
		}
	}		
	if(document.frmClient.txtAddress.value ==""){
		alert("Address should not be blank");
		document.frmClient.txtAddress.focus();
		return false;
	}
	
	if(document.frmClient.txtCity.value == ""){
		alert("City should not be blank");
		document.frmClient.txtCity.focus();
		return false;
	}	
	if(document.frmClient.txtState.value == ""){
		alert("State should not be blank");
		document.frmClient.txtState.focus();
		return false;
	}
	
	if(document.frmClient.txtCountry.value == ""){
		alert("Country should not be blank");
		document.frmClient.txtCountry.focus();
		return false;
	}
	if(document.frmClient.txtFName.value == ""){
		alert("First Name should not be blank");
		document.frmClient.txtFName.focus();
		return false;
	}	
	if(document.frmClient.txtPhoneNo.value == ""){
		alert("Phone should not be blank");
		document.frmClient.txtPhoneNo.focus();
		return false;
	}
	if(!IsNumericforReg(document.frmClient.txtPhoneNo.value))
		{
			alert("Please Enter Valid Phone Number");
			document.frmClient.txtPhoneNo.focus();
			return false;
		}
	document.frmClient.action ="client.php";
	document.frmClient.submit();				
}

function addReg()
{

		///alert("hi");
		if(document.frmRegister.txtEmailID.value == "")
		{
			alert('Please Enter your Email Address');
			document.frmRegister.txtEmailID.focus();
			return false;
		}
		if(document.frmRegister.txtEmailID.value.indexOf("@") == -1 || document.frmRegister.txtEmail.value.indexOf(".") == -1)
		{
			alert("Please Enter Valid Email Address!!!");
			document.frmRegister.txtEmailID.focus();
			return false;
		}
		/*if(document.frmRegister.txtPassword.value == "")
		{
			alert('Please Enter your Password');
			document.frmRegister.txtPassword.focus();
			return false;
		}
		if(document.frmRegister.txtConfPassword.value == "")
		{
			alert('Please Enter your Email Address');
			document.frmRegister.txtConfPassword.focus();
			return false;
		}
		if(document.frmRegister.txtPassword.value != document.frmRegister.txtConfPassword.value)
		{
			alert('password and confirm password are not same');
			document.frmRegister.txtPassword.focus();
			return false;
		}*/
		if(document.frmRegister.txtPhoneNo.value == "")
		{
			alert('Please enter the Phone Number');
			document.frmRegister.txtPhoneNo.focus();
			return false;
		}
	/*	if(document.frmRegister.txtScreen.value.indexOf("@") == -1 || document.frmRegister.txtScreen.value.indexOf(".") == -1)
		{
			alert("Please Enter Valid Screen Name!!!");
			document.frmRegister.txtScreen.focus();
			return false;
		}*/
		if(!IsNumericforReg(document.frmRegister.txtPhoneNo.value))
		{
			return false;
		}
		document.frmRegister.action = "client.php";
		document.frmRegister.submit();

}

function IsNumericforReg(sText)
{   
   var ValidChars = "+0123456789 -()";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
	  		IsNumber = false;
	  }
   }
   return IsNumber;   
 }
 
function deletePhoto(id,photo_id)
{
	
	var ans = confirm("Are you sure want to Delete Photo?");
	if(ans==true)
	{
		document.frmShowPhoto.action = "photo_mgmt.php?do=delete&id="+id+"&photo_id="+photo_id;
		document.frmShowPhoto.submit();
	}
}

function editPhoto(type,FrmPara)
{

	document.frmPhotoAdd.action = FrmPara;
	document.frmPhotoAdd.submit();
}
function editPhotoclient(type,FrmPara)
{
	document.frmPhotoAdd.action = FrmPara;
	document.frmPhotoAdd.submit();
}
function deletePhotoClient(id,photo_id)
{
	
	var ans = confirm("Are you sure want to Delete Photo?");
	if(ans==true)
	{
		document.frmShowPhoto.action = "show_photo.php?do=delete&id="+id+"&photo_id="+photo_id;
		document.frmShowPhoto.submit();
	}
}
function chk1()
	{
			var str=new Array();
			$j=0;
			alert(document.form1.ch.length);
			if(document.form1.ch.length > 1){
			for(var i=0;i<document.form1.ch.length ;i++)
			{
					if(document.form1.ch[i].checked)
					{
					  document.form1.ch[i].checked=true;
					 //alert(document.form1.ch[i].value);
					 str[j]=document.form1.ch[i].value;
					 j++;
					 //alert(str[j]);
					  }
			}
		//alert(str);	
		}
		else
		{
			if(document.form1.ch.checked){
					document.form1.ch.checked=true;
					 //alert(document.form1.ch[i].value);
					 str[j]=document.form1.ch.value;
					 j++;
					  //alert(str);
					  }
		}
		 document.form1.iChk.value=str;
		alert(document.form1.iChk.value);
		
	}
function selectproduct()
{
	var str=new Array();
	var j=0;
			//alert(document.frmSelectProduct.chk.length);
			if(document.frmSelectProduct.chk.length > 1){
			for(var i=0;i<document.frmSelectProduct.chk.length ;i++)
			{
					if(document.frmSelectProduct.chk[i].checked)
					{
					  document.frmSelectProduct.chk[i].checked=true;
					 //alert(document.form1.ch[i].value);
					 str[j]=document.frmSelectProduct.chk[i].value;
					 //alert(str[j]);
					 j++;
					 //alert(str[j]);
					  }
			}
		//alert(str);	
		}
		else
		{
			if(document.frmSelectProduct.chk.checked){
					document.frmSelectProduct.chk.checked=true;
					 //alert(document.form1.ch[i].value);
					 str[j]=document.frmSelectProduct.chk.value;
					 j++;
					  //alert(str);
					  }
		}
		 document.frmSelectProduct.selectedproduct.value=str;
		//alert(document.frmSelectProduct.selectedproduct.value);	
}
function disableproduct()
{
	document.frmOrder.txtProductName.disabled=true;
}

function Inint_AJAX() {
   try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
   try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
   alert("XMLHttpRequest not supported");
   return null;
};

function getStage(val) {
     var req = Inint_AJAX();
		req.onreadystatechange = function () { 
	       if (req.readyState==4) {
	          if (req.status==200) {
	             document.getElementById("stage").innerHTML=req.responseText; //retuen value
              } 
           }
        };
	 req.open("GET", "get_stage.php?val="+val); //make connection
	 
	 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
     req.send(null); //send value
};