
//Used to show/hide advance provider searches.  See homepage, search-providers.
function showhidedivs(show,hide) {
    if (show != "") {
        document.getElementById(show).style.display = 'block';
    }
    if (hide != "") {
        document.getElementById(hide).style.display = 'none';
    }
}

function showhidediv(divID) {
	var current_state = document.getElementById(divID).style.display;
	if (current_state == 'none') {
		document.getElementById(divID).style.display = 'block';
	} else {
		document.getElementById(divID).style.display = 'none';
	}
}

function clearformfield(formID,clearvalue) {
	var fieldvalue = document.getElementById(formID).value;
	
	if (fieldvalue == clearvalue) {
		document.getElementById(formID).value = "";
	}
}

//Used to submit forms as needed.
function form_submit(form_id_name) {
	document.getElementById(form_id_name).submit();
}

//Used for popups.
function pop(file,w,h){
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    myWidth = (myWidth/2 - (w/2));
    myHeight = (myHeight/2 - (h/2));
    
	window.open(file,'newWindow','width='+w+',height='+h+',scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes,top='+myHeight+',left='+myWidth+'');
}

//Used on review pages to popup TaC.
function popTaC(file,w,h){
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
    myWidth = (myWidth/2 - (w/2));
    myHeight = (myHeight/2 - (h/2));
    
	window.open(file,'Terms And Conditions','width='+w+',height='+h+',scrollbars=yes,location=no,directories=no,status=yes,menubar=yes,toolbar=no,resizable=yes,top='+myHeight+',left='+myWidth+'');
}

//Used on review pages to limit chrs.
function count_characters(fieldtocount,fieldvalue,fieldtoreport,maxlength) {
    //alert(fieldtocount + ' ' + fieldvalue + ' ' + fieldtoreport + ' ' + maxlength);
	var stringcount = fieldvalue.length;
	if (stringcount > maxlength) {
		document.getElementById(fieldtoreport).innerHTML = stringcount;
	} else {
		document.getElementById(fieldtoreport).innerHTML = stringcount;
	}
}

//Used on provider pages to get latest ratings.
function GetRatings(provider_id) {
	//alert("GetRatings("+provider_id+")");
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_rating=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_rating=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_rating.onreadystatechange=function() {
		if (xmlhttp_rating.readyState==4 && xmlhttp_rating.status==200) {
			var response = xmlhttp_rating.responseText;
			//alert(response);
			if (response.search("[~]") == -1) {
				//alert(response);
			} else {
				var responseArray = new Array();
				responseArray = response.split("[~]");
				document.getElementById("provider_ratings").innerHTML = responseArray[0];
				document.getElementById("provider_rated").innerHTML = responseArray[1];
			}
		}
	}
	xmlhttp_rating.open("POST","../../../../include/provider-ratings.php",true);
	xmlhttp_rating.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_rating.send("provider_id=" + provider_id);
}

//Used on provider pages to get build latest reviews.
function GetReviews(provider_id) {
	//alert("GetReviews("+provider_id+")");
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_review=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_review=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_review.onreadystatechange=function() {
		if (xmlhttp_review.readyState==4 && xmlhttp_review.status==200) {
			var response = xmlhttp_review.responseText;
			//alert(response);
			if (response.search("[~]") == -1) {
				//alert(response);
			} else {
				var responseArray = new Array();
				responseArray = response.split("[~]");
				document.getElementById("provider_reviews").innerHTML = responseArray[0];
				document.getElementById("div_maxlist").value = responseArray[1];
				document.getElementById("div_currentlocation").value = 1;
				MoveFirstReview();
			}
		}
	}
	xmlhttp_review.open("POST","../../../../include/provider-reviews.php",true);
	xmlhttp_review.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_review.send("provider_id=" + provider_id);
}

