// validation for b2b_trade_add.asp start
function validation_b2b_trade_add()
{
if(document.all.txtName.value=="")
	{
		alert("Enter Name.");
		document.all.txtName.focus();
		return false;
	}

	
if(FunScriptTagValidation(document.all.txtName.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtName.focus();
	return false;	
}
else
{
	document.all.txtName.value=replaceunwantedcharacters(document.all.txtName.value);
}



if(FunScriptTagValidation(document.all.txtOrganization.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtOrganization.focus();
	return false;	
}
else
{
	document.all.txtOrganization.value=replaceunwantedcharacters(document.all.txtOrganization.value);
}

	
if(document.all.txtEmail.value=="")
	{
		alert("Enter Email.");
		document.all.txtEmail.focus();
		return false;
	}
	
	else
	{
	if((document.all.txtEmail.value.indexOf("@")==-1)||(document.all.txtEmail.value.indexOf(".")==-1))
		{
			alert("Enter the valid email address");
			document.all.txtEmail.focus();
			return false;
		}
	}
	
	
if(FunScriptTagValidation(document.all.txtEmail.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtEmail.focus();
	return false;	
}
else
{
	document.all.txtEmail.value=replaceunwantedcharacters(document.all.txtEmail.value);
}

if(FunScriptTagValidation(document.all.txtCountry.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtCountry.focus();
	return false;	
}
else
{
	document.all.txtCountry.value=replaceunwantedcharacters(document.all.txtCountry.value);
}
	
	if(document.all.txtDesc.value=="")
	{
		alert("Enter Description.");
		document.all.txtDesc.focus();
		return false;
	}
	
if(FunScriptTagValidation(document.all.txtDesc.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtDesc.focus();
	return false;	
}
else
{
	document.all.txtDesc.value=replaceunwantedcharacters(document.all.txtDesc.value);
}
		
	if(document.all.txtTradeLeads.value=="")
	{
		alert("Enter Trade Leads.");
		document.all.txtTradeLeads.focus();
		return false;
	}
		
if(FunScriptTagValidation(document.all.txtTradeLeads.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtTradeLeads.focus();
	return false;	
}
else
{
	document.all.txtTradeLeads.value=replaceunwantedcharacters(document.all.txtTradeLeads.value);
}
	
	return true;

}

// validation for b2b_trade_add.asp end


// validation for b2b_trade_Reply.asp start
function validation_b2b_trade_Reply()
{
if(document.all.txtName.value=="")
	{
		alert("Enter Name.");
		document.all.txtName.focus();
		return false;
	}
	
if(FunScriptTagValidation(document.all.txtName.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtName.focus();
	return false;	
}
else
{
	document.all.txtName.value=replaceunwantedcharacters(document.all.txtName.value);
}
	
if(document.all.txtEmail.value=="")
	{
		alert("Enter Email.");
		document.all.txtEmail.focus();
		return false;
	}
	
	else
	{
	if((document.all.txtEmail.value.indexOf("@")==-1)||(document.all.txtEmail.value.indexOf(".")==-1))
		{
			alert("Enter the valid email address");
			document.all.txtEmail.focus();
			return false;
		}
	}
	
if(FunScriptTagValidation(document.all.txtEmail.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtEmail.focus();
	return false;	
}
else
{
	document.all.txtEmail.value=replaceunwantedcharacters(document.all.txtEmail.value);
}
	
	if(document.all.txtReply.value=="")
	{
		alert("Enter Reply.");
		document.all.txtReply.focus();
		return false;
	}
	
if(FunScriptTagValidation(document.all.txtReply.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.all.txtReply.focus();
	return false;	
}
else
{
	document.all.txtReply.value=replaceunwantedcharacters(document.all.txtReply.value);
}

	return true;
}

// validation for b2b_trade_Reply.asp end


// validation for Partner_Login.asp start
function Partner_Login_validation()
{
	if(document.form1.userid.value=="")
		{
			alert("You should not leave blank User ID.");
			document.form1.userid.focus();
			return false;
		}
		
		if(FunScriptTagValidation(document.form1.userid.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.userid.focus();
			return false;	
		}
		else
		{
			document.form1.userid.value=replaceunwantedcharacters(document.form1.userid.value);
		}

		if(document.form1.password.value=="")
		{
			alert("You should not leave blank Password.");
			document.form1.password.focus();
			return false;
		}
		
	if(FunScriptTagValidation(document.form1.password.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.password.focus();
			return false;	
		}
		else
		{
			document.form1.password.value=replaceunwantedcharacters(document.form1.password.value);
		}

	return true;
}
// validation for Partner_Login.asp end



// validation for delete confirmation start

function delete_confirm()
  {
  var r=confirm("Are you sure you want to delete")
  if (r==true)
    {
    return true;
    }
  else
    {
    return false;
    }
  }

// validation for delete confirmation start end

//validation for validation_Partner_Profile_edit start

function validation_Partner_Profile_edit()
{
	
	
	if(FunScriptTagValidation(document.form1.txtDesc.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.txtDesc.value=replaceunwantedcharacters(document.form1.txtDesc.value);
			//document.getElementById('txtDesc').innerHTML=replaceunwantedcharacters(document.getElementById('txtDesc').innerHTML);
			//alert(document.getElementById('txtDesc').body.innerHTML);
		}
		
		if(FunScriptTagValidation(document.form1.fileUpload.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.fileUpload.value=replaceunwantedcharacters(document.form1.fileUpload.value);
		}
		
	return true;	
}
//validation for validation_Partner_Profile_edit end


//validation for Partner_Investment_Opportunities_Edit.asp start
function validation_Partner_Investment_Opportunities_Edit()
{
	
	if(FunScriptTagValidation(document.form1.txtDesc.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.txtDesc.value=replaceunwantedcharacters(document.form1.txtDesc.value);
		}
		
	return true;	
}
//validation for Partner_Investment_Opportunities_Edit.asp end

//validation for validation_Partner_Contact_information_Edit start
function validation_Partner_Contact_information_Edit()
{
	
	if(FunScriptTagValidation(document.form1.txtDesc.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.txtDesc.value=replaceunwantedcharacters(document.form1.txtDesc.value);
		}
		
	return true;	
}
//validation for validation_Partner_Contact_information_Edit end




//validation for validation_Partner_Contact_information_Edit start
function validation_Partner_Upcoming_Events_Edit()
{
	
	if(FunScriptTagValidation(document.form1.txtDesc.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.txtDesc.value=replaceunwantedcharacters(document.form1.txtDesc.value);
		}
		
	return true;	
}
//validation for validation_Partner_Contact_information_Edit end

//validation for validation_Partner_news_media_Edit start
function validation_Partner_news_media_Edit()
{
	
	if(FunScriptTagValidation(document.form1.txtDesc.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			return false;	
		}
		else
		{
			document.form1.txtDesc.value=replaceunwantedcharacters(document.form1.txtDesc.value);
		}
		
	return true;	
}
//validation for validation_Partner_news_media_Edit end


// validation for Partner_Changepassword_validation start
function Partner_Changepassword_validation()
{
	if(document.form1.userid.value=="")
		{
			alert("You should not leave blank User ID.");
			document.form1.userid.focus();
			return false;
		}
		
		if(FunScriptTagValidation(document.form1.userid.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.userid.focus();
			return false;	
		}
		else
		{
			document.form1.userid.value=replaceunwantedcharacters(document.form1.userid.value);
		}

		if(document.form1.password.value=="")
		{
			alert("You should not leave blank Password.");
			document.form1.password.focus();
			return false;
		}
		
	if(FunScriptTagValidation(document.form1.password.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.password.focus();
			return false;	
		}
		else
		{
			document.form1.password.value=replaceunwantedcharacters(document.form1.password.value);
		}
		
		if(document.form1.newpassword.value=="")
		{
			alert("You should not leave blank New Password.");
			document.form1.newpassword.focus();
			return false;
		}
		
	if(FunScriptTagValidation(document.form1.newpassword.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.newpassword.focus();
			return false;	
		}
		else
		{
			document.form1.newpassword.value=replaceunwantedcharacters(document.form1.newpassword.value);
		}
		
		
		if(document.form1.retypenewpassword.value=="")
		{
			alert("You should not leave blank Retype New Password.");
			document.form1.retypenewpassword.focus();
			return false;
		}
		
	if(FunScriptTagValidation(document.form1.retypenewpassword.value)==false)
		{	
			alert("Please do not use Single quote, Semi colon, --  characters.");
			document.form1.retypenewpassword.focus();
			return false;	
		}
		else
		{
			document.form1.retypenewpassword.value=replaceunwantedcharacters(document.form1.retypenewpassword.value);
		}
		
		if(document.form1.newpassword.value!=document.form1.retypenewpassword.value)
		{
			alert("New Password and Retype New Password should be same.");
			document.form1.newpassword.focus();
			return false;
		}

	return true;
}
// validation for Partner_Changepassword_validation end

//validation for b2b-trade.asp start
function validation_b2b_trade_search()
{
	
if(FunScriptTagValidation(document.frmb2btradeleads.txtsearchb2btradeleads.value)==false)
{	
	alert("Please do not use Single quote, Semi colon, --  characters.");
	document.frmb2btradeleads.txtsearchb2btradeleads.focus();
	return false;	
}
else
{
	document.frmb2btradeleads.txtsearchb2btradeleads.value=replaceunwantedcharacters(document.frmb2btradeleads.txtsearchb2btradeleads.value);
}
document.frmb2btradeleads.submit();

return true;
}
//validation for b2b-trade.asp end

// script tag validation function start
function FunScriptTagValidation(data)
	{
		str=data.toLowerCase();
		str=removespacesfromstring(str);
		var flag=true;
		if(str.indexOf("<script>")!=-1 || str.indexOf("</script>")!=-1 || str.indexOf("<script")!=-1 || str.indexOf("script>")!=-1
		|| str.indexOf("</script")!=-1)
		{
			flag=false;				
		}
		return flag;
		
		/*var bool=true;
		var bool1=true;
		var returnBool=true;
		var charval;
		
		data=data.toLowerCase();
				
		charval=data.indexOf("<");
		if(bool==true)
		{
			if(eval(charval)!=-1)
			{
				bool=false;
			}
		}
		charval=data.indexOf(">");
		if(bool==false)
		{
			if(eval(charval)!=-1)
			{
				bool1=false;
			}
		}
		charval=data.indexOf("script");
		if(bool1==false)
		{
			if(eval(charval)!=-1)
			{
				returnBool=false;
			}
		}
		
		if(returnBool==true)
		{
			return true;
		}
		else
		{
			return false;
		}*/		
	}
// script tag validation function end

// function to remove spaces from string start
function removespacesfromstring(str)
{
var tempstr;
tempstr=str;
tempstr=tempstr.replace (/\s+/g, '');
return tempstr;
}
// function to remove spaces from string end


// function replace function for unwanded character start
function replaceunwantedcharacters(str)
{
	/*var tempstr=str;
	tempstr=replaceSubstring(str, "'", "`")
	return tempstr;
	*/	
	var tempstr;
	tempstr=str;
	tempstr=tempstr.replace (/'+/g, '`');
	return tempstr;
}

function replaceSubstring(inputString, fromString, toString) 
{
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
// function replace function for unwanded character end


