function checkEmail()
	{
	var strEmail, strError, countAtRate, countDot, i;
	var checkAtRate, checkDot;
	var ValidChars,CountValidChars;
	ValidChars="abcdefghijklmnopqrstuvwxyz0123456789_.@ABCDEFGHIJKLMNOPQRSTUVWXYZ-";
	strEmail = checkEmail.arguments[0];
	countAtRate=0;
	countDot=0;
	CountValidChars=0;
	if (strEmail.length >= 7)
		{
		for(i=0;i<strEmail.length;i++)
			{
			if(strEmail.charAt(i)=="@")
				countAtRate++;
			if(strEmail.charAt(i)==".")
				countDot++;
			CountValidChars=0;
			for(j=0;j<ValidChars.length;j++)
				{
				if(strEmail.charAt(i)==ValidChars.charAt(j))
					{
					CountValidChars++;
					}
				}
			if(CountValidChars==0)
				{
				strError=0;
				break;
				}
			}
		}
	checkAtRate=strEmail.indexOf("@",1);
	checkDot=strEmail.indexOf(".",1);
	for(i=1;i<countDot;i++)
		checkDot=strEmail.indexOf(".",checkDot+1);
	if(countAtRate==1 && countDot > 0 && strEmail.length >=7 && strError != 0)
		strError=1;
	else
		strError=0;
	if(checkDot>=strEmail.length-2)
		strError=0;
	if(strEmail.charAt(0)=="@" || strEmail.charAt(strEmail.length-1)=="@")
		strError=0;
	if(strEmail.charAt(0)=="." || strEmail.charAt(strEmail.length-1)==".")
		strError=0;
	if(checkDot < checkAtRate)
		strError=0;

	return strError;
}

/*------------------------------------------------------------------------*/

function chkSpace(txtfield)
{
	var i,j;
	j=0;
	txtfield=eval(txtfield)
	var txtval=txtfield.value;
	for(i=0;i<txtval.length;i++)
	{
		j++
		if(txtval.substr(i,1)!=" ")
			break;
	}
	txtval=txtval.substr(j-1,txtval.length);
	if(txtval==" ")
	   txtval="";

	txtfield.value=txtval;
	return(txtval);

}

/*------------------------------------------------------------------------*/

function checkInt(txtfield)
{
	txtfield=eval(txtfield)
	txtval=txtfield.value;
	var newVal=parseInt(txtval);
	if (isNaN(newVal))
		txtfield.value=0;
	else if (newVal<0)
		txtfield.value=0;
	else
		txtfield.value=newVal;
}

/*------------------------------------------------------------------------*/

function checkCur(ObjName)
{
	ObjectName=eval("document.frm."+ObjName);
	ObjVal = '' + ObjectName.value;
	if(ObjVal=="") ObjVal="0";
		for(i=0;i<ObjVal.length;i++)
		    ObjVal=ObjVal.replace(",","");
		for(i=0;i<ObjVal.length;i++)
		    ObjVal=ObjVal.replace("-","");

	if(isNaN(ObjVal)==true)
   	{
		ObjectName.value="0.00"
   	}
	else
	{
		var NegSign="";
      	if(ObjVal.substr(0,1)=="-") {NegSign="-";}
   		ObjVal=parseFloat(ObjVal);
   		PInt=parseInt(ObjVal);
   		PtValue=".00";
   		PInt=Math.abs(PInt);
   		ObjVal=Math.abs(ObjVal);
   		PInt='' + PInt;
   		ObjVal=''+ ObjVal;
   		if(PInt.length!=ObjVal.length)
   		{
			PtValue='' + ObjVal.substr(ObjVal.indexOf("."),ObjVal.length);
		}
		if (PInt.length > 3)
   	    {
			var mod = PInt.length % 3;
       		var output = (mod > 0 ? (PInt.substring(0,mod)) : '');
       		for (i=0 ; i < Math.floor(PInt.length / 3); i++)
       		{
				if ((mod == 0) && (i == 0))
					output += PInt.substring(mod+ 3 * i, mod + 3 * i + 3);
				else
					output+= '' + PInt.substring(mod + 3 * i, mod + 3 * i + 3);
	   		}
       		ObjectName.value=NegSign+output+PtValue;
		}
		else ObjectName.value=NegSign+PInt+PtValue;
 	}
}

/*------------------------------------------------------------------------*/

var errMsg="";
function SubmitLink()
{
	ObjForm=document.frm;
	if(ObjForm.CmbCategory.selectedIndex<1)
		errMsg="- Please select the category";
	if(chkSpace(ObjForm.SiteName)=="")
		errMsg+="\n- Site Name";
	if(chkSpace(ObjForm.SiteURL)=="")
		errMsg+="\n- URL of the Site";
	if(chkSpace(ObjForm.Detail)=="")
		errMsg+="\n- Description";
	else
	{
		if(ObjForm.Detail.value.length>250)
			errMsg+="\n- Description cannot be more than 250 chars";
	}
	if(chkSpace(ObjForm.Name)=="")
		errMsg+="\n- Your Name";
	if(checkEmail(ObjForm.Email.value)==0)
		errMsg+="\n- Your Email Address";

	if(errMsg=="")
	{
		ObjForm.method="post";
		ObjForm.action="http://www.investmentpropertyguy.com/LinkManager/SubmitLink.asp"
		ObjForm.submit();
	}
	else
	{
		alert("Please complete the following fields:\n_____________________________\n"+errMsg)
		errMsg="";
	}
}

