function CharNumeric(value,least,last){
	var CharNumRegxp = /^[0-9a-zA-Zs]+$/;
	str = value;
	len=value.length;
	if(str.match(CharNumRegxp)){
		if(len>=least && len<=last)
			return true;
		else 
			return false;
	}
	else{
		return false;
	}
}
function explodeArray(item,delimiter) { 
	tempArray=new Array(1); 
	var Count=0; 
	var tempString=new String(item); 
	while (tempString.indexOf(delimiter)>0) { 
	tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter)); 
	tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
	Count=Count+1 
	} 
	tempArray[Count]=tempString; 
	return tempArray; 
} 
function in_array(needle,haystack) {
	var bool = false;
	for (var i=0; i<haystack.length; i++) {
	  if (haystack[i]==needle) {
	   bool=true;
	  }
	}
	return bool;
} 
function ValidEmail(email){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	str = email;
	if(str.match(emailRegEx)){
		return true;
	}
	else{
		return false;
	}
}
function Numeric(value,least,last){
	var NumRegxp = /^[0-9a]+$/;
	str = value;
	len=value.length;
	if(str.match(NumRegxp)){
		if(len>=least && len<=last)
			return true;
		else 
			return false;
	}
	else{
		return false;
	}
}
function ModernValidate(frm_Source)	{
	check=0;
	var testform = document.getElementById(frm_Source);
    var itemsInput = testform.getElementsByTagName('input'); 
	var itemsTextArea = testform.getElementsByTagName('textarea'); 
	var itemsSelect = testform.getElementsByTagName('select'); 
	////////////////////////////input
	for(i=0;i < itemsInput.length; i++){
		obj = itemsInput[i];
		if(obj.type=='text' || obj.type=='password' || obj.type=='radio') {
			if(obj.getAttribute('required')==1  && check<1){
			//////////////////////////////////////////Check Empty
				if(obj.value=='' )	{
					msg=obj.getAttribute('msg');
					alert(msg);
					obj.focus();
					check++;
					return false;	
				}////////////////////////////////
				else if(obj.getAttribute('xType')!='' )	{
						pieces=explodeArray(obj.getAttribute('xType'),'|');
						
						type=pieces[0];
						compare=pieces[1];
						nextcompare=pieces[2];
						
						piecesSecond=explodeArray(obj.getAttribute('ApplyDefaultValue'),'|');
						DefaultValueValue=piecesSecond[0];
						DefaultValueMsg=piecesSecond[1];
						
						
						if(type=='Repeat')	{
							if(obj.value!=document.getElementById(compare).value)	{
								alert(obj.value);
								alert(document.getElementById(compare).value);
								alert(nextcompare);
								obj.focus();
								check++;
								return false;
							}//if
						}//if
						if(type=='Compare')	{
							if(obj.value!=compare)	{
								alert(nextcompare);
								obj.focus();
								check++;
								return false;
							}//if
						}//if
						else if(type=='CharNum')	{
							if(!CharNumeric(obj.value,compare,nextcompare))	{
								alert('Please Enter Only Numbers and Characters');
								obj.focus();
								check++;
								return false;
							}//if
						}//if
						else if(type=='Numeric')	{
							if(!Numeric(obj.value,compare,nextcompare))	{
								alert('Please Enter Only Numbers');
								obj.focus();
								check++;
								return false;
							}//if
						}//if
					}//else if
			}
		}
	}
	/////////////////textarea
	for(i=0;i < itemsTextArea.length; i++){
		obj = itemsTextArea[i];
		if(obj.getAttribute('required')==1  && check<1){
		//////////////////////////////////////////Check Empty
			if(obj.value==0 )	{
				msg=obj.getAttribute('msg');
				alert(msg);
				obj.focus();
				check++;
				return false;	
			}////////////////////////////////
		}
	}
	/////////////////select
	for(i=0;i < itemsSelect.length; i++){
		obj = itemsSelect[i];
		if(obj.getAttribute('required')==1  && check<1){
		//////////////////////////////////////////Check Empty
			if(obj.value==0 )	{
				msg=obj.getAttribute('msg');
				alert(msg);
				obj.focus();
				check++;
				return false;	
			}////////////////////////////////
		}
	}
	///////////////////////////
	return true;
}
function Increase(Value,Crease)	{
	temp = Value+Crease;
	return temp;
}
function Decrease(Value,Crease)	{
	if(Value+Crease>2)
		temp = Value-Crease;
	else
		temp = Value
	return temp;
}
function AddMessage(id,Msg)	{
	document.getElementById(id).innerHTML=Msg;
}
function replaceT(obj,classs){
	var newO=document.createElement('input');
	newO.setAttribute('type','password');
	newO.setAttribute('name',obj.getAttribute('name'));
	newO.setAttribute('class',classs);
	newO.setAttribute('required',obj.getAttribute('required'));
	newO.setAttribute('msg',obj.getAttribute('msg'));
	newO.setAttribute('xType',obj.getAttribute('xType'));
	obj.parentNode.replaceChild(newO,obj);
	newO.focus();
}
function ChanegCombo(Value)	{
	var i;
	
	var select = document.getElementById("fld_Cat_Comp_No");
	for (i = select.length - 1; i>=0; i--) {
		//if (elSel.options[i].selected) {
		  select.remove(i);
		//}
	}

	for(index in jsArray) {
		select.options[select.options.length] = new Option(jsArray[index], index);
	}
}
function changeLocationList(page,userno,sorter,sortType)	{
	  document.location=page+'.php?fldUserNo='+userno+'&fld_Sort='+sorter+'&fld_Sort_Type='+sortType;
}
function ChangeMenuColor(value,colorback,classs)	{
	document.getElementById(value.id).style.backgroundColor='#'+colorback;	
	document.getElementById(value.id).className=classs;
}
//now we start our functions

