// JavaScript Document
function shToggle(content) {
	var id = document.getElementById(content)
	id.style.display="block";
}

//check form fields
function isEmptyF(field)
{
	var fieldValue=document.getElementById(field).value;
	if (fieldValue==""||fieldValue==null||!isNaN(fieldValue))
    {
		return false;
    }
	return true;
}

function isValidEmail(emailfield){
 	emailValue=document.getElementById(emailfield).value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailValue)){
		return (true)
	}
	return false
}

/*function getDateObject(dateString,dateSeperator)
{
	//This function return a date object after accepting 
	//a date string ans dateseparator as arguments
	var curValue=dateString;
	var sepChar=dateSeperator;
	var curPos=0;
	var cDate,cMonth,cYear;
	
	//extract day portion
	curPos=dateString.indexOf(sepChar);
	cMonth=dateString.substring(0,curPos);
	
	//extract month portion 
	endPos=dateString.indexOf(sepChar,curPos+1); cDate=dateString.substring(curPos+1,endPos);
	
	//extract year portion 
	curPos=endPos;
	endPos=curPos+5; 
	cYear=curValue.substring(curPos+1,endPos);
	
	//Create Date Object
	dtObject=new Date(cYear,cMonth,cDate); 
	return dtObject;
}
function checkDate(dstart,dend)
{
	svalue=document.getElementById(dstart).value;
	evalue=document.getElementById(dend).value;
	var startDate = getDateObject(svalue,"-");
	var endDate = getDateObject(evalue,"-");
	if(startDate <= endDate)
	{
		//alert("startDate is less than endDate");
		return true;

	}
	
	if(startDate > endDate)
	{
		alert("Completion Date can't be earlier than Start Date");
		return false;
	}
}
function checkCurrentECM(check,require)
{
	var checkIsCheck=document.getElementById(check).checked;
	var requireValue=document.getElementById(require).value;
	var requireLength=document.getElementById(require).value.length;
	if (checkIsCheck)
	{
		if(requireValue==null||requireLength==0)
		{
			alert ("Please fill in the Vendor Name");
			return false;
		}	
	}
	else
	{
		if(requireValue!=null && requireLength>0)
		{
			alert ("Do you own a document management system?");
			return false;
		}
	}
	return true;
}


function checkformsales(firstname,lastname,company,email,check,require){
	if (isEmptyField(firstname) && isEmptyField(lastname) && isEmptyField(company) && isValidEmailField(email) && checkCurrentECM(check,require)){
			return true;
	}	
	return false;
}

function checkform(firstname,lastname,company,email,question){
	if (isEmptyField(firstname) && isEmptyField(lastname) && isEmptyField(company) && isValidEmailField(email) && isEmptyField(question)){
			return true;
		}	
	return false;
}*/
//check form with start-end date
/*function checkformDate(firstname,lastname,company,email,curVendor,curSoftware,curVersion,newVendor,newSoftware,newVersion,datestart,dateend){
	if (isEmptyField(firstname) && isEmptyField(lastname) && isEmptyField(company) && isValidEmailField(email) && isEmptyField(curVendor) && isEmptyField(curSoftware)&& isEmptyField(curVersion) && isEmptyField(newVendor) && isEmptyField(newSoftware)&& isEmptyField(newVersion) &&checkDate(datestart,dateend)){
			return true;
		}	
	return false;
}*/
//check email add

function checkmailregis(firstname,lastname,email){
	var erstr="Please enter a valid value for: ";
	if(!isEmptyF(firstname)) erstr += "\n- First Name";
	if(!isEmptyF(lastname)) erstr += "\n- Last Name";
	if(!isValidEmail(email)) erstr += "\n- Email";
	
	if (erstr=="Please enter a valid value for: "){
			return true;
	}
	else
	{
		alert(erstr);
		erstr="";
		return false;
	}
}


function getSearch ()
{
  document.searchForm.submit() ;
}

function markLinkChild(linkID)
{	
	var id = document.getElementById(linkID);
	id.style.background="url(images/mark.gif) 12px 5px no-repeat";
   	id.style.width="151px";
	id.style.marginLeft="-30px";
	id.style.paddingLeft="30px";
}
function markLinkMiddle(linkID)
{	
	var id = document.getElementById(linkID);
	id.style.background="url(images/mark.gif) 7px 5px no-repeat";
   	id.style.width="161px";
	id.style.marginLeft="-20px";
	id.style.paddingLeft="20px";
}
function markLinkTop(linkID)
{	
	var id = document.getElementById(linkID);
	id.style.background="url(images/mark.gif) -3px 5px no-repeat";
   	id.style.width="166px";
	id.style.marginLeft="-15px";
	id.style.paddingLeft="15px";
}
function checkoption(c1, c2, idshow, idhide)
{
	ctrl1=document.getElementById(c1);
	ctrl2=document.getElementById(c2);
	id1=document.getElementById(idshow);
	id2=document.getElementById(idhide);
	ctrl1.checked=true;
	ctrl2.checked=false;
	id1.style.display='block';
	id2.style.display='none';

}

function clearForms()
{
  var i;
  for (i = 0; (i < document.forms.length); i++) {
	document.forms[i].reset();
  }
}

function validateTextField(fieldName, fieldID)
{	
	var fieldValue=fieldID.value;
	if (fieldValue==""||fieldValue==null||!isNaN(fieldValue))
    {
		alert("Please input a valid value for " + fieldName + " field");
		fieldID.focus();
		fieldID.select();
		return false;
    }
	return true;
}

function validateEmailField(fieldID)
{
  /*validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  emailValue=fieldID.value;

   if (emailValue.search(validRegExp)==-1) 
   {
      alert("Please input a valid email address");
      return false;
    } 
    return true; */
	emailValue=fieldID.value;
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailValue)){
		return (true)
	}
	alert("Please input a valid email address")
	fieldID.focus();
	fieldID.select();
	return (false)

}

function validateDField(DateID)
{
	var DateValue=DateID.value;
 	if (DateValue && !DateValue.replace(/^\s+/).replace(/\s+$/).match(/\d{1,4}[\D\W]+\d{1,4}[\D\W]\d{2,4}/))
    {
       alert("Please input a valid date.");
       DateID.focus();
       DateID.select();
	   return false;
    }
	return true;
}

/*function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}onkeypress="return imposeMaxLength(this, 400);"*/

function textarea(fieldName, fieldID)
{
	var fieldValue=fieldID.value;
	if (fieldValue==""||fieldValue==null||!isNaN(fieldValue))
    {
		alert("Please input a valid value for " + fieldName + " field");
		fieldID.focus();
		fieldID.select();
		return false;
    }
	if (fieldValue.length>400)
	{
		alert("Questions/Comment text limit 400 characters – please abbreviate.");
		fieldID.focus();
		fieldID.select();
		return false;
	}
	return true;		
}
function textareanotrequire(fieldID)
{
	var fieldValue=fieldID.value;
	if (fieldValue.length>400)
	{
		alert("Questions/Comment text limit 400 characters – please abbreviate.");
		fieldID.focus();
		fieldID.select();
		return false;
	}
	return true;		
}

