
function divswapVerify(checker,ID) {
verify = prompt('Enter password:','');
	if ( verify=='ok') {
	   check = divswap(checker,ID);
	} else {
	   alert('Wrong password. You might have to contact jay@icglink to retrieve it.');
	}
}


function divswap(checker,ID) {

	if (ID == '') {
	ID = 'nuthin';
	}

	var counter = (document.all) ? document.all.tags("DIV").length : (document.getElementById) ? document.getElementsByTagName("DIV").length : document.layers.length;	
	var tempname;
	var i=0; 
	var n=0;
	var a=0;
	var d=checker.length;
	var names = new Array();


// FIRST, HIDE ALL DIVS...

	for (i = 0; i < counter; i++) {

    if (document.all) {
	var tempobj = document.all.tags("DIV");
	tempname = tempobj[i].id;
	 }

  	if (document.getElementById) {
	tempname = document.getElementsByTagName("DIV")[i].id;
	 }
	 
    else {
	tempname = document.layers[i].name;
	 }


	var test = tempname.substring(0,d);
	
	if (test == checker) {
	names[n] = tempname;
	n++;
	}	 


	for (a = 0; a < n; a++) {

	samplename = names[a];

	document.getElementById(samplename).style.visibility = "hidden";
	document.getElementById(samplename).style.display = "none";

   	}



// show the right one...
	document.getElementById(ID).style.visibility = "visible";
	document.getElementById(ID).style.display = "block";


}
}




function divswapVerify(checker,ID) {
verify = prompt('Enter password:','');
	if ( verify=='ok') {
	   check = divswap(checker,ID);
	} else {
	   alert('Wrong password. You might have to contact jay@icglink to retrieve it.');
	}
}



function divDisplayAll(checker,status) {

	var counter = (document.all) ? document.all.tags("DIV").length : (document.getElementById) ? document.getElementsByTagName("DIV").length : document.layers.length;	
	var tempname;
	var i=0; 
	var n=0;
	var a=0;
	var d=checker.length;
	var names = new Array();


// FIRST, HIDE ALL DIVS...

	for (i = 0; i < counter; i++) {

    if (document.all) {
	var tempobj = document.all.tags("DIV");
	tempname = tempobj[i].id;
	 }

  	if (document.getElementById) {
	tempname = document.getElementsByTagName("DIV")[i].id;
	 }
	 
    else {
	tempname = document.layers[i].name;
	 }


	var test = tempname.substring(0,d);
	
	if (test == checker) {
	names[n] = tempname;
	n++;
	}	 


	for (a = 0; a < n; a++) {

	samplename = names[a];

		if (status == "hide") {
			document.getElementById(samplename).style.visibility = "hidden";
			document.getElementById(samplename).style.display = "none";
	   	}

		if (status == "show") {
			document.getElementById(samplename).style.visibility = "visible";
			document.getElementById(samplename).style.display = "block";
	   	}	
	}
}
}






function divshow(thediv) {
	document.getElementById(thediv).style.visibility = "visible";
	document.getElementById(thediv).style.display = "block";
}


function divhide(thediv) {
	document.getElementById(thediv).style.visibility = "hidden";
	document.getElementById(thediv).style.display = "none";
}


// ----------------------------------------------------


function clearpart (div) {
	parent_node = document.getElementById(div);
	tag_names = new Array('input', 'textarea', 'select', 'button');
	if( parent_node == undefined ) {
		parent_node = document;
	}
	var out = new Array();
	var elementsFound = new Array();
	eles = 0;
	for( var i = 0; i < tag_names.length; i++ ) {
		elementsFound[i] = parent_node.getElementsByTagName(tag_names[i]);
		for (var j = 0; j < elementsFound[i].length; j++) {
			elementsFound[i][j].value = "";
		}
	}
//	divhide(div);
}

// ----------------------------------------------------


function checkFileName(theForm) {

	str = document.forms[theForm].elements['userfile'].value;
	filename = str.split("/")[str.split("/").length-1];
	filename = filename.split("\\")[filename.split("\\").length-1];
	theviolation = "";
	theerr = "";

	badchars = new Array(" "," ","*","/","\\","!","@","$","%","^","&","*","+","=","{","}","'",";","<",">","?","`");

	for (var x = 0; x <= badchars.length; x++) {
	   if (filename.indexOf(badchars[x]) > 0) {theerr = "y"; theviolation += " " + badchars[x]; }
	}

	if (theerr == "y") { 
	    alert("BAD FILE NAME: Your file NAME can have ONLY letters and numbers in it - no spaces or other characters.\n\n" + theviolation);
	} else {
		document.forms[theForm].submit();
	}

}


