//toproll
function expandCollapse(cmd_type) { 

	var direction = (cmd_type == 'open')? 1 : 2;
	
	var heightCur = (cmd_type == 'open')? parseInt(heightsize):heightSizeClose;
	
	if(document.getElementById) {
		divs = document.getElementById('topads');
		if (divs){
			if (cmd_type == 'open'){
//				divs.style.overflow = 'hidden';
				slideStart('topads', heightCur, direction);										
			}else if (cmd_type == 'close'){
//				divs.style.overflow = 'hidden';	
				slideStart('topads', heightCur, direction);										
			}
		}			
	}
}
// slider start
 var StepPx = 1;  // adım başı pixel
 var StepMs = 10; // mili seconds
 var t = 1;
 var isSliding = false;
 
 function slideStart(objID, toHeight, direction){
     if(isSliding) return;
     slideObj(objID, toHeight, direction);
 }
 
function slideObj(objID, toHeight, direction){						    			    
	isSliding = true;
	var obj = document.getElementById(objID);				
	var curHeight = parseInt(obj.style.height);
	if(direction==1){
	if(curHeight>=toHeight){ isSliding=false; t=1; return;}
		obj.style.height = (curHeight + fn(t)*StepPx) + "px";
	}else{
	if(curHeight<=toHeight){ isSliding=false; t=1; return; }
		obj.style.height = (curHeight - fn(t)*StepPx) + "px";				
	}
	t++;
	setTimeout("slideObj('" + objID + "'," + toHeight + "," + direction + ")", StepMs);
}		

function fn(x){			 			    
return x;
}	
// slider end

//comment
function commentRate(cid, r)
{
	$.ajax({
		type: 'POST',
		url: '/useraction',
		data: 'what=ratecomment&commentid='+cid+'&rate='+r,
		success: function(response){
			switch(response){
				case "0":
					alert('Teşekkürler.');
				break;
				case "1":
					alert('Her yoruma sadece bir kere oy verebilirsiniz..');
				break;
				default:
					alert('Oy vermek için lütfen üye olunuz.');
				break;
			}
		}
	});
}

function informComment(cid){
	$.ajax({
		type: 'POST',
		url: '/useraction',
		data: 'what=informcomment&commentid='+cid,
		success: function(response){
			switch(response){
				case "0":
					alert('Teşekkürler.');
				break;
				default:
					alert('Bir hata oluştu.');
				break;
			}
		}
	});	
}



//form validate functions
function checkLength(field,fieldname,min,max) {
	//Checks for field lendth is greater than min
	if (field.value.length < min) {
		alert(fieldname + " alanı en az " + min + " karakter olmalıdır!");
		field.focus();
		field.select();
		return false;
	}
	if (field.value.length > max) {
		alert(fieldname + " alanı en az " + max + " karakter olmalıdır!");
		field.focus();
		field.select();
		return false;
	}
	return true;
} //isText

function isText(field,fieldname) {
	//Checks for if the user enters some text
	if (( field.value=="" ) || ( field.value=="  " )  ||( field.value=="   " )  ||( field.value=="    " )  ||( field.value=="     " )) {
		alert(fieldname + " alanı boş bırakılamaz!");
		field.focus();
		field.select();
		return false;
	}
	return true;
} //isText

function isTextDouble(field1, field2, fieldname1,fieldname2) {
	//Checks for if the user enters some text
	if (
		((field1.value=="") || (field1.value=="  ")  ||(field1.value=="   ")  ||(field1.value=="    ")  ||(field1.value=="     "))
		&&
		((field2.value=="") || (field2.value=="  ")  ||(field2.value=="   ")  ||(field2.value=="    ")  ||(field2.value=="     "))
	) {
		alert(fieldname1 + " ya da " + fieldname2 +  " alanı boş bırakılamaz!");
		field1.focus();
		field1.select();
		return false;
	}
	return true;
} //isTextDouble

function isSelected(field,fieldname) {
	//Checks for if the user select a value from selectbox

	if (( field.value=="" || field.value=="-1")) {
		alert(fieldname + " alanı seçilmelidir!");
		field.focus();
		return false;
	}
	return true;
} //isSelected

function isChecked(field, fieldname) {
	//Checks for if the user select a checkbox
	var blnChecked = field.checked;
	if (!blnChecked)(alert(fieldname + " alanı seçilmelidir!"))
	return blnChecked
} //isChecked

function isCheckedRadio(field,fieldname) {
	//Checks for if the user select a value from radiobuttons
	var blnChecked = false
	for (x=0 ; x<field.length; x++) {
		if (field[x].checked) {blnChecked = true}
	}
	if (!blnChecked)(alert(fieldname + " alanı seçilmelidir!"))
	field[0].focus();
	return blnChecked
} //isChecked

function isCheckedNotArray(field,fielcount,fieldname) {
	//Checks for if the user select a value from radiobuttons
	var blnChecked = false
	for (x=1 ; x<fielcount; x++) {
		if (document.all[field+x].checked) {blnChecked = true}
	}
	if (!blnChecked)(alert(fieldname + " alanı seçilmelidir!"))
	return blnChecked
} //isChecked

