// JavaScript Document

// JavaScript Document
var active = "link_0";
var active2 = "page-1-marker";
var curpage = "photo-0";
var nextpage = "photo-0";


function validate_phone(phone){
	var rgEx = /[\d]{3}-{0,1}[\d]{3}-{0,1}[\d]{4}/
	if(phone.match(rgEx) != null){
		return true;
	}
	else{
		return false;
	}
	
}

function validate_email(email) {
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(email.match(filter) != null){
		return true;
	}
	else{
		return false;
	}
}

function validate_form(name, required, values){
	var valid = true;
	var error = "";
	var form = document.getElementById(name);
	if(required = "all"){
		var elem = form.elements;
		for(var i = 0; i < elem.length; i++){
			if(validate(elem[i].name,elem[i].value, true) == false){
				valid = false;
				error += "Problem with the field "+elem[i].name+"\n";
			}
		}
	}
	
	if(valid == true){
		document.validateform.submit();
	}
	else{
		alert(error);
	}
}

function validate(name , value, required){
	var status = true;
	
	if(name == "email"){
		status = validate_email(value);
		
	}else if(required == true){
		if(name == "phone"){
			status = validate_phone(value);
		}else {
			if(value == '' || value == null){
				status = false;
			}
		}
	
	}
	
		if(status == true){
			return true;
		}
		else{
			return false;
	}
}


function copy_text(source, destination){
	var src = document.getElementById(source);
	var dest = document.getElementById(destination);
	
	dest.value = src.value;
}

function get_extension(text){
	var l = text.length;
	var i = text.lastIndexOf(".");
	
	if(l !=0 && i != -1){
		return text.substr(i+1,l);
	}
	else{
		return false;
	}
}

function accepted_extensions(type,ext){
	var extensions = new Array();
	extensions["video"] = Array("mpg","mpeg","mp4","mpga");
	extensions["image"] = Array("jpg","jpeg","png","gif");
	
	for(var i in extensions[type]){
		alert(i);
		if(i == ext){
			return true
		}
	}
	return false;
}

function validate_uploads(id){
	alert("IT WAS CALLED");
	var text = document.getElementById(id);
	var type = document.getElementById("mediatype");
	if(accepted_extensions(type.value,get_extension(text.value))){
		alert("IT SHOULD RETURN TRUE");
		return true;
	}
	else{
		alert("Please Enter A Correct File Format! ."+get_extension(text.value)+" is an invalid extension");
		return false;
	}
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }




 function hidediv(thediv) {
	 	//alert("HIDING"+thediv);
		if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(thediv).style.display= 'none'
		}
		else {
			if (document.layers) { // Netscape 4
			document.thediv.display= 'none'
			}
			else { // IE 4
			document.all.thediv.style.display= 'none'
			}
		}
	}
	function showdiv(thediv) {
		//alert("SHOWING"+thediv);
		if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(thediv).style.display = 'block';
		}
		else {
			if (document.layers) { // Netscape 4
			document.thediv.display = 'block';
			}
			else { // IE 4
			document.all.thediv.style.display = 'block';
			}
		}
	}
	
	
	function swapActive(id){
		//alert(curpage);
		//alert(id);
		hidediv(curpage);
		showdiv(id);		
		curpage = id;		
	}
	
	function swapActive2(id){
		//alert(curpage);
		//alert(id);
		hidediv(nextpage);
		showdiv(id);
		nextpage = id;
		
	}
	
	function switchSource(source,id){
		document.getElementById(id).src = source;
	}
	
	function changeClass(classname,id){
		document.getElementById(id).className = classname;
		document.getElementById(active).className ="";
		active = id;		
	}
	
	function changeClass2(classname,id){
		document.getElementById(id).className = classname;
		document.getElementById(active2).className ="";
		active2 = id;		
	}
	
	function makeRelative(value){
	if(value == "featured"){
		document.getElementById(value).className = "relative";
	}
}

function unRelative(value){
	if(value == "featured"){
		document.getElementById(value).className = "";
	}
}

function refreshPage(){
location.reload(true);

}