//This function is to eliminate the leading spaces in a string

function ltrim(string)

  {

    string=new String(string);

    var string1=new Array();

    var i,j;

    for(i=0,j=0;i<string.length;i++)

    {

      if(j==0)

      {

        if(string.charAt(i)!=" ")

        {

            string1[j++]=string.charAt(i);

        }

      }

      else

      {

        string1[j++]=string.charAt(i);

      }

        

    }

    string="";

    for(i=0;i<string1.length;i++)

    {

      string+=string1[i];

    } 

    return string;

  }

//This function is to eliminate the trailing spaces in a string.

function rtrim(string)

  {

    string=new String(string);

    var string1=new Array();

    var i,j;

    for(i=string.length;i>=0;i--)

    {

      if(string.charAt(i-1)==" ")

      {

        continue;

      }

      else

      {

        for(j=0;j<i;j++)

        {

          string1[j]=string.charAt(j);

        }

        break;

      }

        

    }

    string="";

    for(i=0;i<string1.length;i++)

    {

      string+=string1[i];

    }

    

    

    return string;

  }

  

//This function combines the above two functions to elimnate the leading and trailing spaces from the string

function trim(string)

  {

    string=ltrim(string); // // This function is used to trim the left side of a String

    string=rtrim(string);// This function is used to trim the right side of a String

    return string;

  }

//for search page validation

function skey()

{

	if(trim(document.frmCreate.txtTitle.value) == "")

	{

		alert("Enter a key word");

		document.frmCreate.txtTitle.value = "";

		document.frmCreate.txtTitle.focus();

		return false;

	}

	if((!document.frmCreate.kbase.checked)&&(!document.frmCreate.faq.checked)&&(!document.frmCreate.paper.checked)&&(!document.frmCreate.all.checked))

	{

		alert("Select a search criteria");

		return false;

	}

}

function foc()

{

	document.frmCreate.txtTitle.focus();

}



//function to validate login page

function login_validate()

{	

	if(trim(document.frmlogin.txtusername.value)=="")

	{

		alert("Please enter User Name");

		document.frmlogin.txtusername.focus();

		return false;

	}

	if(trim(document.frmlogin.txtpassword.value)=="")

	{

		alert("Please enter Password");

		document.frmlogin.txtpassword.focus();

		return false;

	}

}



//function for getting focus to the user name field

function focusname()

{

	document.frmlogin.txtusername.focus();

}



function addkbase()

{

	if(trim(document.frmcreatekbase.txtTitle.value)=="")

	{

		alert("Please enter the Title");

		document.frmcreatekbase.txtTitle.focus();

		return false;

	}

	if(trim(document.frmcreatekbase.slProduct.value)=="not")

	{

		alert("Please Select a Product");

		return false;

	}

}



//function for getting focus to the username field in login page

function focustitle()

{

	document.frmcreatekbase.txtTitle.focus();

}



//function to validate the call creation page.

function frmcreatecall_validate()

{

	if(document.frmcreatecall.sel_customer.value=="select")

	{

		alert("Please select the Customer");

		document.frmcreatecall.sel_customer.focus();

		return false;

	}

	if(document.frmcreatecall.sel_user.value=="select")

	{

		alert("Please select the User");

		document.frmcreatecall.sel_user.focus();

		return false;

	}

	if(trim(document.frmcreatecall.txtemail.value)=="")

	{

		alert("Please enter your email");

		document.frmcreatecall.txtemail.focus();

		return false;

	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmcreatecall.txtemail.value)))

    {

      alert("Please Enter Valid Email");

      document.frmcreatecall.txtemail.focus();

      return false;

    }

	if(trim(document.frmcreatecall.txtemail.value)=="")

	{

		alert("Please enter your email");

		document.frmcreatecall.txtemail.focus();

		return false;

	}

	if(trim(document.frmcreatecall.txtphone.value)=="")

	{

		alert("Please enter your Phone Number");

		document.frmcreatecall.txtphone.focus();

		return false;

	}
	
	if(document.frmcreatecall.selproduct.value=="select")

	{

		alert("Please select the Product");

		document.frmcreatecall.selproduct.focus();

		return false;

	}

	if(trim(document.frmcreatecall.txtproblem.value)=="")

	{

		alert("Please enter your Problem Title");

		document.frmcreatecall.txtproblem.focus();

		return false;

	}

	if(trim(document.frmcreatecall.txtdescription.value)=="")

	{

		alert("Please give your Problem Description");

		document.frmcreatecall.txtdescription.focus();

		return false;

	}

	if(trim(document.frmcreatecall.txtcontactmethod.value)=="")

	{

		alert("Please give your Preferred method of contact");

		document.frmcreatecall.txtcontactmethod.focus();

		return false;

	}

}



//function to fill the user names when the customer is selected.

function frmcreatecall_filluser()

{

	if(document.frmcreatecall.sel_customer.value!="select")

	{

		document.frmcreatecall.action="create_call.php";

		document.frmcreatecall.submit();

	}

	else

	{

		

		return;

	}

}



//function to fill the product names when the user is selected.

function frmcreatecall_fillproduct()

