﻿
window.onerror = function() {
	return false;//true;
}


var error		=new Array();
var mesageError	=new Array();
var dHeight;
var setFade;
var vTop	=0;
var fadeConfig	=590;
//var ZoomPicId='';
var SetTime;
$(document).ready(function() {

	$('.external').live('mouseup',function(){
		
		var href	=($(this).attr('href'))?$(this).attr('href'):$(this).attr('title');
		var config	=href.substring((href.lastIndexOf('config')+7));
		var size	=config.split('*');
		var wsize	=size[0];
		var hsize	=size[1];
		
		var cw	=wsize/2;
		var ww	=window.screen.width/2;
		var x	=Math.round(ww-cw);

		var ch	=hsize/2;
		var wh	=window.screen.height/2;
		var y	=Math.round(wh-ch);

		if(this.tagName.toLowerCase()=='select'){
			if($(this).attr('alt')!=1){
				$(this).attr('alt','1');
				$(this).change(function(){
					selectExternal(href,$(this).val(),wsize,hsize,x,y);
				});
			}
		}
		else {
			thisWindow	=window.open(encodeURI(href),"mywindow","width="+wsize+",height="+hsize+",scrollbars=yes");
			if (window.focus){thisWindow.focus()};
			thisWindow.moveTo(x,y);
			//alert(x+' '+y);
		}
		return false;
	}).click(function (){return false});
	
	/*
	var title		='';
	var description	='';
	
	$('.picAjax').mouseover(function(){
		
		var aid			=$(this).attr('alt');
		var pos			=$(this).offset();
		var x			=Math.round(pos.left);
		var y			=Math.round(pos.top);
		title		=$(this).parent().attr('title');
		$(this).parent().attr('title','');
		description	=$(this).attr('title');
		$(this).attr('title','');
		var imgSrc		=$(this).attr('src');
		var imgSrc		=imgSrc.replace('thumbnail/','');

		$('body').append(
		'<div class="popupAjax" style="position:absolute; top:'+(y-70)+'px; left:'+(x+121)+'px; width:270px; min-height:250px;display:block;text-align:center; background:#fff; border:1px gray solid; z-index:10000">'+
		'<img src="'+imgSrc+'" alt="" style="margin-top:5px;" /><p style="text-align:right; line-height:200%;padding:5px;background:#F5F5F5"><b>'+
		title+
		'</b><br />'+
		description+
		'</p></div>');
		
	}).mouseout(function(){
		$('.popupAjax').remove();
		$(this).parent().attr('title',title);
		$(this).attr('title',description);
	});
*/
	
	//
	$('.changeSubmit').change(function(){

		$('#formLink').submit();
			
	});
	
		$('.typeCombo').change(function(){
		
		$('#rowPic').show();
		$('#rowRate').show();
		$('.rowFish').show();
		

		switch ($(this).val()){
			case '1':
			$('#rowRate').hide();
			break;
			case '2':
			$('#rowRate').hide();
			case '4':
			$('#rowPic').hide();
			break;
			case '5':
			$('#rowRate').hide();
			$('.rowFish').hide();
			break;
			case '6':
			$('#rowPic').hide();
			$('#rowRate').hide();
			$('.rowFish').hide();
			break;
		}
	});

	
	
$('.vform').submit(function(){

		$(this).find(".validate").each(function(){
			var typeReg		=$(this).attr('title');
			var stringValue	=$(this).val()
			var obj			=$(this);
			if(typeReg!=''){
				if(!checkValid(typeReg,stringValue)){
					error[error.length]	=$(this);
					if(!$(this).attr('alt')){
						var delayId;
						$(this).bind("keyup change", function(){
							if(delayId){clearTimeout(delayId)}
							delayId	=window.setTimeout(function(){
							stringValue	=$(obj).val()
							if(!checkValid(typeReg,stringValue)){
								error[error.length]	=obj;
								if (printError()){
									return false;
								}
							}
							else {
								if ($(obj).next().is('span')){
									$(obj).next().remove();
								}
							}
							},250);
						});
						$(this).attr('alt','1');
					}
		
				}
			}
		});
		if(error.length>0){

			if (printError()){
			
				return false;
			}
		}
	});
	
	$('.delete').live('click',function(){
		if(!window.confirm(delMessage))return false;
	});

	if($('.activeMail').length){
		var ActiveMail	=$('.activeMail').html();
		$('.activeMail').html(ActiveMail.replace('*','@'));
	}

	
	dHeight	=$("#linkFade").height();

	if(dHeight>fadeConfig){
	
		initLink();
		$("#linkFade").mouseover(function(){
			clearInterval(setFade);
		}).mouseout(initLink);
	}
	
	$('#arrowr').click(function(){
		stepcarousel.stepBy('mygallery', -4);
	})
	$('#arrowl').click(function(){
		stepcarousel.stepBy('mygallery', 4);
	})

	var Pages	=new Array();
	var PagesId	=new Array();
	var K=0;
	$('body').find(".divPage").each(function(){
		Pages[K]=$(this).attr('title');
		PagesId[K]=$(this).attr('id');
		
		K++;
	});
	
	$(window).scroll(function(){
		var Sc	=$(window).scrollTop();
		for(i=12; i>0; i--){
			if  (Pages[i] && Sc >= Pages[i] && $('#'+PagesId[i]).attr('load')!=1){
				$('#'+PagesId[i]).find(".picAjax").each(function(){
					$(this).attr('src',$(this).attr('alt'));
					$(this).attr('alt','loaded');

				});
				$('#'+PagesId[i]).attr('load',1);
				break;
			}
		}
	});
/*
	$('.picAjax').mouseover(function(){

		$('.zoomIn').attr('class','zoomOut');
		
		var ID	=$(this).attr('id');
		ID		=ID.split('_');
		var picObj	=$('#zoom_'+$(this).attr('id'))
		$(picObj).html('<table cellpadding="0" cellspacing="0" class="WIP_100 HEP_100 PLoading"><tr><td><img src="images/pictureads/_'+ID[1]+'.jpg" style="width:100%;height:100%;" /></td></tr><tr><td class="bg_white">'+$('#t_'+$(this).attr('id')).html()+'</td></tr></table>');
		//<br />
		$(picObj).parent().attr('class','zoomIn');
		ZoomPicId='zoom_'+$(this).attr('id');
		$(picObj).attr('class','isZoom');
		
		$(picObj).width(214);
		$(picObj).css('top',-40);
		$(picObj).css('left',-50);

		
	});
	$('.zoomPic').mouseout(function(){
		$('.zoomIn').attr('class','zoomOut');
	});
	*/

});