function checkFileNameThis(thisPic) {

	str = thisPic.value;
	filename = str.split("/")[str.split("/").length-1];
	filename = filename.split("\\")[filename.split("\\").length-1];
	theviolation = "";
	theerr = "";

	badchars = new Array(" "," ","*","/","\\","!","@","$","%","^","&","*","+","=","{","}","'",";","<",">","?","`");

	for (var x = 0; x <= badchars.length; x++) {
	   if (filename.indexOf(badchars[x]) > 0) {theerr = "y"; theviolation += " " + badchars[x]; }
	}

	if (theerr == "y") { 
	    alert("BAD FILE NAME: Your file NAME can have ONLY letters and numbers in it - no spaces or other characters.\n\n" + theviolation);
	}

}



function checkFileNameS2(theForm) {
fileList = "";
f = document.forms[theForm];
for(i=0; i<f.elements.length; i++) {
	if (f.elements[i].type == "file") {
		str = f.elements[i].value;
		if (str != "") {
			filename = str.split("/")[str.split("/").length-1];
			filename = filename.split("\\")[filename.split("\\").length-1];
			theviolation = "";
			theerr = "";
	
			badchars = new Array(" "," ","*","/","\\","!","@","$","%","^","&","*","+","=","{","}","'",";","<",">","?","`");

			for (var x = 0; x <= badchars.length; x++) {		
			   if (filename.indexOf(badchars[x]) > 0) {theerr = "y"; theviolation += " " + badchars[x]; fileList = str + "\n" + fileList;}
			}

			if (theerr == "y") { 
			    alert("BAD FILE NAME: \n\nFile NAMEs can have ONLY letters and numbers in it - no spaces or other characters.\n\nThese file(s) have 'bad' names:\n." + fileList + "\n\n" + theviolation);
			} else {
//				document.forms[theForm].submit();
			}
		}
	}
}

} // end function



function getPIC(theIMG,IMGsrc) {
	document.getElementById(theIMG).src = "UserFiles/Image/gallery_big/" + IMGsrc;
}

function showblock(ID) {
	document.getElementById(ID).style.display = 'block';
}



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 checkURL(url) {
//	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
	var urlRegxp = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.){1}([\w]+)(.[\w]+){1,2}$/;
	if (urlRegxp.test(url) != true) {
		alert('Invalid URL. Please start the Web address with http://www (or the equivalent)');
	}
}



// Ä =================================



function echeckB(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					
} // end Ä echeck


// Ä =================================


function prepForm(formname){

	theForm = document.forms[formname];

	errorR = "";
	errorE = "";
	errorW = "";

	//------------------------------
	// Collect values of all form elements

	var els = theForm.elements;

	for(i=0; i<els.length; i++) { 
		switch(els[i].type) {

			case "text":
				if (els[i].value == "") {
					if (els[i].name.indexOf("r_") > -1) {
						thename = els[i].name.replace("r_", "");
						errorR += "\n - Required field: " + thename;
					}
				}
				
				if (els[i].name.indexOf("email") > -1) {
					errorE = echeckB(els[i].value);
					if (errorE == false) { errorE = "\n - Bad email address"; }
				}
				
				if (els[i].name.indexOf("website") > -1) {
					url = els[i].value;
					if (url != "") {
						var objRegExp = /^((ftp|http|https):\/\/){1}(\w+)(\.\w)+/;
						if (objRegExp.test(url)) { errorW = ""; } else { errorW ="\n - Bad Web site address (Start with http:// or equivalent)"; }
					}
				}
				
				break;

		}
	}


	if ((errorR != "" ) || (errorE != true ) || (errorW != "" )) {
		errorE = (errorE == true) ? "" : errorE;
		alert ("Whoa! There are some form errors:\n" + errorR + errorE + errorW);
	} else {
		theForm.submit();
	}

} // end Ä prepForm