{

	if(document.frmcreatecall.sel_user.value!="select")

	{

		document.frmcreatecall.action="create_call.php";

		document.frmcreatecall.submit();

	}

	else

	{

		return;

	}

}



//function to validate the edit call page

function frmeditcall_validate()

{

	if(document.frmeditcall.sel_customer.value=="select")

	{

		alert("Please select the Customer");

		document.frmeditcall.sel_customer.focus();

		return false;

	}

	if(document.frmeditcall.sel_user.value=="select")

	{

		alert("Please select the User");

		document.frmeditcall.sel_user.focus();

		return false;

	}

	if(trim(document.frmeditcall.txtemail.value)=="")

	{

		alert("Please enter your email");

		document.frmeditcall.txtemail.focus();

		return false;

	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.frmeditcall.txtemail.value)))

    {

      alert("Please Enter Valid Email");

      document.frmeditcall.txtemail.focus();

      return false;

    }

	if(trim(document.frmeditcall.txtemail.value)=="")

	{

		alert("Please enter your email");

		document.frmeditcall.txtemail.focus();

		return false;

	}

	if(trim(document.frmeditcall.txtphone.value)=="")

	{

		alert("Please enter your Phone Number");

		document.frmeditcall.txtphone.focus();

		return false;

	}
	
	if(document.frmeditcall.selproduct.value=="select")

	{

		alert("Please select a Product");

		document.frmeditcall.selproduct.focus();

		return false;

	}

	if(trim(document.frmeditcall.txtproblem.value)=="")

	{

		alert("Please enter your Problem Title");

		document.frmeditcall.txtproblem.focus();

		return false;

	}

	if(trim(document.frmeditcall.txtdescription.value)=="")

	{

		alert("Please give your Problem Description");

		document.frmeditcall.txtdescription.focus();

		return false;

	}

	if(trim(document.frmeditcall.txtcontactmethod.value)=="")

	{

		alert("Please give your Preferred method of contact");

		document.frmeditcall.txtcontactmethod.focus();

		return false;

	}

}



//function to fill the usernames when the customer name is selected.

function frmeditcall_filluser(id)

{

	if(document.frmeditcall.sel_customer.value!="select")

	{

		document.frmeditcall.action="editcall.php?cid="+id;

		document.frmeditcall.submit();

	}

	else

	{

		return;

	}

}



//function to fill the product names when the user name is selected.

function frmeditcall_fillproduct(id)

{

	if(document.frmeditcall.sel_user.value!="select")

	{

		document.frmeditcall.action="editcall.php?cid="+id;

		document.frmeditcall.submit();

	}

	else

	{

		return;

	}

}



//function to clear the existing uploaded file field in the edit call page.

function clearfile()

{

	document.frmeditcall.existingfile.value="";

	filespan.innerHTML="";

}



	

//function to edit an ongoing call

function editcall(id)

{

	document.frmongoingcalls.action="editcall.php?menu=call&cid="+id;

	document.frmongoingcalls.submit();

}

/*	

//function to delete an ongoing call.

function deletecall(id)

{

	//if(confirm("Do you really want to delete the call"))

	{

		document.frmongoingcalls.action="deletecall.php?cid="+id;

		document.frmongoingcalls.submit();

	}

}



//function to close an ongoing call.

function closecall(id)

{

	if(confirm("Are you sure you want to close call reference "+id+"?"))

	{

		document.frmongoingcalls.action="closeongoingcall.php?cid="+id;

		document.frmongoingcalls.submit();

	}

}

*/

//function to view and ongoing call.

function viewcall(id)

{

	document.frmongoingcalls.action="viewongoingcall.php?menu=call&cid="+id;

	document.frmongoingcalls.submit();

}



//function  to view a closed call

function viewclosedcall(id)

{

	document.frmclosedcalls.action="viewclosedcall.php?menu=call&cid="+id;

	document.frmclosedcalls.submit();

}



/*

//function to move to the closed calls page from the page to view the details of a closed call.

function movetoclosedcalls(id)

{

	document.frmviewclosedcall.action="closedcalls.php?"+id;

	document.frmviewclosedcall.submit();

}



//function to move to the closed calls page from the page to view the details of a closed call if the url variable is not set.

function movetoclosedcalls1()

{

	document.frmviewclosedcall.action="closedcalls.php";

	document.frmviewclosedcall.submit();

}

*/



function createfaq_validation()

{

	

	if(trim(document.frmcreatefaq.txt_title.value)=="")

	{

		alert("Please enter title");

		document.frmcreatefaq.txt_title.focus();

		return false;

	}

	if(trim(document.frmcreatefaq.txta_details.value)=="")

	{

		alert("Please enter details");

		document.frmcreatefaq.txta_details.focus();

		return false;

	}

	document.frmcreatefaq.submit();

}

function confirmDelete(id)

{

	var msg;

	msg=confirm("Are you sure you want to delete this FAQ");

	if (msg==true)

	{ 

		document.frmdeletefaq.action="delete_faq1.php?&menu=faq&f_id="+id;

		document.frmdeletefaq.submit();

	}

	else

	{

		return false;

	}

}



//function to redirect the page to the paper and guidance download page.

function download(pid)

{

document.frmpaper.action="paper_guidance_download.php?pid="+pid;

document.frmpaper.submit();

}

