﻿// JavaScript Document
function ValidateForm(){
	var Names=document.getElementById("Name")
	if ((Names.value==null)||(Names.value=="")){
		alert("Please Enter your Name")
		Names.focus()
	} else {
		var emailID=document.getElementById("eMail")
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
				emailID.focus()
		} else {
			if (echeck(emailID.value)==false){
				emailID.focus()	
			} else {
				var Title=document.getElementById("Title")
				if ((Title.value==null)||(Title.value=="")){
					alert("Please Enter a Title to the message")
					Title.focus()
				} else {
					var Message=document.getElementById("Message")
					if ((Message.value==null)||(Message.value=="")){
						alert("Please Enter a Message")
						Message.focus()
					} else {
						if ($("newLoadedFile")!=null && $("newLoadedFile").value!="" && $("attach1").value=="") {
							alert("Please click on start Upload, for upload your file")							
						} else {
//						document.myform.submit()
							$("myform").send({update:$("messageCallBack"),onComplete: 
									function() { 
										document.getElementById("messageCallBack").className = "MessageCallBack"
									} });
						}
					}
				}
			} 
		}
	}
 }


function ValidateMailingList(){
	var Names=document.getElementById("Name")
	if ((Names.value==null)||(Names.value=="")){
		alert("Please Enter your Name")
		Names.focus()
//		return false
	} else {
		var emailID=document.getElementById("eMail")
		if ((emailID.value==null)||(emailID.value=="")){
			alert("Please Enter your Email ID")
				emailID.focus()
//		return false
		} else {
			if (echeck(emailID.value)==false){
				emailID.focus()	
//		return false
			} else {
				$("myform").send({update:$("messageCallBack"),onComplete: 
					function() { 
						document.getElementById("messageCallBack").className = "MessageCallBack"
						document.getElementById("messageCallBack").style.backgroundColor = "#F91D37"
						objMyform.start(1,0)
					} });
//				return true
			} 
		}
	}
 }



function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}

function arrangeForLoadingFiles() {
	/**
	 * We take the first input with this class we can find ...
	 */
	var input = $('demo-filedata');
 
	/**
	 * Simple and easy
	 *
	 * swf: the path to the swf
	 * container: the object is embedded in this container (default: document.body)
	 *
	 * NOTE: container is only used for the first uploader u create, all others depend
	 * on the same swf in that container, so the container option for the other uploaders
	 * will be ignored.
	 *
	 */
	var upload = new FancyUpload(input, {
		swf:  'FancyUpload/Swiff.Uploader.swf',
		queueList: 'demo-queue'
	});
	
	$('demo-status').adopt(new Element('a', {
		'href': '#',
		'events': {
			'click': (function(e) {
				e.stop();
				upload.clearList(false);
			}).bindWithEvent()
		}
	}).setHTML(''));


}


