﻿// JScript File
function validateEmail(emailid) 
{
    //Validating the email field
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if (! emailid.match(re)) {
       return (false);
    }
    return(true);
}

function isNumber(frm,TextField)
{
	var ObjNumberid = eval(frm+"."+TextField);
	if (isNaN(ObjNumberid.value))
	{
		alert("Please enter numeric value");
		ObjNumberid.value="";
		ObjNumberid.focus();
		return;
	}
}

// DisableCheckBox this function takes 3 parameteres 
// 1. frm : Form Name 
// 2. ChkEventBox : On which Onclick event is fired
// 3. ChkToSelDselBox :  Group of checkboxes to select or deselect
//

function DisableCheckBox(frm,ChkEventBox,ChkToSelDselBox)
{
	ObjChkEventBox = eval(frm+"."+ChkEventBox);	
	ObjChkToSelDselBox = eval(frm+"."+ChkToSelDselBox);

	if (ObjChkEventBox.checked)
	{
		for (var i=0; i< ObjChkToSelDselBox.length;i++)
		{
			ObjChkToSelDselBox[i].checked = false
		}
	}
}

function CheckEmail(frm,TextField)
{
	var Objemailid = eval(frm+"."+TextField);
	if (!validateEmail(Objemailid.value))
	{
		alert("Please enter valid email address")
		Objemailid.focus();
		return false;
	}
}

/*
function ForgotPassword(frm,TextField)
{
	var Objemailid = eval(frm+"."+TextField);
	var ObjFrm = eval(frm)
	if (!validateEmail(Objemailid.value))
	{
		alert("Please enter valid email address")
		Objemailid.focus();
		return false;
	}
	else
	{
		ObjFrm.action="ForgotPassword.asp";
		ObjFrm.submit();
	}	//
}
*/
function OpenDetailsPage(Id)
{
	window.open("details.asp?UserId="+Id,"mywindow","location=0,resizable=1,status=1,scrollbars=1,width=700,height=680,left=0,top=0");
}

function ValidateSpeialCharacters(str)
{
	var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
  for (var i = 0; i < str.length; i++) {
  	if (iChars.indexOf(str.charAt(i)) != -1) {
  	alert ("Special characters are not allowed.\n Please remove them and try again.");
  	return false;
  	}
  }
  return true;
}

function validateForm(method)
{
	if (document.frmRegister.txtFName.value=="")
	{
	    alert("Please enter your name");
	    document.frmRegister.txtFName.focus();
	    return false;
	}
    else if (document.frmRegister.txtLName.value=="")
	{
	    alert("Please enter Last Name");
	    document.frmRegister.txtLName.focus();
	    return false;
	}
	else if (document.frmRegister.txtPwd.value=="")
	{
        alert("Please enter Password");
	    document.frmRegister.txtPwd.focus();
	    return false;
	}
    else if (document.frmRegister.txtCnfrmPwd.value=="")
	{
        alert("Please enter Password");
	    document.frmRegister.txtCnfrmPwd.focus();
	    return false;
	}
	else if (document.frmRegister.txtCnfrmPwd.value != document.frmRegister.txtPwd.value)
	{
        alert("Passwords not matching");
	    document.frmRegister.txtCnfrmPwd.focus();
	    return false;
	}
    else if (document.frmRegister.txtBirthDate.value=="")
	{
        alert("Please enter your date of birth");
	    document.frmRegister.txtBirthDate.focus();
	    return false;
	}
    else if (document.frmRegister.txtEmail.value=="")
	{
        alert("Please enter your email Id");
	    document.frmRegister.txtEmail.focus();
	    return false;
	}
	else if (!validateEmail(document.frmRegister.txtEmail.value))
	{
		alert("Please enter valid email address")
		document.frmRegister.txtEmail.focus();
		return false;
	}
    else if (document.frmRegister.txtCity.value=="")
	{
        alert("Please enter city");
	    document.frmRegister.txtCity.focus();
	    return false;
	}
    else if (document.frmRegister.txtState.value=="")
	{
        alert("Please enter state");
	    document.frmRegister.txtState.focus();
	    return false;
	}
    else if (document.frmRegister.txtCountry.value=="")
	{
        alert("Please enter country");
	    document.frmRegister.txtCountry.focus();
	    return false;
	}
    else if (document.frmRegister.txtZip.value=="")
	{
        alert("Please enter zip");
	    document.frmRegister.txtZip.focus();
	    return false;
	}
    else if (document.frmRegister.txtPWDQuest.value=="")
	{
        alert("Please enter password question");
	    document.frmRegister.txtPWDQuest.focus();
	    return false;
	}
    else if (document.frmRegister.txtPwdAns.value=="")
	{
        alert("Please enter answer for password question");
	    document.frmRegister.txtPwdAns.focus();
	    return false;
	}
    
    else if(document.frmRegister.txtLookingFor.value=="")
	{
        alert("Please enter keywords for whom you are looking for");
	    document.frmRegister.txtLookingFor.focus();
	    return false;
	}
    else if(document.frmRegister.txtSelfKey.value=="")
	{
        alert("Please enter self keywords");
	    document.frmRegister.txtSelfKey.focus();
	    return false;
	}
    else if (document.frmRegister.txtSelfDesc.value=="")
	{
        alert("Please describe yourself");
	    document.frmRegister.txtSelfDesc.focus();
	    return false;
	}
	else
	{
	    document.frmRegister.method="post";
	    if (method=="update")
	    {
	        document.frmRegister.action ="registerUpdate.asp?method=update";
	    }
	    else
	    {
	        document.frmRegister.action ="registerUpdate.asp";
	    }    
	    frmRegister.submit();
	    return true;
	}
}

