function setSubCategory()
{
	if(document.getElementById("ddlsubCategory").length > 1)
	{
		document.getElementById("setCategoryDisplay").style.display = "block";
		document.getElementById("ddlsubCategory").focus();
	}
	else
	{
		document.getElementById("setCategoryDisplay").style.display = "none";
		document.getElementById("ddlproduct").focus();
	}
}

function ValidatePosting()
{
  	if (document.getElementById("ddlCategory").value == "0" || document.getElementById("ddlCategory").value == "" )
	{
		alert("Please Select Main Category.")
		document.getElementById("ddlCategory").focus();
		return false;
	}
	
	if(document.getElementById("ddlSubCategory").length > 1)
	{
		if(document.getElementById("ddlSubCategory").value == "0" || document.getElementById("ddlSubCategory").value == "")
		{
			alert("Please Select Category.");
			document.getElementById("ddlSubCategory").focus();
			return false;
		}
		
	}
	if(document.getElementById("ddlsSubCategory").length > 1)
	{
		if(document.getElementById("ddlsSubCategory").value == "0" || document.getElementById("ddlsSubCategory").value == "")
		{
			alert("Please Select SubCategory.");
			document.getElementById("ddlsSubCategory").focus();
			return false;
		}
		
	}
	
	if (document.getElementById("ddlproduct").value == "0" || document.getElementById("ddlproduct").value == "" )
	{
		alert("Please Select Product.")
		document.getElementById("ddlproduct").focus();
		return false;
	}
	
	return true;
}

function openUploader(pcode)
{
	var url;
	url = '/imageUploader.aspx?pcode=' + pcode;
	window.open(url,'','menubar=0,resizable=0,scrollbars=1,location=0,width=500,height=200,top=0,left=0,dependent=1');
}

function validatePosting1()
{
	if (document.getElementById("prodComments").value == "")
	{
		alert("Enter Comments For Product.");
		document.getElementById("prodComments").focus();
		return false;
	}
	
	if (document.getElementById("comments").value == "")
	{
		alert("Enter Comments For Company Profile.");
		document.getElementById("comments").focus();
		return false;
	}
	
	return true;
}