/*------------------------------------------------------------------------*/

function checkAll()
{
        if(document.frm.chkall.checked)
      	  {
           for(i=0;i<document.frm.chkid.length;i++)
              document.frm.chkid[i].checked=true;
	  }
        else
      	  {
           for(i=0;i<document.frm.chkid.length;i++)
              document.frm.chkid[i].checked=false;
	  }
}

/*------------------------------------------------------------------------*/

function ApproveData()
{

if(document.frm.chkid.length>=2)
{
 var counter=0;
 for(i=0;i<document.frm.chkid.length;i++)
 {
  if(document.frm.chkid[i].checked)
    counter++;
 }
 if(counter>=1)
   {
    if(confirm("Are you sure to Approve [ "+counter+" ] Data")==true)
    {
    document.frm.method="post";
    document.frm.action="PendingLinks.asp?FuncMod=Approve"
    document.frm.submit();
    }
   }
 if(counter==0)
   alert("Please select any one data to Approve");
 }
else
     {
        if(document.frm.chkid.checked)
      	  {
           if(confirm("Are you sure to Approve the selected Data")==true)
           {
           document.frm.method="post";
           document.frm.action="PendingLinks.asp?FuncMod=Approve"
           document.frm.submit();
           }
  	  }
       else
 	 {
  	  alert("Please select any one data to Approve");
	 }
     }
}


/*------------------------------------------------------------------------*/

function RejectData()
{

if(document.frm.chkid.length>=2)
{
 var counter=0;
 for(i=0;i<document.frm.chkid.length;i++)
 {
  if(document.frm.chkid[i].checked)
    counter++;
 }
 if(counter>=1)
   {
    if(confirm("Are you sure to Reject [ "+counter+" ] Data")==true)
    {
    document.frm.method="post";
    document.frm.action="PendingLinks.asp?FuncMod=Reject"
    document.frm.submit();
    }
   }
 if(counter==0)
   alert("Please select any one data to Reject");
 }
else
     {
        if(document.frm.chkid.checked)
      	  {
           if(confirm("Are you sure to Reject the selected Data")==true)
           {
           document.frm.method="post";
           document.frm.action="PendingLinks.asp?FuncMod=Reject"
           document.frm.submit();
           }
  	  }
       else
 	 {
  	  alert("Please select any one data to Reject");
	 }
     }
}

/*------------------------------------------------------------------------*/

function DeleteData()
{

if(document.frm.chkid.length>=2)
{
 var counter=0;
 for(i=0;i<document.frm.chkid.length;i++)
 {
  if(document.frm.chkid[i].checked)
    counter++;
 }
 if(counter>=1)
   {
    if(confirm("Are you sure to Delte [ "+counter+" ] Data")==true)
    {
    document.frm.method="post";
    document.frm.action="ApprovedLinks.asp?FuncMod=Delete"
    document.frm.submit();
    }
   }
 if(counter==0)
   alert("Please select any one data to Reject");
 }
else
     {
        if(document.frm.chkid.checked)
      	  {
           if(confirm("Are you sure to Delete the selected Data")==true)
           {
           document.frm.method="post";
           document.frm.action="ApprovedLinks.asp?FuncMod=Delete"
           document.frm.submit();
           }
  	  }
       else
 	 {
  	  alert("Please select any one data to Reject");
	 }
     }
}

/*------------------------------------------------------------------------*/

function ChangeBgCol()
{

	ObjChk=ChangeBgCol.arguments[0];
	ObjTR=ChangeBgCol.arguments[0];
	if(ObjChk.checked)
		ObjTR.bgcolor="#F5FFD7";
	else
		ObjTR.bgcolor="#FFE2C6";
}

/*------------------------------------------------------------------------*/

function AddNewCategory()
{
	if(chkSpace(document.frm.Category)=="")
		alert("Please supply the category name")
	else
	{
		document.frm.method="post";
		document.frm.action="AdminLinkCats.asp?FuncMod=AddCategory"
		document.frm.submit();
	}
}


/*------------------------------------------------------------------------*/

function DelCat()
{
	if(confirm("Are you sure to delete the selected Category\nAll the links under this category will also be deleted permanently from the database\nPlease cofirm before you proceed\nYou will not be able to Undo this action"))
		window.location.href="AdminLinkCats.asp?FuncMod=DelCat&CatID="+DelCat.arguments[0];
}


/*------------------------------------------------------------------------*/

function ChangePassword()
{
	if(chkSpace(document.PwdForm.OPwd)=="")
		errMsg+="- Old Password\n";
	if(document.PwdForm.NPwd.value.length<6)
		errMsg+="- New password must be at least 6 chars\n";
	else
	{
		if(document.PwdForm.NPwd.value!=document.PwdForm.VNPwd.value)
		 errMsg+="- New password and confirm password does not match\n";
	}


	if(errMsg=="")
	{
		document.PwdForm.method="post";
		document.PwdForm.action="AdPwd.asp?FuncMod=ChangePwd"
		document.PwdForm.submit();
	}

	else
	{
	  alert("Please complete the following fields:\n____________________________\n"+errMsg)
	  errMsg="";
	}
}

/*------------------------------------------------------------------------*/

function SubmitRecLink()
{
	if(chkSpace(document.frm.RecLink)=="")
		alert("Please enter the URL")
	else
	{
		document.frm.method="post";
		document.frm.action="recLink.asp?FuncMod=Submit&submitID="+SubmitRecLink.arguments[0];
		document.frm.submit();
	}
}