/* Author: 
Sonny Ramos
*/


$(document).ready(function(){
	
	var urlcount = $.cookie("url[1]");

	//alert(myObject);
	valid = 0;
	var msghtml = "";
	if(urlcount) {
		
	var myuRL1 = JSON.parse($.cookie("url_short"));
	var mySuRL = myuRL1.length;				
	var myuRL2 = JSON.parse($.cookie("url_long"));

		
				$('#actionResult').removeClass("errorText");
				$('#actionResult').show('fast');
				$('#actionResult').html('<img src="'+PUBLICDOMAIN+'template'+ACTIVETHEME+'/img/ajax-loader.gif" alt="loading..." />');	
				
				msghtml = msghtml +'<table class="tablesorter" border="0" align="center">';	
				
				msghtml = msghtml + '<thead>';
				msghtml = msghtml + '<tr>';
				msghtml = msghtml + '<th align="center">Shortened links</th>';
				msghtml = msghtml + '<th align="center">Share</th>';
				msghtml = msghtml + '<th align="center">Long links</th>';
				msghtml = msghtml + '</tr>';					
				msghtml = msghtml + '</thead>';	

				

				limit = mySuRL;
				valid = 0;
				for (i=limit;i>=0;i--){
				
				shorturl = myuRL1[i];
				longurl = myuRL2[i];

					if(shorturl) {
						
						linklongurl = longurl;
						
						if(longurl.search(/http/i) == -1) {
							
							linklongurl = "http://"+longurl;
						}						
						
						msghtml = msghtml + '<tr>';
						msghtml = msghtml + '<td><div class="sharelinks">'+shorturl+'<input type="hidden" id="valdynamic'+i+'" value="http://'+shorturl+'" /></div></td>';
						msghtml = msghtml + '<td align="center" nowrap="nowrap">';
						msghtml = msghtml + '<div class="sharelinks"><a id="cdynamic'+i+'">Copy</a></div>';
						msghtml = msghtml + '<div class="sharelinks"><a href="http://www.facebook.com/sharer.php?u=http://'+shorturl+'" target="_blank" title="Facebook"><span><img border="0" title="facebook share" alt="facebook share" src="'+PUBLICDOMAIN+'template/'+ACTIVETHEME+'img/FacebookButton.gif"  /></span></a></div>';
						msghtml = msghtml + '<div class="sharelinks"><a href="https://twitter.com/share?url=http://'+shorturl+'" target="_blank"><span><img border="0"  title="twitter share" alt="twitter share"  src="'+PUBLICDOMAIN+'template/'+ACTIVETHEME+'img/FollowUsOnTwitter1.png"  /></span></a>';
						msghtml = msghtml + '</div>';													
						msghtml = msghtml + '</td>';
						msghtml = msghtml + '<td width="50%"><div id="set'+i+'" class="sharelinks"><a href="'+linklongurl+'" title="'+longurl+'">'+longurl.substring(0, 50)+'</a></div></td>';
						msghtml = msghtml + '</tr>';	
						valid++;
					}

				}	


							
				msghtml = msghtml + '</table>';
    			
				$('#actionResult').html(msghtml);
	

	}
				

});



$(document).ready(function(){

	$('#shortener').submit(function() {
		var validURL = /(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		var inputUrl = $('#inputUrl').val();
		$('#ajaxSubmit').val(1);
		//alert (inputUrl);
		//$('#actionResult').hide('fast');
		$('#actionResult').removeClass("errorText");
		$('#actionResult').show('fast');
		$('#actionResult').html('<img src="'+PUBLICDOMAIN+'template'+ACTIVETHEME+'/img/ajax-loader.gif" alt="loading..." />');
		
		if(validURL.test(inputUrl)){
			$.ajax({
			   type: "POST",
			   url: PUBLICDOMAIN+"includes/processUrl.php",
			   data: $('#shortener').serialize(),
			   success: function(msg){
				//alert( "Data Saved: " + msg );
				if(!validURL.test(msg)) {
					 $('#actionResult').addClass("errorText");
					 msg = 'Invalid Web Address';
					 $('#input-url').value = '';
			 		 $('#input-url').focus();					 
					 $('#actionResult').html(msg);
				}else{	
				$('#actionResult').html('<img src="'+PUBLICDOMAIN+'template'+ACTIVETHEME+'/img/ajax-loader.gif" alt="loading..." />');
				location.reload();
				}		
				
			   }
			});
	        //return true;
		}else{
			$('#input-url').value = '';
			$('#input-url').focus();
			$('#actionResult').addClass("errorText");
			$('#actionResult').html('Invalid Web Address');
			//return false;
		}
	  //alert('Handler for .submit() called.');
	  return false;
	});

});


  $(document).ready(function(){

	$("#signinForm").validate({
		
			rules: { 
				semail_box  : {
                            required: true,
                            minlength: 4,
							email: true				
							},
				spassword_box  : {
                            required: true,
                            minlength: 2					
							}
							
			},
			
            messages: {
                semail_box: {
					required: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 4 characters.",
					email: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Please enter a valid email address."
					
                   /* */
                    },
                spassword_box: {
                    required: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 4 characters."
                    }
            }
        });
  });
  
  $(document).ready(function(){
	  
    $("#registerForm").validate({
		
            rules: {
                fname: {
                            required: true,
                            minlength: 2
                            },
                lname: {
                            required: true,
                            minlength: 2
                            },											
                email: {
                            required: true,
                            minlength: 4,
							email: true
							/*remote: "http://localhost/staging/aly/includes/ajax-check-mail.php"*/
                            },
                pass1: {
                            required: true,
                            minlength: 5
                            },
                pass2: {
                            equalTo: "#pass1"
                            }
            },
			
            messages: {
	            fname: {
                    required: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 2 characters.",
                    },
                lname:  {
                    required: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<br><img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 2 characters.",
                    },
                email: {
					required: "<img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 4 characters.",
					remote: "<br />email has already been taken"
					
                   /* */
                    },
                pass1: {
                    required: "<img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Required",
                    minlength: "<img src='http://www.cozycot.com/images/content/icon_cross.gif' align='absmiddle' /> - Min. Length is 4 characters."
                    }
            }
        });
  });
  
  

	function SelectAll(id)
	{
    document.getElementById(id).focus();
    document.getElementById(id).select();
	}

	  