// Login Forgott Password Script Starts heree // LeftMenu
<!--
var http_request = false;
var Get_http_response;
function makeRequest(url) 
{//alert()
	url=url+"?txtEmailId="+document.frmLogin.txtEmailId.value +"&txtPassword="+document.frmLogin.txtPassword.value+"&hidFileName="+document.frmLogin.hidFileName.value;
	//alert(url)
	http_request = false;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert("Cannot create an XMLHTTP instance");
		return false;
	}
	http_request.onreadystatechange = alertContents;
	http_request.open('POST', url, true);
	http_request.send(null);
}

function alertContents() {
//	
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		Get_http_response=http_request.responseText.split(":")[0];
		Get_http_response1=http_request.responseText.split(":")[1];
		//alert(Get_http_response)
					if (Get_http_response=="0"){
					document.all.myerror.style.display="inline";
					document.all.myerror1.style.display="none";
					document.all.myerror2.style.display="none";
					}else if (Get_http_response=="1"){
					document.all.myerror1.style.display="inline";
					document.all.myerror.style.display="none";
					document.all.myerror2.style.display="none";
					}else if (Get_http_response=="2"){
						if (Get_http_response1 != "" && typeof(Get_http_response1) == "string")
							window.location.href=Get_http_response1;	
						else
							window.location.href="Default.asp";	
					}else if (Get_http_response=="3"){
					document.all.myerror2.style.display="inline";
					document.all.myerror.style.display="none";
					document.all.myerror1.style.display="none";
					}else if (Get_http_response=="5"){
						window.location.href="admin/edit.asp";	
					}else if (Get_http_response=="6"){
						document.all.myerror2.style.display="inline";
					}
				 
		} else {
				alert('There was a problem with the request.');
		}
	}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->

function ForgotPassword(frm,TextField)
{
	var Objemailid = eval(frm+"."+TextField);
	var ObjFrm = eval(frm)
	if (!validateEmail(Objemailid.value))
	{
		alert("Please enter valid email address")
		Objemailid.focus();
		return false;
	}
	else
	{
		ObjFrm.txtPassword.value="";
		makeRequest('authenticate.asp')
		//ObjFrm.action="ForgotPassword.asp";
		//ObjFrm.submit();
	}	
}

// This is used in login page
function ClientLogin(frm,TextField,FileName)
{
	var Objemailid = eval(frm+"."+TextField);
	var ObjFrm = eval(frm)
	if (!validateEmail(Objemailid.value))
	{
		alert("Please enter valid email address")
		Objemailid.focus();
		return false;
	}
	else
	{
		makeRequest('authenticate.asp')
		//ObjFrm.action="ForgotPassword.asp";
		//ObjFrm.submit();
	}	
}

function adminLogin(frm,TextField,FileName)
{
	var Objemailid = eval(frm+"."+TextField);
	var ObjFrm = eval(frm)
	if (!validateEmail(Objemailid.value))
	{
		alert("Please enter valid email address")
		Objemailid.focus();
		return false;
	}
	else
	{
		makeRequest('adminauthenticate.asp')
		//ObjFrm.action="ForgotPassword.asp";
		//ObjFrm.submit();
	}	
}