function prev_news(){
        
            //check if there is a single news container before the current visible container... 
            if($('.news_visible').prev('.single_news_container').length){
            
                //... and if there is we hide the current visible news container by using fadeOut...
                $('.news_visible:not(:animated)').fadeOut(100, function(){
                    /*...and when the animation ends we have few chain events.
                    explanation: we first remove the news_visible class from the current visible news container
                    and apply it to the previous news container, and show that container by using fadeIn()...*/
                    $('.news_visible').removeClass('news_visible').prev('.single_news_container').addClass('news_visible').fadeIn(100); 
                    //... then we get the current page number and using parseInt we convert it from text to number (string to integer)...
                    var current = parseInt($('#current_news_num').text());
                    //...and change the current page number
                    $('#current_news_num').text(current - 1);
                });
            }    
            
}

/*bellow we make a function for next_news. I wont explain it line by line because it's almost the same like the previous function.
the difference: 
1) instead of checking if there is previous news (by using prev()) we check if there is by using next()
2) and in the chained events we change the prev() to next() so we show the next news div  '*/
function next_news(){
            if($('.news_visible').next('.single_news_container').length){
                $('.news_visible:not(:animated)').fadeOut(100, function(){
                    $('.news_visible').removeClass('news_visible').next('.single_news_container').addClass('news_visible').fadeIn(100); 
                    var current = parseInt($('#current_news_num').text());
                    $('#current_news_num').text(current + 1);
                });
            }  
}
function ShowHideNews(id,plusid,minusid,type)	{
	if(type==1)	{
		document.getElementById(id).style.display = 'block';	
		document.getElementById(plusid).style.visibility = 'hidden';
		document.getElementById(minusid).style.visibility = 'visible';
	}
	else if(type==2)	{
		document.getElementById(id).style.display = 'none';
		document.getElementById(plusid).style.visibility = 'visible';
		document.getElementById(minusid).style.visibility = 'hidden';
	}
}
function CheckAll(AllCheck,frm_Source)	{
	var testform = document.getElementById(frm_Source);
	var itemsInput = testform.getElementsByTagName('input'); 
	for(i=0;i < itemsInput.length; i++){
		obj = itemsInput[i];
		if(obj.type == 'checkbox' && !AllCheck.checked)	{
			obj.checked=false;
		}
		else if(obj.type == 'checkbox' && AllCheck.checked)	{
			obj.checked='CHECKED';
		}
	}
}
function SubmitDataGrid()	{
	if(confirm("Are You Sure?")){
		return true;
	}
	else	{
		return false;
	}
}