$(document).ready(function(){
			$(".fade").css('display', 'none').fadeIn(1500); 
			$("#cat").selectbox(); // search cats
			$('#keyword').helperCreate('Search');
			$('#reg-birth').helperCreate('YYYY');
			$('#search form').submit(function(){
				$('#search input.hint').val('');
			});
			$('#captcha').helperCreate('Enter Code');
			
			$('a.blank, a[rel*=external]').attr('target','_blank');

			$('.contact-us select[name=formCategory]').change(function(){
				$('#tr_helper').hide(); 
				if(this.value=='Transaction'){
					$('#tr_helper').show();
				}	
			});
			
});
		
$.fn.toggleSection = function(box){ // <a href="javascript:;" onclick="toggleSection('#boxId');">toggle</a>
		$(this).blur();
		if($(box).css('display')=='block')
			$(box).slideUp();
		else $(box).slideDown();
		$(this).toggleClass('on');
}

function showTOCPopup(){
	window.open('terms-and-conditions.html','TOCPopup','width=550,height=600,scrollbars=yes');
}
function popupCalc(url, w ,h){
	window.open(url,"popup","width="+w+",height="+h+",resizable,scrollbars=no,status=1");
}

function popupWindow(url, w ,h){
	window.open(url,"popup","width="+w+",height="+h+",resizable,scrollbars=yes,status=1");
}

function ratingaction(num, action)
{
	var base_url=document.getElementsByTagName('base')[0].href;

	var input = document.getElementById ('rating');
	if(action == 'click'){
		input.value = num;
		for (i=1; i<=num; i++){
			var star = document.getElementById('your-rating-' + i);
			star.style.backgroundImage = 'url('+base_url+'images/star-yellow.gif)';
		}
	}

	if((action == 'show') && (num > input.value)){
		for (i=1; i<=num; i++){
			var star = document.getElementById ('your-rating-' + i);
			star.style.backgroundImage = 'url('+base_url+'images/star-yellow.gif)';
		}
	}

	if ((action == 'hide') && (num > input.value)){
		var star = document.getElementById ('your-rating-' + num);
		star.style.backgroundImage = 'url('+base_url+'images/star-gray.gif)';
	}

	if (action == 'hideall'){
		for (i=5; i>input.value; i--){
			var star = document.getElementById ('your-rating-' + i);
			star.style.backgroundImage =
			'url('+base_url+'images/star-gray.gif)';
		}
	}
}



/*** registration page ***/
function pass_test(p){
	var intScore = 0;

	// PASSWORD LENGTH
	intScore += p.length;

	if(p.length > 0 && p.length <= 4){                    // length 4 or less
		intScore += p.length;
	}
	else if(p.length >= 5 && p.length <= 7){	// length between 5 and 7
		intScore += 6;
	}
	else if(p.length >= 8 && p.length <= 15){	// length between 8 and 15
		intScore += 12;
	}
	else if(p.length >= 16){               // length 16 or more
		intScore += 18;
	}

	// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
	if(p.match(/[a-z]/)){              // [verified] at least one lower case letter
		intScore += 1;
	}
	if(p.match(/[A-Z]/)){              // [verified] at least one upper case letter
		intScore += 5;
	}
	// NUMBERS
	if(p.match(/\d/)){             	// [verified] at least one number
		intScore += 5;
	}
	if(p.match(/.*\d.*\d.*\d/)){            // [verified] at least three numbers
		intScore += 5;
	}

	// SPECIAL CHAR
	if(p.match(/[!,@,#,$,%,^,&,*,?,_,~]/)){           // [verified] at least one special character
		intScore += 5;
	}
	// [verified] at least two special characters
	if(p.match(/.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~]/)){
		intScore += 5;
	}
	
	// COMBOS
	if(p.match(/(?=.*[a-z])(?=.*[A-Z])/)){        // [verified] both upper and lower case
		intScore += 2;
	}
	if(p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/)){ // [verified] both letters and numbers
		intScore += 2;
	}
	// [verified] letters, numbers, and special characters
	if(p.match(/(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!,@,#,$,%,^,&,*,?,_,~])/)){
		intScore += 2;
	}
	
	return intScore;
}
function passStrong(val){
	document.getElementById('divStrong').style.width = pass_test(val)*3+'px';
}


function checkUsernameForLength(whatYouTyped){
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if(txt.length > 0){
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}
function checkNotEmpty(whatYouTyped){
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if (txt.length){
		fieldset.className = "welldone";
	}
	else {
		fieldset.className = "";
	}
}

function checkGender(whatYouTyped){
	var fieldset = whatYouTyped.parentNode;
	var val = whatYouTyped.value;
	if(val != 0){
		fieldset.className = "welldone";
	}else{
		fieldset.className = "";
	}
}

function checkBirth(whatYouTyped){
	var fieldset = whatYouTyped.parentNode;
	var val = whatYouTyped.value;
	if(val <= 2010 && val >= 1900){
		fieldset.className = "welldone";
	}else{
		fieldset.className = "";
	}
	if(val=='')  fieldset.className += 'withHint';
	else fieldset.className.replace('withHint','');
}



function checkEmail(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if(/^[A-Za-z0-9\-\.\_]{1,}\@([A-Za-z0-9\-\.\_]{1,}\.){1,}[a-z]{2,}$/.test(txt)){
		fieldset.className = "welldone";
	}else{
		fieldset.className = "";
	}
}

function checkPassword(whatYouTyped) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if(txt.length > 4) {
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}

function checkPasswordIdent(whatYouTyped, pass) {
	var fieldset = whatYouTyped.parentNode;
	var txt = whatYouTyped.value;
	if(txt == pass.value){
		fieldset.className = "welldone";
	} else {
		fieldset.className = "";
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
function prepareInputsForHints(){
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		inputs[i].onfocus = function(){
			$(this).parent().children("span").css('display','inline');
		}
		inputs[i].onblur = function() {
			$(this).parent().children("span").css('display','none');
		}

	}
	$('select').focus(function(){$(this).parent().children("span").css('display','inline'); });
	$('select').blur(function(){$(this).parent().children("span").css('display','none'); });
}
/*** / registration page ***/



/*** 
 * Input Helper
 * Example
 * $('input[@name=fname]').helperCreate('first name');
 */
$.fn.helperIn = function(text){
	if ( $(this).val() == text ){
		$(this).removeClass('hint').val('');
	}
}
$.fn.helperOut = function(text){
	if ( $(this).val() == '' || $(this).val() == text ){
		$(this).addClass('hint').val(text);
	}
}
$.fn.helperCreate = function(text){
	$(this).focus(function(){ $(this).helperIn(text); } ).blur(function (){ $(this).helperOut(text); } ).helperDestroy(text);
}
$.fn.helperDestroy = function(text){
	if ( $(this).val() == '' || $(this).val() == text ){
		$(this).addClass('hint').val(text);
	}
}

function c(val){
	if (navigator.appName=="Netscape") console.log(val);
}