//Used on provider pages to get latest images.
function GetPictures(provider_id) {
	//alert("GetPictures("+provider_id+")");
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_pictures=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_pictures=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_pictures.onreadystatechange=function() {
		if (xmlhttp_pictures.readyState==4 && xmlhttp_pictures.status==200) {
			var response = xmlhttp_pictures.responseText;
			//alert(response);
			if (response != "") {
				document.getElementById("provider_pictures").innerHTML = response;
			}
		}
	}
	xmlhttp_pictures.open("POST","../../../../include/provider-images.php",true);
	xmlhttp_pictures.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_pictures.send("provider_id=" + provider_id);
}

//Used on provider pages to get build latest reviews.
function GetMap(provider_address) {
	//alert("GetMap("+provider_address+")");
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_map=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_map=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_map.onreadystatechange=function() {
		if (xmlhttp_map.readyState==4 && xmlhttp_map.status==200) {
			var response = xmlhttp_map.responseText;
			//alert(response);
			document.getElementById("map_div").innerHTML = response;
		}
	}
	xmlhttp_map.open("POST","../../../../include/provider-map.php",true);
	xmlhttp_map.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_map.send("provider_address=" + provider_address);
}

//Used on provider pages for review navigation.
function MoveFirstReview() {
	//alert("MoveFirstReview()");
	var minlist = 1;
	var open = document.getElementById('div_currentlocation').value;
	var shut = document.getElementById('div_currentlocation').value;
	if (shut != "") {
		HideReview(shut);
	}
	if (open != "") {
		if (parseInt(open) != 0) {
			open = minlist;
			ShowReview(open);
		}
	}
}

//Used on provider pages for review navigation.
function MoveBackReview() {
	//alert("MoveBackReview()");
	var minlist = 1;
	var open = document.getElementById('div_currentlocation').value;
	var shut = document.getElementById('div_currentlocation').value;
	if (open != "") {
		open = parseInt(open) - 1;
		if (open < minlist) {
			open = minlist;
		} else {
			HideReview(shut);
			ShowReview(open);
		}
	}
}

//Used on provider pages for review navigation.
function MoveNextReview() {
	//alert("MoveNextReview()");
	var maxlist = document.getElementById('div_maxlist').value;
	var open = document.getElementById('div_currentlocation').value;
	var shut = document.getElementById('div_currentlocation').value;
	if (open != "") {
		open = parseInt(open) + 1;
		if (open > maxlist) {
			open = maxlist;
		} else {
			HideReview(shut);
			ShowReview(open);
		}
	}
}

//Used on provider pages for review navigation.
function MoveLastReview() {
	//alert("MoveLastReview()");
	var maxlist = document.getElementById('div_maxlist').value;
	var open = document.getElementById('div_currentlocation').value;
	var shut = document.getElementById('div_currentlocation').value;
	if (open != "") {
		open = maxlist;
		if (open > maxlist) {
			open = maxlist;
		} else {
			HideReview(shut);
			ShowReview(open);
		}
	}
}

//Used on provider pages for review navigation.
function ShowReview(open) {
	//alert("ShowReview("+open+")");
	var userAgent = navigator.userAgent;
	var FF = userAgent.search(/firefox/i);
	var IE = userAgent.search(/msie/i);
	
	if (IE == -1) {
		document.getElementById(open).style.display = 'table';
	} else {
		document.getElementById(open).style.display = 'block';
	}
	document.getElementById('div_currentlocation').value = open;
}

//Used on provider pages for review navigation.
function HideReview(shut) {
	//alert("HideReview("+shut+")");
	document.getElementById(shut).style.display = 'none';
	document.getElementById('div_previouslocation').value = shut;
}

//Used on create scripts.
function GetCities() {
	//alert("GetCities()");
	var provider_state = document.getElementById('state').value;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_cities=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_cities=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_cities.onreadystatechange=function() {
		if (xmlhttp_cities.readyState==4 && xmlhttp_cities.status==200) {
			var response = xmlhttp_cities.responseText;
			//alert(response);
			if (response != "") {
				document.getElementById("select_city").innerHTML = response;
			}
		}
	}
	xmlhttp_cities.open("POST","../../include/provider-cities.php",true);
	xmlhttp_cities.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_cities.send("s=" + provider_state);
}

