function printDocument()
{
	var filename = /\/([^\/]+$)/.exec(location.pathname);
	if (filename != null && filename.length > 1 && filename[1].substring(0, 12) == "content.aspx")
		window.open("print.aspx" + location.search, "print", "");
	else
		window.print();
}

/*
	Validate a form's elements according to varius attributes
*/
function validateForm(form, title, submit)
{
	var i, j, u, sum;
	var input;
	var valid;
	var sErrorMsg = "";

	for (i=0; i<form.elements.length; i++)
	{
		input = form.elements[i];
		// skip input when it's not rendered (ie. parent display:none)
		if (input.offsetHeight == 0) continue;
		valid = true;

		// Validate value according to element type and validation type
		switch (input.type.toLowerCase())
		{
		case "text":
		case "password":
		case "textarea":
		case "file":
			if (!input.getAttribute("validation"))
				input.setAttribute("validation", "string");
			if (input.getAttribute("mandatory"))
			{
				if (input.getAttribute("mandatory").toLowerCase() != "true" && input.value.length == 0)
					continue;
			}
			else
				if (input.value.length == 0)
					continue;
			switch (input.getAttribute("validation").toLowerCase())
			{
			case "string":
			case "password":
				if (input.value.length == 0)
					valid = false;
				break;
			case "integer":
				if (!/\d+/.test(input.value))
					valid = false;
				break;
			case "email":
				if (!/^[\w\.\-]+@[\w\-]+(\.\w+)+$/.test(input.value))
					valid = false;
				break;
			case "phone":
				if (!/^\+?\d+(-\d+)*$/.test(input.value))
					valid = false;
				break;
			case "id":
				j = input.value.toString();
				input.value = j.replace(/\D/g, "");
				if (/\d+/.test(input.value))
				{
					sum = 0;
					for (j=0; j<input.value.length; j++)
					{
						u = (j % 2 ? 2 : 1) * parseInt(input.value.charAt(input.value.length - j - 1));
						sum += u > 9 ? Math.floor(u / 10) + u % 10 : u;
					}
					if (sum % 10) valid = false;
				}
				else
					valid = false;
				break;
			case "compare":
				// Check the compareInput attribute
				if (input.getAttribute("compareInput"))
					if (input.value != form.elements[input.getAttribute("compareInput")].value)
						valid = false;
				break;
			default:
				var regExp = new RegExp(input.getAttribute("validation"), "im");
				valid = regExp.test(input.value);
			}

			// Validate max and min according to validation type
			if (valid == true)
			{
				switch (input.getAttribute("validation").toLowerCase())
				{
				case "integer":
					if (input.getAttribute("validmax"))
					{
						if (parseInt(input.value) > parseInt(input.getAttribute("validmax")))
							valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (parseInt(input.value) < parseInt(input.getAttribute("validmin")))
							valid = false;
					}
					break;
				default:
					if (input.getAttribute("validmax"))
					{
						if (input.value.length > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (input.value.length < input.getAttribute("validmin")) valid = false;
					}
					break;
				}
			}
			break;
		case "select-one":
			if (input.getAttribute("mandatory"))
				if (input.selectedIndex == 0)
					valid = false;
			break;
		case "select-multiple":
			if (input.getAttribute("mandatory"))
			{
				sum = 0;
				for (j=0; j<input.options.length; j++)
				{
					if (input.options[j].selected) sum++;
				}
				if ((!input.getAttribute("validmax")) && (!input.getAttribute("validmin")))
				{
					if (sum == 0) valid = false;
				}
				else
				{
					if (input.getAttribute("validmax"))
					{
						if (sum > input.getAttribute("validmax")) valid = false;
					}
					if (input.getAttribute("validmin"))
					{
						if (sum < input.getAttribute("validmin")) valid = false;
					}
				}
			}
			break;
		case "checkbox":
			if (input.getAttribute("mandatory"))
				valid = input.checked;
			break;
		}

		if (!valid)
		{
			if (input.getAttribute("validationError"))
				sErrorMsg += input.getAttribute("validationError") + "\n";
			else
				sErrorMsg += "Error in field " + input.name + "\n";
		}
	}
	if (sErrorMsg.length)
	{
		alert((title ? title + "\n" : "") + sErrorMsg);
		return false;
	}
	else
	{
		if (submit)
			form.submit();
		return true;
	}
}

function SetUrl(idx)
{
parent.window.location.href="Default.aspx?id=" + idx;
return "";

}

function SetUrlSearch(idx,q)
{
parent.window.location.href="Default.aspx?id=" + idx + "&q=" + q;
return "";

}

function SetUrl2(Pathx)
{
parent.window.location.href=Pathx;
return "";

}

function SelTab(id,tab,comid,catid)
{

temp="Default.aspx?id=" + id  + "&TypeID=" + comid + "&tab=" + tab + "&cateid=" + catid;		
parent.window.location.href=temp;
//SelCom.id.value=id;
//SelCom.tab.value=tab;
//SelCom.TypeId.value=comid;
//SelCom.submit();
}


function CheckForm()
{
var i=0
var check=true;
var checkEmail=true;

for (i=0;i<document.InquiryForm.elements.length;i++)
{	
		if (document.InquiryForm.elements[i].type!="hidden" && document.InquiryForm.elements[i].title!="")
	    { 
	    	        if (document.InquiryForm.elements[i].name=="Email")
	    	         {
                           		
                          		            			            
                                    if(document.InquiryForm.elements[i].value.length==0)
                                    {
                                            check=-1
				            break;	
                                    }
			            checkEmail=validEmail(document.InquiryForm.elements[i].value)
                                   			           		            
						if (checkEmail==false) 
						{
							alert("Invalid E-Mail Address");
							document.InquiryForm.elements[i].focus();
							return;
						}			   			

			        }			       		   					    	    	    
		    if(document.InquiryForm.elements[i].value=="" || document.InquiryForm.elements[i].value==0)	
		    {		
				check=-1
				break;				
			}
       }
}   
if (check!=true)
{
		alert("Please fill " + document.InquiryForm.elements[i].title);
		document.InquiryForm.elements[i].focus();

}	 

else 
{
document.InquiryForm.action = "Subscribe.aspx";
document.InquiryForm.submit();
}
}


function validEmail(email) 
{
	invalidChars = " /:,;"		
	var atPos=0
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
		return false;
	}
	if (email.indexOf("@",atPos+1) != -1) {
		return false;
	}//50
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {
		return false;
	}
	if (periodPos+3 > email.length)	{
		return false;
	}	
	return true;
}
		

 

function checktav(the_string){
		for(i=0;i<=the_string.length;i++) 
		{
			 
			 tav=(the_string.toLowerCase().charAt(i));
			 if(tav=="'" ||  tav=="*" || tav=="%")
			 {
			 	alert("Invalid characters " + tav)
			 	return -1;
			 }
		}
return 0;
}
	