//This is used on several pages for the pop_window function as well as the txtCounter function.

//This is the main function ***NOT IN USE***
function fullFilter (input) {
    s = input.value;
    filteredValues = "\'$\";()<>#&%+=*,[]{}|^\/";     // Characters stripped out
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (filteredValues.indexOf(c) == -1) returnString += c;
    }
    input.value = returnString;
}

// Trim Keywords Box
function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    }
}

function pop_window(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;
    }
    //window.alert( 'Width = ' + myWidth );
    //window.alert( 'Height = ' + myHeight );
    myWidth = (myWidth/2 - (w/2));
    myHeight = (myHeight/2 - (h/2));
    //alert("myWidth: " + myWidth + "\r myHeight: " + myHeight + "\r popwidth: " + w + "\r height: " + h);
    
	window.open(file,'newWindow','width='+w+',height='+h+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,top='+myHeight+',left='+myWidth+'');
}

function toggleview(element1, value1) {
    element1 = document.getElementById(element1);
    if (element1.style.display == 'block' || element1.style.display == '') {
        element1.style.display = 'none';
    } else {
        // businesssigup_business.asp 
        if (value1 == "sales") {
            element1.style.display = 'block';
        }
        // businesssignup_upgrade.asp
        if (value1 == "credits") {
            element1.style.display = 'block';
        }
    }
    return;
}

function addToFavorites(text) {
    session_test = '<% =session("uid") %>';
    if (session_test == '') {
        alert ("You must be signed in first.");
    }
    if (session_test != '') {
        document.form1.inputDoBox.value = text;
        document.form1.submit();
    }
}

function removeFromFavorites(text) {
    session_test = '<% =session("uid") %>';
    if (session_test == '') {
        alert ("You must be signed in first.");
    }
    if (session_test != '') {
        document.form1.inputDoBox.value = text;
        document.form1.submit();
    }
}

function reportAbuse(t,n) {
    session_test = '<% =session("uid") %>';
    if (session_test == '') {
        alert ("You must be signed in first.");
    }
    if (session_test != '') {
        document.form1.inputDoBox.value = t;
        document.form1.inputID.value = n;
        document.form1.submit();
    }
}

//Businessdetails.asp & Reviewsedit.asp
function rateThis(rating) {
    document.form1.inputRate.value = rating;
    document.getElementById("rating").innerHTML = rating + " out of 5";
}

//Used on userreviews.asp, eventadd.asp
function DoBox(action,number) {
    //alert("Action: " + action + "; Number: " + number)
    document.form1.inputDoBox.value = action;
    document.form1.inputNumber.value = number;
    document.form1.submit();
}

//Used on businesssignup_products.asp
function runPrgm(val) {
    document.form1.inputT.value = val;
    document.form1.submit();
}

//Used on businesssignup_payment.asp
function doPayment(val) {
    document.form1.ToDoBox.value = val;
}

//Used on userpermissions.asp on the useroptions_all.asp include
function form_submit() {
    document.form1.submit();
}

//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;
}