function SendMail(f)
{
	var frm = eval ("document."+f)
	if (frm.txtSubject.value=="")
	{
		alert("Please enter the subject");
		frm.txtMailBody.focus();
		return
	}
	
	if (frm.txtMailBody.value=="")
	{
		alert("Please enter some text to send mail");
		frm.txtMailBody.focus();
		return
	}
	
	frm.hidSendMail.value="yes"
	frm.submit()
}

function ValidateComment(f)
{
	var frm = eval("document."+f);
	if (frm.txtComment.value=="")
	{
		alert("Please enter the coment");
		frm.txtComment.focus();
		return
	}	
	else
	{
		frm.method="post";
		frm.target="iFraCombo1";
		frm.action='addComment.asp'
		frm.submit();
	}
}


// This is used in admin/editCategory.asp... 
//when a category is selected to edit, it takes the category Id and categoryName and seperates it
function changeCatValue()
{
    catValue = document.frmEditCat.selcategory.value;
    i = catValue.indexOf(",")
    categoryId = catValue.substring(0, i)
 	categoryName = catValue.substring(i+1, catValue.length);
 	document.frmEditCat.selectedCatId.value = categoryId;
 	document.frmEditCat.txtCatName.value = categoryName;
}

// This is used in default.asp and Listing.asp, when changing the categories
function changeCategory(f)
{
    catgrId = eval("document."+f+".selCatgr.value");
    location.href="listing.asp?id="+catgrId;
}

// This is used in detail.asp.. to change the products within a particular category
function selectPro(categoryId, productId, exp)
{
    productId = document.frmDetail.selPro.value;
    location.href="detail.asp?pId="+productId+"&cId="+categoryId+"&exp="+exp;
}


function validateCategory()
{
    if (document.frmAddCat.txtCatName.value=="")
    {
        alert("Please enter category name");
        return false;
    }
    else
    {
        document.frmAddCat.method = "post";
        document.frmAddCat.action = "addCategoryAdd.asp";
        document.frmAddCat.submit();
        return true;
    }
}

function cnfrmDeleteCategory()
{
    if (document.frmEditCat.selcategory.value=="")
    {
        alert("Please select a category");
        return false;
    }
    else
    {
        var boo = confirm("Are you sure you want to delete this category?? \n This will delete all the related products.")
        if (boo)
        {   
            document.frmEditCat.method = "post";
            document.frmEditCat.action = "editCategoryEdit.asp?action=del";
            document.frmEditCat.submit();
        }
    }
}

function updateCategory()
{
    document.frmEditCat.method = "post";
    document.frmEditCat.action = "editCategoryEdit.asp";
    document.frmEditCat.submit();
}

// End of Category related Functions

// Start Of Product related Functions 
function prodOrder()
{
    document.frmSetProdOrder.method = "post";
    document.frmSetProdOrder.action = "setProdOrder.asp";
    document.frmSetProdOrder.submit();
}

function updateProduct()
{
    convertHTML();
    document.frmEditProduct.fileText.value = document.frmEditProduct.edited.value;  //frames.message.document.body.innerHTML;
    document.frmEditProduct.encoding = "multipart/form-data";
    document.frmEditProduct.method = "post";
    document.frmEditProduct.action = "editProductEdit.asp";
    document.frmEditProduct.submit();
}

function cnfrmDeleteProduct()
{
    if (document.frmEditProduct.selproduct.value=="")
    {
        alert("Please select a Product");
        return false;
    }
    else
    {
        var boo = confirm("Are you sure you want to delete this Product??")
        if (boo)
        {   
            document.frmEditProduct.encoding="multipart/form-data";
            document.frmEditProduct.method = "post";
            document.frmEditProduct.action = "editProductEdit.asp?action=del";
            document.frmEditProduct.submit();
        }
    }
}

function validateProduct()
{
    if (document.frmAddProduct.txtProductName.value=="")
    {
        alert("Please enter Product name");
        document.frmAddProduct.txtProductName.focus();
        return false;
    }
    else if(document.frmAddProduct.selCat.selectedIndex==0)
    {
        alert("Please select category");
        document.frmAddProduct.selCat.focus();
        return false;
    }
    else
    {
        convertHTML();
        document.frmAddProduct.fileText.value = document.frmAddProduct.edited.value;  //frames.message.document.body.innerHTML;
        document.frmAddProduct.method = "post";
        document.frmAddProduct.action = "AddProductAdd.asp";
        document.frmAddProduct.submit();
        return true;
    }
}