//Used on registration page.
function GetCities2() {
	//alert("GetCities()");
	var provider_state = document.getElementById('state').value;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_cities=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_cities=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_cities.onreadystatechange=function() {
		if (xmlhttp_cities.readyState==4 && xmlhttp_cities.status==200) {
			var response = xmlhttp_cities.responseText;
			//alert(response);
			if (response != "") {
				document.getElementById("select_city").innerHTML = response;
			}
		}
	}
	xmlhttp_cities.open("POST","../include/provider-cities.php",true);
	xmlhttp_cities.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_cities.send("s=" + provider_state);
}

//Used on create scripts.
function GetProviders() {
	//alert("GetProviders()");
	var provider_state = document.getElementById('state').value;
	var provider_city = document.getElementById('city').value;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp_providers=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		xmlhttp_providers=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_providers.onreadystatechange=function() {
		if (xmlhttp_providers.readyState==4 && xmlhttp_providers.status==200) {
			var response = xmlhttp_providers.responseText;
			//alert(response);
			if (response != "") {
				document.getElementById("select_provider").innerHTML = response;
			}
		}
	}
	xmlhttp_providers.open("POST","../../include/provider-names.php",true);
	xmlhttp_providers.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_providers.send("s=" + provider_state + "&c=" + provider_city);
}

//Used to dynamically change rss feed.
function showRSS(rss_url) {
	if (rss_url.length==0) {
		document.getElementById("rssOutput").innerHTML = "";
		return;
	}
	if (window.XMLHttpRequest) {
		xmlhttp_rss = new XMLHttpRequest();
	} else {
		xmlhttp_rss = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp_rss.onreadystatechange=function() {
		if (xmlhttp_rss.readyState==4 && xmlhttp_rss.status==200) {
			var response = xmlhttp_rss.responseText;
			document.getElementById("rssOutput").innerHTML = response;
		}
	}
	xmlhttp_rss.open("POST","../include/rss_feed.php",true);
	xmlhttp_rss.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp_rss.send("q=" + rss_url);
}

//Password strength checker.
function password_strength(password)
{
	var desc = new Array();
	desc[0] = "Extremely Weak";
	desc[1] = "Very Weak";
	desc[2] = "Weak";
	desc[3] = "Better";
	desc[4] = "Medium";
	desc[5] = "Strong";
	var points = 0;
	//---- if password is bigger than 7 , give 1 point.
	if (password.length > 7) points++;
	//---- if password has both lowercase and uppercase characters , give 1 point.	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) points++;
	//---- if password has at least one number , give 1 point.
	if (password.match(/\d+/)) points++;
	//---- if password has at least one special caracther , give 1 point.
	// if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	points++;
	if ( password.match(/.[~,!,-,:,.,?,`,_,<,>,@,(,),|,{,},^]/) )	points++;
	//---- if password is bigger than 12 ,  give 1 point.
	if (password.length > 12) points++;
	//---- Showing  description for password strength.
	document.getElementById("password_description").innerHTML = desc[points];
	//---- Changeing CSS class.
	document.getElementById("password_strength").className = "strength" + points;
}

//Tally the total for premium plans.
function DoTotal(price,term,tax,div_id) {
    //alert(price+","+term+","+tax+","+div_id);
    var sub = (term * price);
    var taxrate = (tax/100);
    var taxes = (sub * taxrate);
    var payment = (sub + taxes);
    document.getElementById(div_id).innerHTML = "<table border='0' style='width:70%; text-align:right;'><tr><td>$" + sub.toFixed(2) + "</td></tr><tr><td>+$" + taxes.toFixed(2) + "</td><td>(tax " + tax.toFixed(2) + "%)</td></tr><tr><td><hr /></td></tr><tr><td style='font-weight:bold;'>$" + payment.toFixed(2) + "</td></tr></table>";
}