function isNum(field,fieldname) {
	//Checks for if the value of the field is numerical
	var valid = "0123456789."
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1" || valid.value == "" ) ok = "no";
	}
	if ((ok == "no") || (field.value=="")) {
		alert(fieldname + " alanı sayısal bir değer olmalıdır!");
		field.value="0";
		field.focus();
		field.select();
		return false;
	}
	return true;
} // isNum

function isNumber(e, max){	
	var unicode = e.charCode? e.charCode : e.keyCode

	if(max > -1 && unicode!=8) {
		var IE = document.all?true:false;
		if (IE) {
			if(e.srcElement.value.length >= max) return false;
		} else {
			if(e.target.value.length >= max) return false;
		}

	}
	if (unicode!=8){ 
		if (unicode<48||unicode>57)
		return false;
	}
}

function isEmail(field,fieldname){
	//Checks for if the value of the field is a valid email address
	if (field.value.indexOf ('@',0) == -1 || field.value.indexOf ('.',0) == -1 || field.value == "")
	{
		alert(fieldname + " alanı geçerli bir email adresi olmalıdır!");
		field.select();
		field.focus();
		return false;
	}
	return true;
	} //isEmail

function isSame(field1,field2,fieldname1,fieldname2){
	//Checks for if the value of the both field is same. For Password validation
	if (field1.value != field2.value) {
		alert(fieldname1 + ", " + fieldname2 + " alanları aynı olmalaıdır!");
		field1.focus();
		return false; 
	}
	return true;
} //isSame

function isDate(field,fieldname,seperator,format){
	//Checks for if the value of the field is a valid date
	//field			text field of the date (not value of the text!)
	//fieldname		text fields caption for alerting
	//seperator		"/",".","," or smth. else
	//format		2=mm dd yyyy 1=dd mm yyyy

	var strDate
	var blnIsDate
	var intFirstSep
	var intSecSep
	var intday
	var intMonth
	var intYear
	var Temp
	var DaysArray = new Array(12)

	for (var i = 1; i <= 12; i++) {
		DaysArray[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {DaysArray[i] = 30}
		if (i==2) {DaysArray[i] = 29}
	} 

	strDate=field.value
	blnIsDate = true

	if (isNaN(field.value.substring(field.value.length-1,field.value.length))){
		blnIsDate = false	
	}

	intFirstSep = strDate.indexOf(seperator)
	intSecSep = strDate.indexOf(seperator,intFirstSep+1)

	intday=parseInt(strDate.substring(0,intFirstSep),10)
	intMonth=parseInt(strDate.substring(intFirstSep+1,intSecSep),10)
	intYear=parseInt(strDate.substring(intSecSep+1,10),10)

	if ( isNaN(intday) || isNaN(intMonth) || isNaN(intYear)){blnIsDate = false}

	if (format==2 ) {
		Temp=intday
		intday=intMonth
		intMonth=Temp
	}

	if (intday>31 || intday<1) {blnIsDate = false}
	if (intMonth>12 || intMonth<1) {blnIsDate = false}
	if (intYear>3000 || intYear<1000) {blnIsDate = false}

	if (((intMonth==2) && (intday>(((intYear % 4 == 0) && ( (!(intYear % 100 == 0)) || (intYear % 400 == 0))) ? 29 : 28 ))) || (intday > DaysArray[intMonth])){
		blnIsDate= false
	}

	if (blnIsDate) {
		return true 
	} else {
		alert(fieldname + " alanı geçerli bir tarih olmalıdır!");
		return false;
	}
}

function isTime(field,fieldname){
	var timecount = field.value.length
	var blnerror = false

	if (timecount==4) {
		if (! (parseInt(field.value.substring(0,1)) < 24) ) {blnerror = true}
		if (! (field.value.substring(1,2) == ':') ) {blnerror = true}
		if (! (parseInt(field.value.substring(2,4)) < 60)) {blnerror = true}
		if ( field.value == '0:00') {blnerror = true}
	}

	if (timecount==5) {
		if (! (parseInt(field.value.substring(0,2)) < 25) ) {blnerror = true}
		if (! (field.value.substring(2,3) == ':') ) {blnerror = true}
		if (! (parseInt(field.value.substring(3,5)) < 60)) {blnerror = true}
		if ( field.value == '00:00') {blnerror = true}
	}

	if (! (timecount==4 || timecount==5)) {blnerror = true}

	if (blnerror) {
		alert(fieldname + "alanı 00:01 ile 24:00 arasında geçerli bir saat olmalıdır!")
		return false;
	} else {
		return true;	
	}
}

function getFirstChars(tempstr,charsize){
	if (tempstr.length <= charsize) {
		return tempstr
	} else {
		tempstr = tempstr.substring(0, charsize-2) + '..'
		return tempstr
	}
}