// End of Product Related Functions
function validateFeedbackAgree()
{
    if (document.frmAgree.chkAccept.checked)
    {
        document.frmAgree.method="post";
        document.frmAgree.action = "feedback.asp";
        document.frmAgree.submit()
    }   
    else
    {
        alert("Accept the terms and conditions")
        return false;
    }
}

function validateFeedback()
{
    bsHidHtml = trBusiness.innerHTML;
    crHidHtml = trCorporate.innerHTML;
    document.frmFeedback.bsHtml.value = bsHidHtml;
    document.frmFeedback.crHtml.value = crHidHtml;
    
    if (document.frmFeedback.corpTextVal.value=="Ex")
    {
        exNewHtm = tblCorpEx.innerHTML;
        document.frmFeedback.corpExNew.value = exNewHtm
    }
    else if(document.frmFeedback.corpTextVal.value=="New")
    {
        exNewHtm = tblCorpNew.innerHTML;
        document.frmFeedback.corpExNew.value = exNewHtm
    }
    valEmail = validateEmail(document.frmFeedback.email.value)
    if (!(valEmail))
    {
        alert("Invalid emailId")
        return false;
    }
    if (document.frmFeedback.name.value=="")
    {
        alert("Please enter name");
        document.frmFeedback.name.focus();
        return false;
    }
    else if (document.frmFeedback.city.value=="")
    {
        alert("Please enter city");
        document.frmFeedback.city.focus();
        return false;
    }
    else if (document.frmFeedback.phone.value=="")
    {
        alert("Please enter phone number");
        document.frmFeedback.phone.focus();
        return false;
    }
    else if (document.frmFeedback.email.value=="")
    {
        alert("Please enter email address");
        document.frmFeedback.email.focus();
        return false;
    }
    else if((document.all.selcategory.selectedIndex <= 0) || (document.all.selproduct.selectedIndex <= 0))
    {
        alert("Please select the product");
        return false;
    }
    else
    {
        document.frmFeedback.target="_top";
        document.frmFeedback.encoding = "multipart/form-data";
        document.frmFeedback.method="post";
        document.frmFeedback.action = "feedback.asp?action=send";
        document.frmFeedback.submit();
        return true;
    }
    
}

//***************************************************************//
// ------------------- RELATED TO EDITOR ----------------------- //
//***************************************************************//