/*
function zoomPics(ZoomPicId){
	
	var picObj	=$('#'+ZoomPicId);
	var W	=$(picObj).width();
	var H	=$(picObj).height();
	var T	=parseInt($(picObj).css('top'));
	var L	=parseInt($(picObj).css('left'));

	if(W < 214)$(picObj).width(W+7);
	if(H < 170)$(picObj).height(H+6);
	if(T > -40)$(picObj).css('top',(T-4)+'px');
	if(L > -50)$(picObj).css('left',(T-5)+'px');
	if(W >= 214)clearInterval(SetTime);
}*/
function initLink(){
	setFade=setInterval('fadeLink()',6000);
	
}
function fadeLink(){

	$("#linkFade").fadeOut(500, function () {
		vTop	=vTop-fadeConfig;
		$(this).css('margin-top',(vTop+'px')).fadeIn(500);
			vTop	=((vTop+dHeight)<=fadeConfig)?fadeConfig:vTop;
	});
}


function selectExternal(href,val,wsize,hsize,x,y){
	href	=(href+'&word='+val);
	thisWindow	=window.open(encodeURI(href),"mywindow","width="+wsize+",height="+hsize+",scrollbars=yes");
	if (window.focus){thisWindow.focus()};
	thisWindow.moveTo(x,y);			
}




function setPermission(el){
	if(el.value>2)document.getElementById('permissionTr').className="showDisplay";
	else document.getElementById('permissionTr').className="noDisplay";
}

function setAboutSection(el){
	if(el.value==5 || el.value==6 )document.getElementById('secTitle').className="showDisplay";
	else document.getElementById('secTitle').className="noDisplay";
}

function newWindow(url,w,h){
	mywindow	=window.open(url,'chating','width='+w+'px,height='+h+'px,status=0,scrollbars=1');
	a	=screen.width/2;
	b	=w/2;
	c	=(a-b > 0) ? a-b : 0;
	mywindow.moveTo(c,200);
	mywindow.focus();
}