function ValidateRegistration()
{
	checkValidUrl();
	
	var form = "document.myform.f2fregistrationForm_";
	
	if(eval(form + "reg_userid.value") == "")
	{
		alert("Enter Valid User Id.");
		eval(form + "reg_userid.focus()");
		return false;
	}
	if ( !ValidateNo( eval(form + "reg_userid.value") , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" )){
		alert("Invalid User Id: " + eval(form + "reg_userid.value"));
		eval(form + "reg_userid.focus()");
		return false;
	}
	
	if(eval(form + "reg_name.value") == "")
	{
		alert("Enter Valid Contact Person Name.");
		eval(form + "reg_name.focus()");
		return false;
	}
	
	if(eval(form + "reg_password.value") == "")
	{
		alert("Enter Valid Password.");
		eval(form + "reg_password.focus()");
		return false;
	}
	if ( !ValidateNo( eval(form + "reg_password.value") , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" )){
		alert("Invalid PassWord. Avoid using special characters in password.");
		eval(form + "reg_password.focus()");
		return false;
	}
	
	if(eval(form + "reg_conform_password.value") == "" || eval(form + "reg_conform_password.value") != eval(form + "reg_password.value") )
	{
		alert("Enter Valid Conform Password.");
		eval(form + "reg_conform_password.focus()");
		return false;
	}
	
	txt = eval(form + "reg_email.value");
	
	if(txt == "")
	{
		alert("Please Specify Your Email.");
		eval(form + "reg_email.focus()");
		return false;
	}
	if(txt.indexOf("@")<1)
	{
		alert("Please Enter Valid E-mail.");
		eval(form + "reg_email.focus()");
		return false;
	}	
	if( txt.indexOf('@',0)==0 || txt.indexOf('.',0)<1 || txt.indexOf("@") > txt.indexOf(".") || txt.indexOf(".") == ( txt.indexOf("@") + 1 ) || txt.indexOf(".") == ( txt.length - 1 ) )
	{
		alert("Please Enter Valid E-mail.")
		eval(form + "reg_email.focus()");
		return false;
	}		
	if ( !ValidateNo( txt , "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-" ))
	{
		alert("Invalid Email: " + eval(form + "reg_email.value"));
		eval(form + "reg_email.focus()");
		return false;
	}
	if (txt.indexOf("/")>1 || txt.indexOf(",")>1)
	{
		alert("Please Enter Valid E-mail.");
		eval(form + "reg_email.focus()");
		return false;
	}
	
	cnt = 0;
	instr = txt.toString()
	for(var i=0; i<instr.length; i++)
	{
		var char1 = instr.charAt(i)
		if (char1 == "@")
		{
			cnt = cnt+1;
		}
	}					
	if(cnt > 1)
	{
		alert("Please Enter Valid E-mail.");
		eval(form + "reg_email.focus()");
		return false;
	}
	
	if(eval(form + "reg_company_name.value") == "")
	{
		alert("Enter Valid Company Name.");
		eval(form + "reg_company_name.focus()");
		return false;
	}
	
	if(eval(form + "reg_address1.value") == "" && eval(form + "reg_address2.value") == "" && eval(form + "reg_address3.value") == "" )
	{
		alert("Enter Valid Address.");
		eval(form + "reg_address1.focus()");
		return false;
	}
	
	if(eval("document.myform.country.value") == "0")
	{
		alert("Select Country You Belong To.");
		eval("document.myform.country.focus()");
		return false;
	}
	
	if(eval("document.myform.mainBusinessArea.value") == 0)
	{
		alert("Select Main Business Area.");
		eval("document.myform.mainBusinessArea.focus()");
		return false;
	}
	
	return true;
}

function checkValidUrl()
{
	var form = "document.myform.f2fregistrationForm_";
	var val = eval(form + "reg_url.value");	
	var rehttp = /http:\/\//;
	
	val = val.replace(rehttp,"");
	eval(form + "reg_url.value='" + val + "';" );
}

function usercheck()
{ 
	flag1 = false;
	var valu = document.getElementById("f2fregistrationForm_reg_userid").value;							
	
	if(valu == "")
	{
		flag=false;
	}

	instr = valu.toString()
	var flag;
	
	for (var i=0; i<instr.length; i++)
	{
		var char1 = instr.charAt(i)
		value = char1.charCodeAt()
	
		if(value == "32")
		{
			flag = false;
		}
		else
		{
			flag = true;
			break;
		}
	}
	
	if(flag == false)
	{
		alert("Please Specify User ID.");
		document.getElementById("f2fregistrationForm_reg_userid").focus();
		return false;
	}

	var msg3 = document.getElementById("f2fregistrationForm_reg_userid").value;
	
	for (var i=0; i<msg3.length; i++)
	{
		chk1 = msg3.charCodeAt(i);
		
		if (!(chk1>47 && chk1<=57) && !(chk1>64 && chk1<91) && !(chk1>96 && chk1<123))
		{
			flag1 = true;
		}
	}
	
	if (flag1 == true)
	{
		alert("Please Choose User ID Using Alphabet and Numbers Only.");
		return false;
	}
	else
	{
		var msg3 = document.getElementById("f2fregistrationForm_reg_userid").value;
		var newwin;
		
		chk1 = "http://www.fibre2fashion.com/popchkuser.asp?user=" + msg3;
		
		if (!newwin || newwin.closed)
		{
			newwin = eval("window.open('" + chk1 + "','child','left=130,top=120,width=300,height=100,scrollbars=no')");
		}
		else
		{		  
			newwin.close();
			newwin = eval("window.open('" + chk1 + "','child','left=130,top=120,width=300,height=100,scrollbars=no')");
		}
	}
}

function ValidateNo(NumStr, String)
{				
	for(var Idx=0; Idx<NumStr.length; Idx++)
	{
		var Char = NumStr.charAt(Idx);
		var Match = false;

		for(var Idx1=0; Idx1<String.length; Idx1++)
		{
			if(Char == String.charAt (Idx1))
				 Match = true;
		}

		if (!Match) 
			return false;
	}
	return true;
}