//Function to check form is filled in correctly before submitting
function CheckForm () {
	
	var errorMsg = "";
	
	//Check for an Author
	if (document.frmAddProduct.author.value==""){
		errorMsg += "\n\tAuthor \t- Enter your name";
	}
	
	//Check for an Journal Title
	if (document.frmAddProduct.title.value==""){
		errorMsg += "\n\tTitle \t\t- Enter a title for the Journal Item";
	}
	
	//Check for journal Item
	if (document.frmAddProduct.journalItem.value==""){
		errorMsg += "\n\tJournal Item \t- Enter a Journal Item to post";
	}
	
	//If there is a problem with the form then display an error
	if (errorMsg != ""){
		msg = "____________________________________________________________________\n\n";
		msg += "Your Journal Item has not been submitted because there are problem(s) with the form.\n";
		msg += "Please correct the problem(s) and re-submit the form.\n";
		msg += "____________________________________________________________________\n\n";
		msg += "The following field(s) need to be corrected: -\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
	return true;
}

//Function to format text in the text box
function FormatText(command, option){
	
  	frames.message.document.execCommand(command, true, option);
  	frames.message.focus();
}

//Function to add image
function AddImage(){	
	imagePath = prompt('Enter the web address of the image', 'http://');				
	
	if ((imagePath != null) && (imagePath != "")){					
		frames.message.document.execCommand('InsertImage', false, imagePath);
  		frames.message.focus();
	}
	frames.message.focus();			
}

//Function to clear form
function ResetForm()
{
	if (window.confirm('Are you sure you want to clear the e-mail you have entered?')){
	 	frames.message.document.body.innerHTML = ''; 
	 	return true;
	 } 
	 return false;		
}

//Function to open pop up window
function openWin(theURL,winName,features) {
  	window.open(theURL,winName,features);
}
// -->

//***************************************************************//
// --------------- RELATED TO EDITOR ENDS HERE ----------------- //
//***************************************************************//

//***************************************************************//
//--- RELATED TO LIST BOX .. USED FOR SET ORDER OF PRODUCTS------//
//***************************************************************//

    function InsertQuotes(strValue)
    {
	    strValue=strValue.replace("=+=","\"");
	    strValue=strValue.replace("=","'");	
	    return strValue;
    }
    
	function RemoveQuotes(strValue)
	{
		strValue=strValue.replace("\"","=+=");
		strValue=strValue.replace("'","=");	
		return strValue;
	}
	
	function CategoryChk()
	{	
		if(document.frmSetProdOrder.SubCategoryName)
		{
			document.frmSetProdOrder.SubCategoryName.value="";	
		}
		document.frmSetProdOrder.submit();
	}

	function UpThis(formName)
	{
			var tempCatId;
			var selectedCatId;
			var selectedVal;
			var tempCatName1;
			var frmName;
            frmName = eval("document."+formName)
			selectedCatId = frmName.CatName.value;
			
			for(i=0;i<CatId.length;i++)
			{
				if(frmName.CatName.value == CatId[i])
				{
					if(i!=0)
					{
						tempCatId = CatId[i];
						tempCatName1 = RemoveQuotes(CatName1[i]);
						CatId[i] = CatId[i-1];
						CatId[i-1] = tempCatId;
						CatName1[i] = CatName1[i-1];
						CatName1[i-1] = tempCatName1;
						i = i+1;
					}
				}
			}
			CatDiv.innerHTML = "";
			
			var str;
			str = "<select size='10' name='CatName' MULTIPLE>";
			for(i=0;i<CatId.length;i++)
			{
				//alert(CatId[i]);
				if(selectedCatId==CatId[i])
				{
					selectedVal = " selected";
				}		
				else
				{
					selectedVal = "";
				}
				//newval = reverse(CatId[i]) ;
				str = str + "<option value='" + CatId[i] + "'" + selectedVal + ">" + InsertQuotes(CatName1[i]) + "</option>";
			}
			str = str + "</select>";
			CatDiv.innerHTML = str;
	}
	function DownThis(formName)
	{
			var tempCatId;
			var selectedCatId;
			var selectedVal;
			var tempCatName1;
            
            frmName = eval("document."+formName)
			selectedCatId = frmName.CatName.value;
			
			
			for(i=0;i<CatId.length;i++)
			{
				if(frmName.CatName.value == CatId[i])
				{
					if(i!=(CatId.length-1))
					{
						tempCatId = CatId[i];
						tempCatName1 = RemoveQuotes(CatName1[i]);
						CatId[i] = CatId[i+1];
						CatId[i+1] = tempCatId;
						CatName1[i] = CatName1[i+1];
						CatName1[i+1] = tempCatName1;
						i = i+1;
					}
				}
			}
			CatDiv.innerHTML = "";
			
			var str;
			str = "<select size='10' name='CatName' MULTIPLE>";
			for(i=0;i<CatId.length;i++)
			{
				
				if(selectedCatId==CatId[i])
				{
					selectedVal = " selected";
				}		
				else
				{
					selectedVal = "";
				}
				//newval = reverse(CatId[i]) ;
				str = str + "<option value='" + CatId[i] + "'" + selectedVal + ">" + InsertQuotes(CatName1[i])+ "</option>";
			}
			str = str + "</select>";
			CatDiv.innerHTML = str;
	}
	
	function SaveMe()
	{
		for (var i=0; i<document.frmSetProdOrder.CatName.options.length; i++) 
		{
			document.frmSetProdOrder.CatName.options[i].selected = true;
		}
		document.frmSetProdOrder.method = "post";
		document.frmSetProdOrder.action = "setProdOrder.asp?SaveMe=Y";
		document.frmSetProdOrder.submit();
	}
	
	function saveCatOrder()
	{
        for (var i=0; i<document.frmSetCatOrder.CatName.options.length; i++) 
		{
			document.frmSetCatOrder.CatName.options[i].selected = true;
		}
		document.frmSetCatOrder.method = "post";
		document.frmSetCatOrder.action = "setCatOrder.asp?SaveMe=Y";
		document.frmSetCatOrder.submit();
	}