function setCombo(combo,txt,val){
	var combo	=document.getElementById(combo);
	var txts	=txt.split('~');
	var vals	=val.split('~');
	removeComboOption(combo);
	var count	=txts.length;
	var i=0;
	for(i=0; i<count; i++){
	addComboOption(combo,txts[i],vals[i]);
	}
	
}
function removeComboOption(combo)
{
	var i;
	var count	=combo.length - 1;
	for (i = count; i>0; i--) {
		combo.remove(i);
	}
}

function addComboOption(combo,txt,val)
{
	var elOptNew = document.createElement('option');
	elOptNew.text = txt;
	elOptNew.value = val;
	try {
		combo.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
	catch(ex) {
		combo.add(elOptNew);
	}
}




function checkValid(typeReg,stringValue){

	var regs		=new Array();
	regs['jalili']	=/^(([1-2])([0-9]{3})\/)((([0][1-6]{1})\/(([0][1-9]{1})|([1-2][0-9]{1})|([3][0-1]{1})))|((([0][7-9]{1})|[1][0-2]{1})\/(([0][1-9]{1})|([1-2][0-9]{1})|([3][0]{1}))))$/;
	regs['miladi']	=/^(([1-2])(([0-1])|[9])([0-9]{2})\/)((([0])([1]|[3]|[5]|[7]|[8])\/(([0][1-9])|([1-2][0-9])|([3][0-1])))|(([0])([4]|[6]|[9])\/(([0][1-9])|([1-2][0-9])|([3][0])))|(([0][2])\/(([0][1-9])|([1-2][0-9])))|(([1]([0]|[2]))\/(([0][1-9])|([1-2][0-9])|([3][0-1])))|(([1][1])\/(([0][1-9])|([1-2][0-9])|([3][0]))))$/;
//	regs['miladi']	= /^(19|20|21)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/;
	regs['mail']	=/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,5})$/i;
	regs['url']		=/(^(\w){2,}((\w)*[\.|\-|_]*)+([\.])([a-z]{2,5}))$/i;
	regs['link']	=/(^(\w){2,}((\w)*[\.|\-|_]*)+([\.])([a-z]{2,5}))(([\/|#|\?])([\W\w])*)*$/i;
	
	
	
	var titles		=typeReg.split(' ');
	var regValidate	=(titles.length>1)?titles[1]:titles[0];
	
	if(!(/MSIE ()/.test(navigator.userAgent) && navigator.platform == "Win32")){
		stringValue		=stringValue.trim();
	}
	
	if(titles[0] == 'required' && (stringValue == 0 || !stringValue)){
		mesageError[mesageError.length]	=regValidate;
		return false;
	}
	if(titles[0] == 'notempty' && !stringValue){
		mesageError[mesageError.length]	=regValidate;
		return false;
	}
	if(titles.length == 1 && (titles[0] == 'required' || titles[0] == 'notempty')){
		return true;
	}

	if(stringValue && !stringValue.match(regs[regValidate])){
		mesageError[mesageError.length]	=regValidate;
		return false;
	}
	else {
		return true;
	}
	
}

function printError(){
	
	var msg			=new Array();
	msg['required']	='*********';
	msg['notempty']	='*********';
	msg['jalili']	='YYYY/MM/DD';
	msg['miladi']	='YYYY-MM-DD';
	msg['mail']		='mail@example.com';
	msg['url']		='http://www.example.com';
	msg['link']		='http://www.example.com/?req=example';

	var dirPage='rtl';
	
	for (var i=0; i<error.length; i++){
	
		var eTop	=(error[i].position().top+12);
		if (!error[i].next().is('span')){
		
			errorlist	=$(document.createElement("span")).attr("class","errorlist").css('top',(eTop+'px')).insertAfter(error[i]);
			errorlist.append(msg[mesageError[i]]);
			var eLeft	=(dirPage=='rtl')?(error[i].position().left-errorlist.width()-5):(error[i].position().left+error[i].width());
			errorlist.css('left',(eLeft+'px'));
			
		}
	}
	
	error=new Array();
	mesageError=new Array();
	
	return true;
}




























